godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add support for expand margin, and/or extra spacing from edge of ScrollContainer follow focus #10244

Open Giganzo opened 2 months ago

Giganzo commented 2 months ago

Describe the project you are working on

User interface/option menu

Describe the problem or limitation you are having in your project

When using follow focus the expand margin on the focus style for buttons is not included, so it visual looks like the button is not entirely in focus. See image:

Screenshot_20240715_223902

Describe the feature / enhancement and how it helps to overcome the problem or limitation

If there was a toggle for the ScrollContainer to include the expand margin it would look like this:

Screenshot_20240715_223935

I made an implementation of this, where I also added support for extra spacing between the focused child and the edge's of the container as a theme setting.

With extra spacing:

Screenshot_20240715_223954

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

My idea is it would look something like this:

Screenshot_20240718_162005

Screenshot_20240718_161922

image

This was my first time trying to implement something like this, so there might be a better way to do this. Was a little bit tricky figuring out how to get the expand margin.

https://github.com/Giganzo/godot/tree/scroll-container-follow-focus-settings

If this enhancement will not be used often, can it be worked around with a few lines of script?

It might be possible to write your own version of this in gdscript and send a signal when child gets focused

Is there a reason why this should be core and not an add-on in the asset library?

Improving the usability of the ScrollContainer

Giganzo commented 2 months ago

Should this include control nodes that doesn't have a focus style? As other control nodes can be set to get focus too (or by using ensure_control_visible), and they might have expand margin set on the StyleBox they use.

Or what about setting the focus to an StyleBoxEmpty (I agree with the docs about this not being recommended), but they might use expand margin on any of the other styles. So how should this be handled or not?