Add as_sortable_control() to unify Container checks

This commit is contained in:
kobewi
2024-05-06 12:38:51 +02:00
parent 17a81260cb
commit 5c28814b39
15 changed files with 65 additions and 170 deletions

View File

@@ -55,11 +55,8 @@ void BoxContainer::_resort() {
HashMap<Control *, _MinSizeCache> min_size_cache;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(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<Control>(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<Control>(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<Control>(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();