-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Expand/collapse nodes recursively in scene tree dock #19936
Conversation
The feature is nice, but I'm not convinced that putting it as a button in the top bar is a good idea. It's far from the location where you actually want to expand children recursively (the currently selected node), and most other such actions are provided in the right click popup. |
Yeah, there could be several issues with the current design:
If work should be done, is it ok to push commits to the branch and rebase later? |
I made some improvements that solve some of the described usability issues (haven't pushed the changes yet, but the purposed design has allowed to simplify the code greatly as well):
Demo: Still need to find (or create) |
I'd rather not to have the button, it's already quite crowded in this area. |
Also, a single entry is better to me. As having too many options is bloat to me. |
Bear in mind that if both options are combined, you'd have to call the popup menu twice in some cases with current implementation (because it checks whether any children are expanded/collapsed recursively to determine whether to expand or collapse first)... Or it could be simplified to checking whether the selected item is expanded/collapsed without checking its children... So that:
That would simplify the implementation as well. |
Also, we can add a keyboard shortcut to solve the problem. |
As suggested, I made it work to expand/collapse nodes by simply using a modifier shortcut. Just holding The popup menu option `Expand/Collapse All" is remained and allows to expand nodes first if not completely expanded, and collapse if all children expanded. Needs rebase since I wanted to keep several versions. |
Nice! |
That PR looks good to me now, could you squash the commits together and edit the resulting commit message to describe the final state? |
Done. Also wanted to rename the branch to reflect the changes but figured it would trigger GitHub to close the PR! |
Blender has a drag and collapse/"uncollapse" option. If there is a good ux idea, that also would be worth a thought. (Ask if i need to be more precise in what i mean) |
@toger5 You mean something like this? The problem with implementing such feature is that dragging triggers the actual node dragging with LMB, and RMB alone triggers popup menu, so in either case the key modifier needs to be pressed to circumvent this behavior and to allow "drag-to-collapse/expand" feature, which kinda defeats the purpose imo. Another problem might be that expanding a node might fill the scene tree dock entirely with its children so that "drag-to-collapse/expand" wouldn't be possible anymore for other nodes just because they will become out of reach in the scene tree dock (though this might be more suitable for instant collapsing). |
I agree, that a key mod would be required. Maybe this is also more suitable for the inspector. The scene tree than also should have the same behaviour, just for the sake of consitency. |
Well the idea is good enough but I think this deserves another PR (which as of now is not a good idea because the engine is reaching feature freeze). What do you think @akien-mga? I could try implement suggested feature but I'm afraid this could take some time (if this "drag-to-collapse" feature is even desired at all). |
Moving to 3.2 milestone as we're about to enter the beta stage and release freeze for Godot 3.1. Only bug fixes against issues of the 3.1 milestone (or enhancements to core features of the 3.1 roadmap) will be considered until 3.1-stable is released. Note: If it's merged after 3.1-stable is released, this change might be considered for cherry-picking into a later 3.1.x release. |
Didn't see this when I reimplemented this in another PR. Only feedback I have here is that you could change it so the button also appears when you have multiple nodes selected and you just collapse / expand them all. |
@MunWolf yeah, better to keep it in one place, besides I've tested it thoroughly and kept up with latest features added to the engine recently.
How does that differ from simply collapsing the whole branch? Unless you say you want to expand specific nodes on the branch. |
Lets say you have a node with 5 child nodes all collapsed. This would mean you could select 2 or more of them with shift etc and expand them in one click, the only thing you would have to change is move the shortcut adding outside the if (selection.count == 1) and do a loop over the whole selection in your handling code. |
Well I think this wouldn't hurt anything. I don't recall exactly but I think I've stumbled upon an issue with getting the actual nodes associated with tree items, so I'll take an opportunity and add you as a co-author since you've done some work as well, if you don't mind. 😃 |
You can if you want to but you have most of it here yourself ;)
is the code I used to get the selection and set it recursively. You can have a look at _set_fold_recursive as well in my PR if you want to see how I get the Node* from TreeItem* |
Oh I misread your message, you say that the actual button should appear when multiple nodes are selected. I've been removing and adding the button on the whim of anybody, so no consensus on this unfortunately... |
Well I guess that depends on the ones with authority to decide then ;) |
I've managed to fold/unfold all selected nodes in scene tree, but discovered that this could actually lead to unexpected behavior when selected nodes happen to be affected by recursive calls against parent nodes. Detailscase TOOL_EXPAND_COLLAPSE: {
if (!scene_tree->get_selected())
break;
Tree *tree = scene_tree->get_scene_tree();
TreeItem *selected_item = tree->get_selected();
List<TreeItem *> selection;
while (selected_item) {
selection.push_back(selected_item);
selected_item = tree->get_next_selected(selected_item);
}
if (selection.empty()) {
selection.push_back(tree->get_root());
}
for (List<TreeItem *>::Element *E = selection.front(); E; E = E->next()) {
bool collapsed = _is_collapsed_recursive(E->get());
_set_collapsed_recursive(E->get(), !collapsed);
}
tree->ensure_cursor_is_visible();
} break; This issue could be solved by sorting the selected items based on how deep they are in the scene tree, which would make the implementation quite complex for such a simple feature. I personally don't see much issue with Shift-clicking multiple times on nodes that I want to unfold, if there are many nodes then it would be much easier to just fold/unfold the whole branch instead. I didn't actually push any changes so the current version is merge-ready (added MunWolf as co-author, but for some reason GitHub can't detect...) |
To expand or collapse the node recursively (all children), hold `Shift` button and click on the node's folding arrow. The popup menu option `Expand/Collapse All" checks whether any node is expanded or collapsed first and performs the opposite operation. That means if any children node is collapsed, it will first expand all nodes at selected node. Co-authored-by: Rikhardur Bjarni Einarsson (MunWolf) badulf96@gmail.com
I was looking to implement something like this recently (by using Ctrl + Click on the folding arrows, which seems to be a more common modifier in other software). Thanks for working on this feature 🙂 |
@Calinou I don't recall exactly but I avoided using Ctrl because one could accidentally select multiple nodes with this modifier. Same could be said regarding the use of Shift but it doesn't seem like it interferes with the scene tree dock much compared to other modifiers. |
Thanks for your work and putting up with a slow review and merge process :) |
Jump to the most recent design proposal
Initial proposal with a button
Added a button to fold/unfold all of the nodes at selected node.
It will first check if any of the children are folded or not already. If any folded, it will first unfold them all. Then you have to press button for the second time to fold them all. If all of the children are unfolded, then you don't have to press the same button twice to collapse nodes.
While working on it I mostly haven't touched
Node
s and only had to deal withTree
andTreeItem
elements... makes me wonder whetherTreeItem
should have method likeset_collapsed_recursive()
...All in all, it works fine.