-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Improve TreeItem API and allow to move nodes #46773
Conversation
90e5f6b
to
a200e8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. My only worry would be about making sure that TreeItems are always freed correctly, but it' seems that there is no way to make them orphan (without a tree).
So I guess it should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think get_first_sibling and get_last_sibling should be remove.
Sorry for the double review I messed up the first one (you cannot edit the review status)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks overral good to me.
My only concern would be the efficiency get_child_count/get_index/etc... TreeItem might benefit of using an internal array of pointers to all its children, that would avoid the need to iterate over all children every time. Those pointers would need to be updated, but I don't think it's a big deal since TreeItem is internal anyway.
2e480da
to
d946cdc
Compare
Implemented. Now when you call get_child, get_child_count and get_children, children are cached (the first time it iterates over all the children to construct the cache). And the cache is updated efficiently when adding and removing nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rebase but looks good to me overall.
a62688f
to
6820a01
Compare
Thanks! |
I don't think this PR is enough to close godotengine/godot-proposals#2088. It is missing some feature listed there, like drag 'n' drop. |
Reopened, but note that it was closed because you used a keyword that triggers closure:
What should be added? This list is mostly TODOs, not an exhaustive overview of renames that did happen (there's a lot more than what the list includes). |
Thanks for reopening. I thought GH is smarter 😕.
Oh, ok. It's not important to me, especially if it not a tracker of all breaking changes. |
I think it should be
How can I move
|
@CsloudX you can add a dummy item to NodeB, |
@trollodel Thanks |
Is it possible to backport this feature to Godot 3? |
This PR includes many compatibility-breaking changes, and therefore can't be backported as-is to Godot 3.x. Feel free to work on a backport of the backwards-compatible features yourself, still. |
Partially fixes godotengine/godot-proposals#2088
Fixes #19796 by renaming get_children to get_first_child, as suggested in #19796 and in #16863 3 times.
This PR adds:
Tree get_tree()
.get_first_child
to replaceget_children
.TreeItem.create_child
.move_before
andmove_after
for moving items (see below), and removemove_to_top
andmove_to_bottom
as they are not necessary anymore.The new move_* methods allows moving items over the tree and (unlikely the current system), allow reparent and even moving the item and its children to another tree.
Those methods move
self
before (or after) the specified item. For me, this is the simplest (and less error-prone) approach, but I'm open to suggestions.An example of cross-tree move