diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 45df2233e5a5..a69811d6be37 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -117,8 +117,8 @@ void BoxContainer::_resort() { stretch_space += stretch_diff; //available stretch space. // First, allocate extra space to Controls which have a desired size larger than their minimum size, up to their desired size, in proportion to how much extra space they want. - if (stretch_space > 0 && desired_extra_space > 0) { - real_t space_available_ratio = MIN(real_t(stretch_space) / real_t(desired_extra_space), 1.0); + if (stretch_diff > 0 && desired_extra_space > 0) { + real_t space_available_ratio = MIN(real_t(stretch_diff) / real_t(desired_extra_space), 1.0); for (Node *child : iterate_children()) { Control *c = as_sortable_control(child, SortableVisibilityMode::VISIBLE); diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index e190581adfa8..52b6c8b8a2b1 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -134,19 +134,24 @@ void GridContainer::_resort() { // Evaluate the remaining space for expanded columns/rows. Size2 remaining_space = get_size(); + Size2 empty_space = remaining_space; for (const KeyValue &E : col_minw) { if (!col_expanded.has(E.key)) { remaining_space.width -= E.value; } + empty_space.width -= E.value; } for (const KeyValue &E : row_minh) { if (!row_expanded.has(E.key)) { remaining_space.height -= E.value; } + empty_space.height -= E.value; } remaining_space.height -= theme_cache.v_separation * MAX(max_row - 1, 0); remaining_space.width -= theme_cache.h_separation * MAX(max_col - 1, 0); + empty_space.height -= theme_cache.v_separation * MAX(max_row - 1, 0); + empty_space.width -= theme_cache.h_separation * MAX(max_col - 1, 0); // Distribute the remaining space to cols/rows which have a desired size larger than their minimum size, up to their desired size, in proportion to how much extra space they want. int total_desired_extra_space = 0; @@ -156,8 +161,8 @@ void GridContainer::_resort() { total_desired_extra_space += desired_extra_space; } } - if (remaining_space.width > 0 && total_desired_extra_space > 0) { - real_t space_available_ratio = MIN(real_t(remaining_space.width) / real_t(total_desired_extra_space), 1.0); + if (empty_space.width > 0 && total_desired_extra_space > 0) { + real_t space_available_ratio = MIN(real_t(empty_space.width) / real_t(total_desired_extra_space), 1.0); for (const KeyValue &E : col_desiredw) { int desired_extra_space = E.value - col_minw[E.key]; if (desired_extra_space > 0) { @@ -176,8 +181,8 @@ void GridContainer::_resort() { total_desired_extra_space += desired_extra_space; } } - if (remaining_space.height > 0 && total_desired_extra_space > 0) { - real_t space_available_ratio = MIN(real_t(remaining_space.height) / real_t(total_desired_extra_space), 1.0); + if (empty_space.height > 0 && total_desired_extra_space > 0) { + real_t space_available_ratio = MIN(real_t(empty_space.height) / real_t(total_desired_extra_space), 1.0); for (const KeyValue &E : row_desiredh) { int desired_extra_space = E.value - row_minh[E.key]; if (desired_extra_space > 0) {