godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Allow using external scroll bars in some `Control`s #10620

Open AThousandShips opened 2 months ago

AThousandShips commented 2 months ago

Describe the project you are working on

N/A

Describe the problem or limitation you are having in your project

Controls with scroll bars, like RichTextLabel, ScrollContainer, etc. can be difficult to fully customize in some more elaborate UI designs, like having a smaller elaborate scroll bar on the size with some spacing from a scroll area

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

Controls would be able to "delegate" the scroll bar interface to an external scroll bar, which the user can place where ever they like, and design how ever they would like

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

Each Control that has some built-in scroll bar feature would be provided a new set of methods allowing you to provide your own scroll bar(s) that the Control would use instead (with some checks to ensure they are still valid of course), the Control would treat the layout of itself as if the scroll bar(s) were hidden and handle resizing based on that, it would then handle all the detail configuration of the scroll bar(s) directly (such as setting up the range and value of it when needed) but would not touch any theme details or other aspects (such as drawing ticks etc.)

Optionally the provided interface could use a plain Range allowing a fully custom interface for drawing not relying on the standard ScrollBar system (though this would require substituting scroll and scroll_to)

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

This can be generally worked around at least in some cases (with setting the scroll manually, or scrolling to a particular line, etc.) but it involves detecting various conditions when the scroll bars need to be updated (for example when the size of the container changes, or the size of the content changes, and the scroll bar range needs updating, etc.) so it's fragile and hard to accomplish

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

This would be a core feature of these Controls and replaces existing code

sockeye-d commented 2 months ago

Is it possible to just "steal" the internal scroll bar from the control and reparent it somewhere else?

AThousandShips commented 2 months ago

That wouldn't be recommended IMO, internal nodes should be left to the management of the parent, making the controls able to gracefully deal with that would make the code more complicated and fragile