diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index d9dcf949c71..7c69ac589a2 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -72,16 +72,10 @@ Size2 EditorProperty::get_minimum_size() const { ms.height = label.is_empty() ? 0 : font->get_height(font_size) + 4 * EDSCALE; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } if (c == bottom_editor) { continue; } @@ -143,16 +137,10 @@ void EditorProperty::_notification(int p_what) { //compute room needed for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } if (c == bottom_editor) { continue; } @@ -218,13 +206,10 @@ void EditorProperty::_notification(int p_what) { //set children for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } if (c == bottom_editor) { continue; } @@ -1347,14 +1332,10 @@ void EditorInspectorSection::_notification(int p_what) { int header_height = _get_header_height(); Vector2 offset = Vector2(is_layout_rtl() ? 0 : inspector_margin, header_height); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - fit_child_in_rect(c, Rect2(offset, size)); } } break; @@ -1503,16 +1484,10 @@ void EditorInspectorSection::_notification(int p_what) { Size2 EditorInspectorSection::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cpp index 711dd137813..1663a7d602a 100644 --- a/scene/gui/aspect_ratio_container.cpp +++ b/scene/gui/aspect_ratio_container.cpp @@ -35,16 +35,10 @@ Size2 AspectRatioContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } @@ -107,13 +101,10 @@ void AspectRatioContainer::_notification(int p_what) { bool rtl = is_layout_rtl(); Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } // Temporary fix for editor crash. TextureRect *trect = Object::cast_to(c); diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 2728126e649..88f65ca1bc1 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -55,11 +55,8 @@ void BoxContainer::_resort() { HashMap min_size_cache; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -109,11 +106,8 @@ void BoxContainer::_resort() { float error = 0.0; // Keep track of accumulated error in pixels for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -201,11 +195,8 @@ void BoxContainer::_resort() { } for (int i = start; i != end; i += delta) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -252,17 +243,10 @@ Size2 BoxContainer::get_minimum_size() const { bool first = true; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - - if (!c->is_visible()) { - continue; - } Size2i size = c->get_combined_minimum_size(); diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp index acdeae289b9..1af33d28144 100644 --- a/scene/gui/center_container.cpp +++ b/scene/gui/center_container.cpp @@ -36,16 +36,10 @@ Size2 CenterContainer::get_minimum_size() const { } Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } @@ -81,14 +75,10 @@ void CenterContainer::_notification(int p_what) { case NOTIFICATION_SORT_CHILDREN: { Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - Size2 minsize = c->get_combined_minimum_size(); Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor(); fit_child_in_rect(c, Rect2(ofs, minsize)); diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index c6e66c95c69..5db8d69eef1 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -141,6 +141,14 @@ void Container::queue_sort() { pending_sort = true; } +Control *Container::as_sortable_control(Node *p_node) const { + Control *c = Object::cast_to(p_node); + if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { + return nullptr; + } + return c; +} + Vector Container::get_allowed_size_flags_horizontal() const { Vector flags; if (GDVIRTUAL_CALL(_get_allowed_size_flags_horizontal, flags)) { diff --git a/scene/gui/container.h b/scene/gui/container.h index 94c3c540d72..405220cee63 100644 --- a/scene/gui/container.h +++ b/scene/gui/container.h @@ -42,6 +42,8 @@ class Container : public Control { protected: void queue_sort(); + Control *as_sortable_control(Node *p_node) const; + virtual void add_child_notify(Node *p_child) override; virtual void move_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; diff --git a/scene/gui/flow_container.cpp b/scene/gui/flow_container.cpp index f8128a9dc67..ceffd9d103d 100644 --- a/scene/gui/flow_container.cpp +++ b/scene/gui/flow_container.cpp @@ -63,11 +63,8 @@ void FlowContainer::_resort() { // First pass for line wrapping and minimum size calculation. for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to(get_child(i)); - if (!child || !child->is_visible()) { - continue; - } - if (child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } @@ -138,11 +135,8 @@ void FlowContainer::_resort() { ofs.y = 0; for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to(get_child(i)); - if (!child || !child->is_visible()) { - continue; - } - if (child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } Size2i child_size = children_minsize_cache[child]; @@ -256,17 +250,10 @@ Size2 FlowContainer::get_minimum_size() const { Size2i minimum; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - - if (!c->is_visible()) { - continue; - } Size2i size = c->get_combined_minimum_size(); diff --git a/scene/gui/graph_element.cpp b/scene/gui/graph_element.cpp index 9c13a3ad9e3..e231b05d7f6 100644 --- a/scene/gui/graph_element.cpp +++ b/scene/gui/graph_element.cpp @@ -49,14 +49,10 @@ void GraphElement::_resort() { Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to(get_child(i)); - if (!child || !child->is_visible_in_tree()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } - if (child->is_set_as_top_level()) { - continue; - } - fit_child_in_rect(child, Rect2(Point2(), size)); } } @@ -65,10 +61,7 @@ Size2 GraphElement::get_minimum_size() const { Size2 minsize; for (int i = 0; i < get_child_count(); i++) { Control *child = Object::cast_to(get_child(i)); - if (!child) { - continue; - } - if (child->is_set_as_top_level()) { + if (!child || child->is_set_as_top_level()) { continue; } diff --git a/scene/gui/graph_frame.cpp b/scene/gui/graph_frame.cpp index ca9f7e6fcf1..8cd7dbbeb56 100644 --- a/scene/gui/graph_frame.cpp +++ b/scene/gui/graph_frame.cpp @@ -160,14 +160,10 @@ void GraphFrame::_resort() { Point2 offset = Point2(sb_panel->get_margin(SIDE_LEFT), sb_panel->get_margin(SIDE_TOP) + titlebar_min_size.height + sb_titlebar->get_minimum_size().height); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - if (!child || !child->is_visible_in_tree()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } - if (child->is_set_as_top_level()) { - continue; - } - fit_child_in_rect(child, Rect2(offset, size)); } } @@ -325,8 +321,8 @@ Size2 GraphFrame::get_minimum_size() const { Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size(); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - if (!child || !child->is_visible() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index d035515b51c..75ac5c51351 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -175,9 +175,8 @@ void GraphNode::_resort() { HashMap min_size_cache; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -218,8 +217,8 @@ void GraphNode::_resort() { bool refit_successful = true; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -256,8 +255,8 @@ void GraphNode::_resort() { int width = new_size.width - sb_panel->get_minimum_size().width; int valid_children_idx = 0; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -614,8 +613,8 @@ Size2 GraphNode::get_minimum_size() const { Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size(); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to(get_child(i, false)); - if (!child || !child->is_visible() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index a4baf3bb8d1..a67bba786b0 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -44,11 +44,8 @@ void GridContainer::_notification(int p_what) { // Compute the per-column/per-row data. int valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -186,8 +183,8 @@ void GridContainer::_notification(int p_what) { valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } int row = valid_controls_index / columns; @@ -282,8 +279,8 @@ Size2 GridContainer::get_minimum_size() const { int valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } int row = valid_controls_index / columns; diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 6d331afbb54..91e6c1f0924 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -36,16 +36,10 @@ Size2 MarginContainer::get_minimum_size() const { Size2 max; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 s = c->get_combined_minimum_size(); if (s.width > max.width) { @@ -103,13 +97,10 @@ void MarginContainer::_notification(int p_what) { Size2 s = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } int w = s.width - theme_cache.margin_left - theme_cache.margin_right; int h = s.height - theme_cache.margin_top - theme_cache.margin_bottom; diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index ef859198595..76fde26b268 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -35,11 +35,8 @@ Size2 PanelContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -87,11 +84,8 @@ void PanelContainer::_notification(int p_what) { } for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 4f49f60d700..6f5d0cdcfbf 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -43,11 +43,8 @@ Size2 ScrollContainer::get_minimum_size() const { largest_child_min_size = Size2(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } if (c == h_scroll || c == v_scroll) { @@ -308,11 +305,8 @@ void ScrollContainer::_reposition_children() { } for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } if (c == h_scroll || c == v_scroll) { @@ -542,13 +536,10 @@ PackedStringArray ScrollContainer::get_configuration_warnings() const { int found = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } if (c == h_scroll || c == v_scroll) { continue; } diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 5f4586a6d53..4ea67eec49a 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -126,11 +126,8 @@ Control *SplitContainer::get_containable_child(int p_idx) const { int idx = 0; for (int i = 0; i < get_child_count(false); i++) { - Control *c = Object::cast_to(get_child(i, false)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i, false)); + if (!c) { continue; }