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

Tree: add expand_all and collapse_all methods #22728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/classes/Tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@
If [code]true[/code] column titles are visible.
</description>
</method>
<method name="expand_all">
<return type="void">
</return>
<description>
Expand all the children recursively.
</description>
</method>
<method name="collapse_all">
<return type="void">
</return>
<description>
Collapse all the children recursively.
</description>
</method>
</methods>
<members>
<member name="allow_reselect" type="bool" setter="set_allow_reselect" getter="get_allow_reselect">
Expand Down
29 changes: 29 additions & 0 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,32 @@ bool Tree::is_anything_selected() {
return (selected_item != NULL);
}

void recursive_collapsed(TreeItem *p_item, bool p_collapsed) {

if (!p_item) {
return;
}

p_item->set_collapsed(p_collapsed);
TreeItem *c = p_item->get_children();

while (c) {

recursive_collapsed(c, p_collapsed);
c = c->get_next();
}
}

void Tree::expand_all() {

recursive_collapsed(root, false);
}

void Tree::collapse_all() {

recursive_collapsed(root, true);
}

void Tree::clear() {

if (blocked > 0) {
Expand Down Expand Up @@ -3765,6 +3791,9 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_select_mode", "mode"), &Tree::set_select_mode);
ClassDB::bind_method(D_METHOD("get_select_mode"), &Tree::get_select_mode);

ClassDB::bind_method(D_METHOD("expand_all"), &Tree::expand_all);
ClassDB::bind_method(D_METHOD("collapse_all"), &Tree::collapse_all);

ClassDB::bind_method(D_METHOD("set_columns", "amount"), &Tree::set_columns);
ClassDB::bind_method(D_METHOD("get_columns"), &Tree::get_columns);

Expand Down
3 changes: 3 additions & 0 deletions scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ class Tree : public Control {
void deselect_all();
bool is_anything_selected();

void expand_all();
void collapse_all();

void set_columns(int p_columns);
int get_columns() const;

Expand Down