Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TreeItem.add_child #77446

Merged
merged 1 commit into from
May 31, 2023

Conversation

YuriSizov
Copy link
Contributor

#46773 implemented some of the requested item management methods, but one thing was amiss — a way to add an unparented TreeItem back to the Tree (or move it to another Tree). The issue was made worse by the fact that we have a TreeItem::remove_child method, but no TreeItem::add_child method. Documentation for remove_child states that the unparented item can be reused, but how?

At the same time, aforementioned PR added move_before/move_after, which actually support moving items between different trees. So the implementation of the add_child method was on the surface. And it was explicitly asked for in godotengine/godot-proposals#3607.

Personally, I thought about using it for some sort of cache in the editor. For example, in the editor help search dialog we could create every TreeItem that we need and then reuse them, instead of recreating them on the fly, constantly. I was working on that, but decided to split Tree improvements for now.

Additional changes in this PR include:

  • Better names for the create_child method variables;
  • Add a missing (I think) call to _change_tree(nullptr) to the remove_child method;
  • Move some methods around to group them logically;
  • Small style improvements in the files.

Closes godotengine/godot-proposals#3607.

godot.windows.editor.dev.x86_64_2023-05-24_19-40-37.mp4

@YuriSizov YuriSizov added this to the 4.1 milestone May 24, 2023
@YuriSizov YuriSizov requested review from a team as code owners May 24, 2023 17:41
Copy link
Contributor

@trollodel trollodel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to add this since the proposal was opened, but I forgot about that.
Good that you added it.

scene/gui/tree.cpp Outdated Show resolved Hide resolved
scene/gui/tree.cpp Show resolved Hide resolved
doc/classes/TreeItem.xml Show resolved Hide resolved
scene/gui/tree.cpp Outdated Show resolved Hide resolved
scene/gui/tree.cpp Show resolved Hide resolved
@YuriSizov
Copy link
Contributor Author

Okay, changes done.

scene/gui/tree.cpp Outdated Show resolved Hide resolved
@YuriSizov YuriSizov force-pushed the gui-treeitem-add-child branch from 663b2da to 3ed7bdc Compare May 31, 2023 09:36
@YuriSizov YuriSizov merged commit 5598fec into godotengine:master May 31, 2023
@YuriSizov YuriSizov deleted the gui-treeitem-add-child branch May 31, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add methods to TreeItem to freely move them between parents
3 participants