Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Remove parent cache setting in layout containers

Enzo Novoselic8ce33fd97a69
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml
index 1bd80c7904d..fa73a58a3ae 100644
--- a/doc/classes/Control.xml
+++ b/doc/classes/Control.xml
@@ -1075,11 +1075,9 @@
Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input.
</member>
<member name="custom_maximum_size" type="Vector2" setter="set_custom_maximum_size" getter="get_custom_maximum_size" default="Vector2(-1, -1)">
- The maximum size of this Control's bounding rectangle. If set to a value greater than or equal to [code](0, 0)[/code], the node's bounding rectangle will never exceed this size. A value below [code](0, 0)[/code] means there is no maximum size.
- [b]Note:[/b] The final effective maximum size may be subject to parent Container sizing and propagated maximum sizes. See also: [method get_combined_maximum_size].
- [b]Note:[/b] Not all [Control] subtypes handle a custom maximum size gracefully, which may lead to unexpected behavior if the control's contents exceed this size.
- [b]Note:[/b] This value has priority over [member custom_minimum_size]. For example, if you set [member custom_maximum_size] to [code](100, 100)[/code] and [member custom_minimum_size] to [code](200, 200)[/code], the resulting size will be [code](100, 100)[/code].
- [b]Note:[/b] It is recommended to use [method get_bound_minimum_size] instead of [method get_combined_minimum_size] when using this property, as the former respects maximum size limits when calculating the minimum size, while the latter does not.
+ The maximum size of the node's bounding rectangle. If set to a value greater than or equal to [code](0, 0)[/code], the node's bounding rectangle will never exceed this size. A value below [code](0, 0)[/code] means there is no maximum size. This value has priority over [member custom_minimum_size] if the two conflict.
+ [b]Note:[/b] The final effective maximum size may be subject to the parent's maximum size (via [member propagate_maximum_size]), so it is recommended to use [method get_combined_maximum_size] instead of [method get_maximum_size]. Likewise, use [method get_bound_minimum_size] instead of [method get_combined_minimum_size] to account for the maximum size.
+ [b]Note:[/b] Not all [Control] subtypes handle this gracefully, and their contents may extend beyond the bounding rectangle. Set [member clip_contents] to [code]true[/code] to prevent child controls from rendering outside of this size, especially when this node is a [Container].
</member>
<member name="custom_minimum_size" type="Vector2" setter="set_custom_minimum_size" getter="get_custom_minimum_size" default="Vector2(0, 0)">
The minimum size of the node's bounding rectangle. If you set it to a value greater than [code](0, 0)[/code], the node's bounding rectangle will always have at least this size. Note that [Control] nodes have their internal minimum size returned by [method get_minimum_size]. It depends on the control's contents, like text, textures, or style boxes. The actual minimum size is the maximum value of this property and the internal minimum size (see [method get_combined_minimum_size]).
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 299ac3209d6..789c28281ac 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -65,9 +65,6 @@ void BoxContainer::_resort() {
continue;
}
- if (propagating_max_size) {
- c->set_parent_maximum_size_cache(combined_max_size);
- }
Size2i min_size = c->get_bound_minimum_size().ceil();
Size2i desired_size = c->get_bound_desired_size().ceil();
Size2i max_size = c->get_combined_maximum_size().floor();
@@ -270,7 +267,6 @@ void BoxContainer::_resort() {
delta = +1;
}
- int accumulated_size = 0;
for (int i = start; i != end; i += delta) {
Control *c = as_sortable_control(get_child(i));
if (!c) {
@@ -305,17 +301,8 @@ void BoxContainer::_resort() {
rect = Rect2(from, 0, size, new_size.height);
}
- if (propagating_max_size) {
- if (vertical) {
- c->set_parent_maximum_size_cache(Size2(combined_max_size.width, MAX(combined_max_size.height - accumulated_size, 0)));
- } else {
- c->set_parent_maximum_size_cache(Size2(MAX(combined_max_size.width - accumulated_size, 0), combined_max_size.height));
- }
- }
-
fit_child_in_rect(c, rect);
- accumulated_size += size + theme_cache.separation;
ofs = to;
idx++;
}
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 0ee4e9c27a2..005b35af03b 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -62,9 +62,6 @@ void GridContainer::_resort() {
int col = valid_controls_index % columns;
valid_controls_index++;
- if (is_propagating_maximum_size()) {
- c->set_parent_maximum_size_cache(combined_max_size);
- }
Size2i ms = c->get_bound_minimum_size().ceil();
Size2i desired_size = c->get_bound_desired_size().ceil();
Size2i max_size = c->get_combined_maximum_size().floor();
@@ -319,8 +316,6 @@ void GridContainer::_resort() {
}
}
- int accumulated_width = 0;
- int accumulated_height = 0;
valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = as_sortable_control(get_child(i));
@@ -359,19 +354,6 @@ void GridContainer::_resort() {
s.y++;
}
- if (is_propagating_maximum_size()) {
- Size2 ms = combined_max_size;
- if (ms.width >= 0) {
- ms.width -= accumulated_width;
- ms.width = MAX(ms.width, 0);
- }
- if (ms.height >= 0) {
- ms.height -= accumulated_height;
- ms.height = MAX(ms.height, 0);
- }
- c->set_parent_maximum_size_cache(ms);
- }
-
if (rtl) {
Point2 p(col_ofs - s.width, row_ofs);
fit_child_in_rect(c, Rect2(p, s));
@@ -381,13 +363,6 @@ void GridContainer::_resort() {
fit_child_in_rect(c, Rect2(p, s));
col_ofs += s.width + theme_cache.h_separation;
}
-
- if (col == columns - 1) {
- accumulated_height += s.height + theme_cache.v_separation;
- accumulated_width = 0;
- } else {
- accumulated_width += s.width + theme_cache.h_separation;
- }
}
}
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 6d24b933e44..202128ce88b 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -50,7 +50,7 @@ Size2 MarginContainer::get_desired_size() const {
continue;
}
- Size2 s = c->get_desired_size();
+ Size2 s = c->get_bound_desired_size();
ds = ds.max(s);
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 36044908944..6b22c596a4c 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -50,7 +50,7 @@ Size2 PanelContainer::get_desired_size() const {
continue;
}
- Size2 minsize = c->get_desired_size();
+ Size2 minsize = c->get_bound_desired_size();
ds = ds.max(minsize);
}
if (theme_cache.panel_style.is_valid()) {