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

Fix drag-dropping nodes to parent with internal nodes #78816

Conversation

kleonc
Copy link
Member

@kleonc kleonc commented Jun 28, 2023

When reparenting nodes (or moving within the same parent) within the SceneTreeDock all indexes were taking into account internal nodes. However, Node::move_child does move the child only within the group of nodes the given node belongs to (internal-front / non-internal / internal-back), its parameter is supposed to be such relative index. Hence an absolute index (including internal nodes) shouldn't be passed to it.

This PR makes the SceneTreeDock::_do_reparent method ensure only non-internal nodes are being moved, and changes all indexes to not take internal nodes into account (hopefully I haven't missed any 🙃; please double check the changes).

Fixes #78810 (TabContainer has internal TabBar node).

@kleonc kleonc requested a review from KoBeWi June 28, 2023 23:03
@kleonc kleonc requested review from a team as code owners June 28, 2023 23:03
@akien-mga akien-mga added this to the 4.2 milestone Jun 29, 2023
@KoBeWi
Copy link
Member

KoBeWi commented Jun 30, 2023

hopefully I haven't missed any 🙃

You did. Search the file for get_index(), seems like they all cause problem. Note that here

for (int i = to_node->get_index() + 1; i < to_node->get_parent()->get_child_count(); i++) {

you also need to do get_child_count(false).

@kleonc
Copy link
Member Author

kleonc commented Jun 30, 2023

hopefully I haven't missed any upside_down_face

You did. Search the file for get_index(), seems like they all cause problem. Note that here

for (int i = to_node->get_index() + 1; i < to_node->get_parent()->get_child_count(); i++) {

you also need to do get_child_count(false).

Ah, saw that and concluded it's fine... but indeed it could result in finding a lower_sibling which is a back internal node. Which shouldn't happen.

@kleonc kleonc force-pushed the scene-tree-fix-drag-drop-to-parent-with-internal-nodes branch from ed7fbf9 to 94d96ae Compare June 30, 2023 12:14
@KoBeWi
Copy link
Member

KoBeWi commented Jul 1, 2023

By "they all cause problem" I actually meant all calls in scene tree dock. Deleting nodes, changing node to root or instantiating all have the same bug.

@kleonc kleonc force-pushed the scene-tree-fix-drag-drop-to-parent-with-internal-nodes branch from 94d96ae to 3f6e35b Compare July 7, 2023 17:38
@kleonc
Copy link
Member Author

kleonc commented Jul 7, 2023

By "they all cause problem" I actually meant all calls in scene tree dock. Deleting nodes, changing node to root or instantiating all have the same bug.

Ok, I've restricted some more code to non-internal nodes only. Haven't tested it at all though, just went with find-read-update manner (again, not sure if I've handled everything). 🙃

Alternatively I guess I could maybe add a method like Node::get_internal_index so its result could be passed to Node::move_child (and nodes could be readded with the same internal mode as they had).

Current combination of how Node::get_index/Node::move_child work is unfortunate, I see no way to obtain internal node's "internal index" aka index only within the front/back internal nodes (for front ones it's the same as the absolute index but back ones are problematic). And that's what's needed for moving.

@akien-mga akien-mga merged commit c081d1b into godotengine:master Aug 16, 2023
@akien-mga
Copy link
Member

Thanks!

@kleonc kleonc deleted the scene-tree-fix-drag-drop-to-parent-with-internal-nodes branch August 16, 2023 17:11
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.

Incorrect behaviour when reordering TabContainer children
3 participants