Skip to content

Commit a6bb8b0

Browse files
committed
Merge pull request godotengine#92664 from KoBeWi/ultimate_final_solution_for_containers
Add visibilty mode to `as_sortable_control()`
2 parents 2c01573 + 02e1e6d commit a6bb8b0

File tree

9 files changed

+35
-23
lines changed

9 files changed

+35
-23
lines changed

scene/gui/box_container.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ Size2 BoxContainer::get_minimum_size() const {
243243
bool first = true;
244244

245245
for (int i = 0; i < get_child_count(); i++) {
246-
Control *c = Object::cast_to<Control>(get_child(i));
247-
if (!c || !c->is_visible() || c->is_set_as_top_level()) {
246+
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
247+
if (!c) {
248248
continue;
249249
}
250250

scene/gui/container.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,15 @@ void Container::queue_sort() {
139139
pending_sort = true;
140140
}
141141

142-
Control *Container::as_sortable_control(Node *p_node) const {
142+
Control *Container::as_sortable_control(Node *p_node, SortableVisbilityMode p_visibility_mode) const {
143143
Control *c = Object::cast_to<Control>(p_node);
144-
if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
144+
if (!c || c->is_set_as_top_level()) {
145+
return nullptr;
146+
}
147+
if (p_visibility_mode == SortableVisbilityMode::VISIBLE && !c->is_visible()) {
148+
return nullptr;
149+
}
150+
if (p_visibility_mode == SortableVisbilityMode::VISIBLE_IN_TREE && !c->is_visible_in_tree()) {
145151
return nullptr;
146152
}
147153
return c;

scene/gui/container.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ class Container : public Control {
4141
void _child_minsize_changed();
4242

4343
protected:
44+
enum class SortableVisbilityMode {
45+
VISIBLE,
46+
VISIBLE_IN_TREE,
47+
IGNORE,
48+
};
49+
4450
void queue_sort();
45-
Control *as_sortable_control(Node *p_node) const;
51+
Control *as_sortable_control(Node *p_node, SortableVisbilityMode p_visibility_mode = SortableVisbilityMode::VISIBLE_IN_TREE) const;
4652

4753
virtual void add_child_notify(Node *p_child) override;
4854
virtual void move_child_notify(Node *p_child) override;

scene/gui/graph_element.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ void GraphElement::_resort() {
6060
Size2 GraphElement::get_minimum_size() const {
6161
Size2 minsize;
6262
for (int i = 0; i < get_child_count(); i++) {
63-
Control *child = Object::cast_to<Control>(get_child(i));
64-
if (!child || child->is_set_as_top_level()) {
63+
Control *child = as_sortable_control(get_child(i), SortableVisbilityMode::IGNORE);
64+
if (!child) {
6565
continue;
6666
}
6767

scene/gui/graph_node.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
130130
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
131131
int idx = 0;
132132
for (int i = 0; i < get_child_count(false); i++) {
133-
Control *child = Object::cast_to<Control>(get_child(i, false));
134-
if (!child || child->is_set_as_top_level()) {
133+
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::IGNORE);
134+
if (!child) {
135135
continue;
136136
}
137137

@@ -658,8 +658,8 @@ void GraphNode::_port_pos_update() {
658658
int slot_index = 0;
659659

660660
for (int i = 0; i < get_child_count(false); i++) {
661-
Control *child = Object::cast_to<Control>(get_child(i, false));
662-
if (!child || child->is_set_as_top_level()) {
661+
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::IGNORE);
662+
if (!child) {
663663
continue;
664664
}
665665

scene/gui/margin_container.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Size2 MarginContainer::get_minimum_size() const {
3636
Size2 max;
3737

3838
for (int i = 0; i < get_child_count(); i++) {
39-
Control *c = Object::cast_to<Control>(get_child(i));
40-
if (!c || !c->is_visible() || c->is_set_as_top_level()) {
39+
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
40+
if (!c) {
4141
continue;
4242
}
4343

scene/gui/panel_container.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Size2 PanelContainer::get_minimum_size() const {
3636
Size2 ms;
3737
for (int i = 0; i < get_child_count(); i++) {
38-
Control *c = as_sortable_control(get_child(i));
38+
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
3939
if (!c) {
4040
continue;
4141
}

scene/gui/scroll_container.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Size2 ScrollContainer::get_minimum_size() const {
4242
largest_child_min_size = Size2();
4343

4444
for (int i = 0; i < get_child_count(); i++) {
45-
Control *c = as_sortable_control(get_child(i));
45+
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
4646
if (!c) {
4747
continue;
4848
}

scene/gui/tab_container.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ void TabContainer::_on_mouse_exited() {
362362
Vector<Control *> TabContainer::_get_tab_controls() const {
363363
Vector<Control *> controls;
364364
for (int i = 0; i < get_child_count(); i++) {
365-
Control *control = Object::cast_to<Control>(get_child(i));
366-
if (!control || control->is_set_as_top_level() || control == tab_bar || children_removing.has(control)) {
365+
Control *control = as_sortable_control(get_child(i), SortableVisbilityMode::IGNORE);
366+
if (!control || control == tab_bar || children_removing.has(control)) {
367367
continue;
368368
}
369369

@@ -539,8 +539,8 @@ void TabContainer::add_child_notify(Node *p_child) {
539539
return;
540540
}
541541

542-
Control *c = Object::cast_to<Control>(p_child);
543-
if (!c || c->is_set_as_top_level()) {
542+
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
543+
if (!c) {
544544
return;
545545
}
546546
c->hide();
@@ -569,8 +569,8 @@ void TabContainer::move_child_notify(Node *p_child) {
569569
return;
570570
}
571571

572-
Control *c = Object::cast_to<Control>(p_child);
573-
if (c && !c->is_set_as_top_level()) {
572+
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
573+
if (c) {
574574
tab_bar->move_tab(c->get_meta("_tab_index"), get_tab_idx_from_control(c));
575575
}
576576

@@ -584,8 +584,8 @@ void TabContainer::remove_child_notify(Node *p_child) {
584584
return;
585585
}
586586

587-
Control *c = Object::cast_to<Control>(p_child);
588-
if (!c || c->is_set_as_top_level()) {
587+
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
588+
if (!c) {
589589
return;
590590
}
591591

0 commit comments

Comments
 (0)