godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 68 forks source link

Add an option to follow selected `TreeItem` for `Tree` #9919

Open feois opened 3 weeks ago

feois commented 3 weeks ago

Describe the project you are working on

An application that only uses GUI

Describe the problem or limitation you are having in your project

ScrollContainer does not work with Tree and Tree does not have the ability to automatically follow the selected TreeItem

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

Add an option to follow selected item for Tree similar to ScrollContainer

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

Tree will scroll to the selected TreeItem automatically

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

AFAIK I think no

Edit: After reading ScrollContainer and Tree source code, I now think yes, but still not something easy (as there is nothing in docs or internet about this) for newbie programmers like me

Yes, just connect Tree.item_selected to Tree.scroll_to_item(Tree.get_selected())

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

Tree is a core node

AThousandShips commented 3 weeks ago

just use the same code for ScrollContainer

This isn't necessarily as simple as that, and some more details on what you want the feature to do is good to add to a proposal

feois commented 3 weeks ago

just use the same code for ScrollContainer

This isn't necessarily as simple as that, and some more details on what you want the feature to do is good to add to a proposal

I read through a bit of ScrollContainer and Tree source code, it seems like it won't be impossibly hard with Tree::get_item_rect()

Hiiamwilliam commented 3 weeks ago

Tree has a scroll_to_item method, does it not work for your case?

feois commented 3 weeks ago

Tree has a scroll_to_item method, does it not work for your case?

I didn't know that exists, sorry, however my proposal is still valid in that it can be a little bit more convenient.