Godot Engine – Multi-platform 2D and 3D game engine
Add `SIZE_MAXIMIZE` size flag
Enzo Novoselic14dd3c714e7a
diff --git a/doc/classes/Control.xml b/doc/classes/Control.xmlindex baa85b3701f..2f74909257f 100644--- a/doc/classes/Control.xml+++ b/doc/classes/Control.xml@@ -1556,6 +1556,11 @@<constant name="SIZE_SHRINK_END" value="8" enum="SizeFlags" is_bitfield="true">Tells the parent [Container] to align the node with its end, either the bottom or the right edge. It is mutually exclusive with [constant SIZE_FILL] and other shrink size flags, but can be used with [constant SIZE_EXPAND] in some containers. Use with [member size_flags_horizontal] and [member size_flags_vertical].</constant>+ <constant name="SIZE_MAXIMIZE" value="16" enum="SizeFlags" is_bitfield="true">+ Tells the parent [Container] to use the node's [member custom_maximum_size] when doing minimum size calculations. Use with [member size_flags_horizontal] and [member size_flags_vertical].+ [b]Note:[/b] Setting this flag does not necessarily mean the node will be resized to its maximum size, as the parent container may not have enough space to do so.+ [b]Note:[/b] If this node is a child of a Container that enables the [member size_flags_stretch_ratio] property on its children for layout, nodes with this flag set will be given priority in stretching. If multiple nodes have this flag set, their relative stretch ratios will still be respected.+ </constant><constant name="MOUSE_FILTER_STOP" value="0" enum="MouseFilter">The control will receive mouse movement input events and mouse button input events if clicked on through [method _gui_input]. The control will also receive the [signal mouse_entered] and [signal mouse_exited] signals. These events are automatically marked as handled, and they will not propagate further to other controls. This also results in blocking signals in other controls.</constant>diff --git a/editor/scene/gui/control_editor_plugin.cpp b/editor/scene/gui/control_editor_plugin.cppindex d4d1e4ddfe0..fc76962f84c 100644--- a/editor/scene/gui/control_editor_plugin.cpp+++ b/editor/scene/gui/control_editor_plugin.cpp@@ -283,10 +283,12 @@ void EditorPropertySizeFlags::_preset_selected(int p_which) {break;}- bool is_expand = flag_expand->is_visible() && flag_expand->is_pressed();- if (is_expand) {+ if (flag_expand->is_visible() && flag_expand->is_pressed()) {value |= Control::SIZE_EXPAND;}+ if (flag_maximize->is_visible() && flag_maximize->is_pressed()) {+ value |= Control::SIZE_MAXIMIZE;+ }emit_changed(get_edited_property(), value);}@@ -305,6 +307,20 @@ void EditorPropertySizeFlags::_expand_toggled() {emit_changed(get_edited_property(), value);}+void EditorPropertySizeFlags::_maximize_toggled() {+ uint32_t value = get_edited_property_value();++ if (flag_maximize->is_visible() && flag_maximize->is_pressed()) {+ value |= Control::SIZE_MAXIMIZE;+ } else {+ value ^= Control::SIZE_MAXIMIZE;+ }++ // Keep the custom preset selected as we toggle individual flags.+ keep_selected_preset = true;+ emit_changed(get_edited_property(), value);+}+void EditorPropertySizeFlags::_flag_toggled() {uint32_t value = 0;for (int i = 0; i < flag_checks.size(); i++) {@@ -314,10 +330,12 @@ void EditorPropertySizeFlags::_flag_toggled() {}}- bool is_expand = flag_expand->is_visible() && flag_expand->is_pressed();- if (is_expand) {+ if (flag_expand->is_visible() && flag_expand->is_pressed()) {value |= Control::SIZE_EXPAND;}+ if (flag_maximize->is_visible() && flag_maximize->is_pressed()) {+ value |= Control::SIZE_MAXIMIZE;+ }// Keep the custom preset selected as we toggle individual flags.keep_selected_preset = true;@@ -336,22 +354,23 @@ void EditorPropertySizeFlags::update_property() {}}- bool is_expand = value & Control::SIZE_EXPAND;- flag_expand->set_pressed(is_expand);+ flag_expand->set_pressed(value & Control::SIZE_EXPAND);+ flag_maximize->set_pressed(value & Control::SIZE_MAXIMIZE);if (keep_selected_preset) {keep_selected_preset = false;return;}+ uint32_t size_flags_without_modifiers = value & ~(Control::SIZE_EXPAND | Control::SIZE_MAXIMIZE);FlagPreset preset = SIZE_FLAGS_PRESET_CUSTOM;- if (value == Control::SIZE_FILL || value == (Control::SIZE_FILL | Control::SIZE_EXPAND)) {+ if (size_flags_without_modifiers == Control::SIZE_FILL) {preset = SIZE_FLAGS_PRESET_FILL;- } else if (value == Control::SIZE_SHRINK_BEGIN || value == (Control::SIZE_SHRINK_BEGIN | Control::SIZE_EXPAND)) {+ } else if (size_flags_without_modifiers == Control::SIZE_SHRINK_BEGIN) {preset = SIZE_FLAGS_PRESET_SHRINK_BEGIN;- } else if (value == Control::SIZE_SHRINK_CENTER || value == (Control::SIZE_SHRINK_CENTER | Control::SIZE_EXPAND)) {+ } else if (size_flags_without_modifiers == Control::SIZE_SHRINK_CENTER) {preset = SIZE_FLAGS_PRESET_SHRINK_CENTER;- } else if (value == Control::SIZE_SHRINK_END || value == (Control::SIZE_SHRINK_END | Control::SIZE_EXPAND)) {+ } else if (size_flags_without_modifiers == Control::SIZE_SHRINK_END) {preset = SIZE_FLAGS_PRESET_SHRINK_END;}@@ -370,6 +389,7 @@ void EditorPropertySizeFlags::setup(const Vector<String> &p_options, bool p_vertflag_presets->add_item(TTRC("Container Default"));flag_presets->set_disabled(true);flag_expand->set_visible(false);+ flag_maximize->set_visible(false);return;}@@ -379,7 +399,7 @@ void EditorPropertySizeFlags::setup(const Vector<String> &p_options, bool p_vertint64_t current_val = text_split[1].to_int();flags[current_val] = text_split[0];- if (current_val == SIZE_EXPAND) {+ if (current_val == SIZE_EXPAND || current_val == SIZE_MAXIMIZE) {continue;}@@ -420,6 +440,7 @@ void EditorPropertySizeFlags::setup(const Vector<String> &p_options, bool p_vertflag_presets->add_item(TTRC("Custom"), SIZE_FLAGS_PRESET_CUSTOM);flag_expand->set_visible(flags.has(SIZE_EXPAND));+ flag_maximize->set_visible(flags.has(SIZE_MAXIMIZE));}EditorPropertySizeFlags::EditorPropertySizeFlags() {@@ -446,6 +467,13 @@ EditorPropertySizeFlags::EditorPropertySizeFlags() {vb->add_child(flag_expand);add_focusable(flag_expand);flag_expand->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertySizeFlags::_expand_toggled));++ flag_maximize = memnew(CheckBox);+ flag_maximize->set_text(TTRC("Maximize"));+ flag_maximize->set_clip_text(true);+ vb->add_child(flag_maximize);+ add_focusable(flag_maximize);+ flag_maximize->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertySizeFlags::_maximize_toggled));}bool EditorInspectorPluginControl::can_handle(Object *p_object) {@@ -723,6 +751,9 @@ void SizeFlagPresetPicker::_preset_button_pressed(const int p_preset) {if (expand_button->is_pressed()) {flags |= SIZE_EXPAND;}+ if (maximize_button->is_pressed()) {+ flags |= SIZE_MAXIMIZE;+ }emit_signal("size_flags_selected", flags);_update_preset_button_state(p_preset);@@ -732,6 +763,10 @@ void SizeFlagPresetPicker::_expand_button_pressed() {emit_signal("expand_flag_toggled", expand_button->is_pressed());}+void SizeFlagPresetPicker::_maximize_button_pressed() {+ emit_signal("maximize_flag_toggled", maximize_button->is_pressed());+}+void SizeFlagPresetPicker::set_allowed_flags(Vector<SizeFlags> &p_flags) {preset_buttons[SIZE_SHRINK_BEGIN]->set_disabled(!p_flags.has(SIZE_SHRINK_BEGIN));preset_buttons[SIZE_SHRINK_CENTER]->set_disabled(!p_flags.has(SIZE_SHRINK_CENTER));@@ -745,6 +780,13 @@ void SizeFlagPresetPicker::set_allowed_flags(Vector<SizeFlags> &p_flags) {expand_button->set_pressed(false);expand_button->set_tooltip_text(TTRC("Some parents of the selected nodes do not support the Expand flag."));}+ maximize_button->set_disabled(!p_flags.has(SIZE_MAXIMIZE));+ if (p_flags.has(SIZE_MAXIMIZE)) {+ maximize_button->set_tooltip_text(TTRC("Enable to also set the Maximize flag.\nDisable to only set Shrink/Fill/Expand flags."));+ } else {+ maximize_button->set_pressed(false);+ maximize_button->set_tooltip_text(TTRC("Some parents of the selected nodes do not support the Maximize flag."));+ }}void SizeFlagPresetPicker::set_selected_preset(int p_preset) {@@ -755,6 +797,10 @@ void SizeFlagPresetPicker::set_expand_flag(bool p_expand) {expand_button->set_pressed(p_expand);}+void SizeFlagPresetPicker::set_maximize_flag(bool p_maximize) {+ maximize_button->set_pressed(p_maximize);+}+void SizeFlagPresetPicker::_notification(int p_notification) {switch (p_notification) {case NOTIFICATION_THEME_CHANGED: {@@ -778,6 +824,7 @@ void SizeFlagPresetPicker::_notification(int p_notification) {void SizeFlagPresetPicker::_bind_methods() {ADD_SIGNAL(MethodInfo("size_flags_selected", PropertyInfo(Variant::INT, "size_flags")));ADD_SIGNAL(MethodInfo("expand_flag_toggled", PropertyInfo(Variant::BOOL, "expand_flag")));+ ADD_SIGNAL(MethodInfo("maximize_flag_toggled", PropertyInfo(Variant::BOOL, "maximize_flag")));}SizeFlagPresetPicker::SizeFlagPresetPicker(bool p_vertical) {@@ -803,6 +850,13 @@ SizeFlagPresetPicker::SizeFlagPresetPicker(bool p_vertical) {expand_button->set_tooltip_text(TTRC("Enable to also set the Expand flag.\nDisable to only set Shrink/Fill flags."));expand_button->connect(SceneStringName(pressed), callable_mp(this, &SizeFlagPresetPicker::_expand_button_pressed));main_vb->add_child(expand_button);++ maximize_button = memnew(CheckButton);+ maximize_button->set_flat(true);+ maximize_button->set_text(TTRC("Maximize"));+ maximize_button->set_tooltip_text(TTRC("Enable to also set the Maximize flag.\nDisable to only set Shrink/Fill/Expand flags."));+ maximize_button->connect(SceneStringName(pressed), callable_mp(this, &SizeFlagPresetPicker::_maximize_button_pressed));+ main_vb->add_child(maximize_button);}// Toolbar.@@ -950,6 +1004,41 @@ void ControlEditorToolbar::_expand_flag_toggled(bool p_expand, bool p_vertical)undo_redo->commit_action();}+void ControlEditorToolbar::_maximize_flag_toggled(bool p_maximize, bool p_vertical) {+ const List<Node *> &selection = editor_selection->get_top_selected_node_list();++ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();+ if (p_vertical) {+ undo_redo->create_action(TTR("Change Vertical Maximize Flag"));+ } else {+ undo_redo->create_action(TTR("Change Horizontal Maximize Flag"));+ }++ for (Node *E : selection) {+ Control *control = Object::cast_to<Control>(E);+ if (control) {+ int old_flags = p_vertical ? control->get_v_size_flags() : control->get_h_size_flags();+ int new_flags = old_flags;++ if (p_maximize) {+ new_flags |= Control::SIZE_MAXIMIZE;+ } else {+ new_flags &= ~Control::SIZE_MAXIMIZE;+ }++ if (p_vertical) {+ undo_redo->add_do_method(control, "set_v_size_flags", new_flags);+ undo_redo->add_undo_method(control, "set_v_size_flags", old_flags);+ } else {+ undo_redo->add_do_method(control, "set_h_size_flags", new_flags);+ undo_redo->add_undo_method(control, "set_h_size_flags", old_flags);+ }+ }+ }++ undo_redo->commit_action();+}+Vector2 ControlEditorToolbar::_position_to_anchor(const Control *p_control, Vector2 position) {ERR_FAIL_NULL_V(p_control, Vector2());@@ -1032,6 +1121,8 @@ void ControlEditorToolbar::_update_container_sizing_selection_ui(bool p_pressed)bool all_v_shrink_fill_same = true;bool all_h_expand = true;bool all_v_expand = true;+ bool all_h_maximize = true;+ bool all_v_maximize = true;int first_h_flags = -1;int first_v_flags = -1;@@ -1044,8 +1135,8 @@ void ControlEditorToolbar::_update_container_sizing_selection_ui(bool p_pressed)const int h_flags = control->get_h_size_flags();const int v_flags = control->get_v_size_flags();- const int h_shrink_fill = h_flags & ~(Control::SIZE_EXPAND);- const int v_shrink_fill = v_flags & ~(Control::SIZE_EXPAND);+ const int h_shrink_fill = h_flags & ~(Control::SIZE_EXPAND | Control::SIZE_MAXIMIZE);+ const int v_shrink_fill = v_flags & ~(Control::SIZE_EXPAND | Control::SIZE_MAXIMIZE);if (first_h_flags == -1) {first_h_flags = h_shrink_fill;@@ -1065,6 +1156,13 @@ void ControlEditorToolbar::_update_container_sizing_selection_ui(bool p_pressed)if (!(v_flags & Control::SIZE_EXPAND)) {all_v_expand = false;}++ if (!(h_flags & Control::SIZE_MAXIMIZE)) {+ all_h_maximize = false;+ }+ if (!(v_flags & Control::SIZE_MAXIMIZE)) {+ all_v_maximize = false;+ }}container_h_picker->set_selected_preset(all_h_shrink_fill_same ? first_h_flags : -1);@@ -1072,6 +1170,9 @@ void ControlEditorToolbar::_update_container_sizing_selection_ui(bool p_pressed)container_h_picker->set_expand_flag(all_h_expand);container_v_picker->set_expand_flag(all_v_expand);++ container_h_picker->set_maximize_flag(all_h_maximize);+ container_v_picker->set_maximize_flag(all_v_maximize);}void ControlEditorToolbar::_selection_changed() {@@ -1087,6 +1188,7 @@ void ControlEditorToolbar::_selection_changed() {SIZE_SHRINK_END,SIZE_FILL,SIZE_EXPAND,+ SIZE_MAXIMIZE,};Vector<SizeFlags> allowed_v_flags = {SIZE_SHRINK_BEGIN,@@ -1094,6 +1196,7 @@ void ControlEditorToolbar::_selection_changed() {SIZE_SHRINK_END,SIZE_FILL,SIZE_EXPAND,+ SIZE_MAXIMIZE,};for (const KeyValue<ObjectID, Object *> &E : editor_selection->get_selection()) {@@ -1182,6 +1285,7 @@ void ControlEditorToolbar::_selection_changed() {SIZE_SHRINK_END,SIZE_FILL,SIZE_EXPAND,+ SIZE_MAXIMIZE,};container_h_picker->set_allowed_flags(allowed_all_flags);@@ -1254,6 +1358,7 @@ ControlEditorToolbar::ControlEditorToolbar() {containers_button->get_popup_hbox()->add_child(container_h_picker);container_h_picker->connect("size_flags_selected", callable_mp(this, &ControlEditorToolbar::_container_flags_selected).bind(false));container_h_picker->connect("expand_flag_toggled", callable_mp(this, &ControlEditorToolbar::_expand_flag_toggled).bind(false));+ container_h_picker->connect("maximize_flag_toggled", callable_mp(this, &ControlEditorToolbar::_maximize_flag_toggled).bind(false));containers_button->get_popup_hbox()->add_child(memnew(HSeparator));@@ -1264,6 +1369,7 @@ ControlEditorToolbar::ControlEditorToolbar() {containers_button->get_popup_hbox()->add_child(container_v_picker);container_v_picker->connect("size_flags_selected", callable_mp(this, &ControlEditorToolbar::_container_flags_selected).bind(true));container_v_picker->connect("expand_flag_toggled", callable_mp(this, &ControlEditorToolbar::_expand_flag_toggled).bind(true));+ container_v_picker->connect("maximize_flag_toggled", callable_mp(this, &ControlEditorToolbar::_maximize_flag_toggled).bind(true));// Editor connections.editor_selection = EditorNode::get_singleton()->get_editor_selection();diff --git a/editor/scene/gui/control_editor_plugin.h b/editor/scene/gui/control_editor_plugin.hindex 2c28764e5ec..b49353a437d 100644--- a/editor/scene/gui/control_editor_plugin.h+++ b/editor/scene/gui/control_editor_plugin.h@@ -104,6 +104,7 @@ class EditorPropertySizeFlags : public EditorProperty {OptionButton *flag_presets = nullptr;CheckBox *flag_expand = nullptr;+ CheckBox *flag_maximize = nullptr;VBoxContainer *flag_options = nullptr;Vector<CheckBox *> flag_checks;@@ -113,6 +114,7 @@ class EditorPropertySizeFlags : public EditorProperty {void _preset_selected(int p_which);void _expand_toggled();+ void _maximize_toggled();void _flag_toggled();protected:@@ -192,11 +194,13 @@ class SizeFlagPresetPicker : public ControlEditorPresetPicker {GDCLASS(SizeFlagPresetPicker, ControlEditorPresetPicker);CheckButton *expand_button = nullptr;+ CheckButton *maximize_button = nullptr;bool vertical = false;virtual void _preset_button_pressed(const int p_preset) override;void _expand_button_pressed();+ void _maximize_button_pressed();protected:void _notification(int p_notification);@@ -206,6 +210,7 @@ public:void set_allowed_flags(Vector<SizeFlags> &p_flags);void set_selected_preset(int p_preset);void set_expand_flag(bool p_expand);+ void set_maximize_flag(bool p_maximize);SizeFlagPresetPicker(bool p_vertical);};@@ -232,6 +237,7 @@ class ControlEditorToolbar : public HBoxContainer {void _anchor_mode_toggled(bool p_status);void _container_flags_selected(int p_flags, bool p_vertical);void _expand_flag_toggled(bool p_expand, bool p_vertical);+ void _maximize_flag_toggled(bool p_maximize, bool p_vertical);void _update_anchor_selection_ui(bool p_pressed);void _update_container_sizing_selection_ui(bool p_pressed);diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cppindex e583b32b1b7..a3163cccae5 100644--- a/scene/gui/aspect_ratio_container.cpp+++ b/scene/gui/aspect_ratio_container.cpp@@ -33,19 +33,6 @@#include "core/object/class_db.h"#include "scene/gui/texture_rect.h"-Size2 AspectRatioContainer::get_minimum_size() const {- Size2 ms;- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);- if (!c) {- continue;- }- Size2 minsize = c->get_bound_minimum_size();- ms = ms.max(minsize);- }- return ms;-}-void AspectRatioContainer::set_ratio(float p_ratio) {if (ratio == p_ratio) {return;@@ -84,6 +71,7 @@ Vector<int> AspectRatioContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -93,6 +81,7 @@ Vector<int> AspectRatioContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/aspect_ratio_container.h b/scene/gui/aspect_ratio_container.hindex 59b428d525a..5e30576e97e 100644--- a/scene/gui/aspect_ratio_container.h+++ b/scene/gui/aspect_ratio_container.h@@ -38,7 +38,6 @@ class AspectRatioContainer : public Container {protected:void _notification(int p_what);static void _bind_methods();- virtual Size2 get_minimum_size() const override;public:enum StretchMode {diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cppindex a69811d6be3..299ac3209d6 100644--- a/scene/gui/box_container.cpp+++ b/scene/gui/box_container.cpp@@ -88,7 +88,17 @@ void BoxContainer::_resort() {if (msc.will_stretch) {stretch_space += msc.min_size;- stretch_ratio_total += c->get_stretch_ratio();+ msc.stretch_ratio = c->get_stretch_ratio();+ if (vertical) { /* VERTICAL */+ if (c->get_v_size_flags().has_flag(SIZE_MAXIMIZE)) {+ msc.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }+ } else { /* HORIZONTAL */+ if (c->get_h_size_flags().has_flag(SIZE_MAXIMIZE)) {+ msc.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }+ }+ stretch_ratio_total += msc.stretch_ratio;}combined_min += msc.min_size;@@ -159,8 +169,7 @@ void BoxContainer::_resort() {_MinSizeCache &msc = min_size_cache[c];if (msc.will_stretch) {- float stretch_ratio = c->get_stretch_ratio();- float final_pixel_size = stretch_space * stretch_ratio / stretch_ratio_total;+ float final_pixel_size = stretch_space * msc.stretch_ratio / stretch_ratio_total;// Add leftover fractional pixels to error accumulator and dump if greater than 1.error += final_pixel_size - (int)final_pixel_size;@@ -172,7 +181,7 @@ void BoxContainer::_resort() {if (final_pixel_size < msc.min_size) {// If stretching would make the Control smaller than its minimum size, cap it and redistribute its unused share.msc.will_stretch = false;- stretch_ratio_total -= stretch_ratio;+ stretch_ratio_total -= msc.stretch_ratio;refit_successful = false;stretch_space -= msc.min_size;msc.final_size = msc.min_size;@@ -180,7 +189,7 @@ void BoxContainer::_resort() {} else if (msc.max_size >= 0 && final_pixel_size > msc.max_size) {// If stretching would exceed the Control's maximum size, cap it and redistribute its unused share.msc.will_stretch = false;- stretch_ratio_total -= stretch_ratio;+ stretch_ratio_total -= msc.stretch_ratio;refit_successful = false;stretch_space -= msc.max_size;msc.final_size = msc.max_size;@@ -313,38 +322,36 @@ void BoxContainer::_resort() {}Size2 BoxContainer::_get_minimum_size(bool p_use_desired_sizes) const {- /* Calculate MINIMUM SIZE */-- Size2i minimum;+ const int axis = vertical ? 1 : 0;+ const int other_axis = vertical ? 0 : 1;- bool first = true;+ Size2 minimum;- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);+ List<Control *> children;+ for (Node *child : iterate_children()) {+ Control *c = as_sortable_control(child, SortableVisibilityMode::VISIBLE);if (!c) {continue;}+ children.push_back(c);+ }- Size2i size = p_use_desired_sizes ? c->get_bound_desired_size().ceil() : c->get_bound_minimum_size().ceil();-- if (vertical) { /* VERTICAL */-- if (size.width > minimum.width) {- minimum.width = size.width;- }-- minimum.height += size.height + (first ? 0 : theme_cache.separation);+ for (Control *c : children) {+ const Size2 min_size = p_use_desired_sizes ? c->get_bound_desired_size().ceil() : c->get_bound_minimum_size().ceil();+ const Size2 max_size = c->get_custom_maximum_size();- } else { /* HORIZONTAL */+ const bool maximize_axis = vertical ? c->get_v_size_flags().has_flag(SIZE_MAXIMIZE) : c->get_h_size_flags().has_flag(SIZE_MAXIMIZE);+ const bool maximize_other_axis = vertical ? c->get_h_size_flags().has_flag(SIZE_MAXIMIZE) : c->get_v_size_flags().has_flag(SIZE_MAXIMIZE);- if (size.height > minimum.height) {- minimum.height = size.height;- }+ const real_t axis_size = maximize_axis && max_size[axis] >= 0 ? max_size[axis] : min_size[axis];+ const real_t other_axis_size = maximize_other_axis && max_size[other_axis] >= 0 ? max_size[other_axis] : min_size[other_axis];- minimum.width += size.width + (first ? 0 : theme_cache.separation);- }+ minimum[axis] += axis_size;+ minimum[other_axis] = MAX(minimum[other_axis], other_axis_size);+ }- first = false;+ if (children.size() > 0) {+ minimum[axis] += theme_cache.separation * (children.size() - 1);}return minimum;@@ -443,6 +450,7 @@ Vector<int> BoxContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -455,6 +463,7 @@ Vector<int> BoxContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cppindex 1a7a17b5479..bd4712554ba 100644--- a/scene/gui/center_container.cpp+++ b/scene/gui/center_container.cpp@@ -36,17 +36,7 @@ Size2 CenterContainer::get_minimum_size() const {if (use_top_left) {return Size2();}- Size2 ms;- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);- if (!c) {- continue;- }- Size2 minsize = c->get_bound_minimum_size();- ms = ms.max(minsize);- }-- return ms;+ return Container::get_minimum_size();}Size2 CenterContainer::get_desired_size() const {@@ -82,11 +72,11 @@ bool CenterContainer::is_using_top_left() const {}Vector<int> CenterContainer::get_allowed_size_flags_horizontal() const {- return Vector<int>();+ return Vector<int>{ SIZE_MAXIMIZE };}Vector<int> CenterContainer::get_allowed_size_flags_vertical() const {- return Vector<int>();+ return Vector<int>{ SIZE_MAXIMIZE };}void CenterContainer::_notification(int p_what) {diff --git a/scene/gui/container.cpp b/scene/gui/container.cppindex 351a2851c7a..815fde1d40e 100644--- a/scene/gui/container.cpp+++ b/scene/gui/container.cpp@@ -52,7 +52,7 @@ void Container::add_child_notify(Node *p_child) {return;}- control->connect(SceneStringName(size_flags_changed), callable_mp(this, &Container::queue_sort));+ control->connect(SceneStringName(size_flags_changed), callable_mp(this, &Container::_child_minsize_changed));control->connect(SceneStringName(minimum_size_changed), callable_mp(this, &Container::_child_minsize_changed));control->connect(SceneStringName(maximum_size_changed), callable_mp(this, &Container::_child_minsize_changed));control->connect("_desired_size_changed", callable_mp(this, &Container::_child_desired_size_changed));@@ -81,7 +81,7 @@ void Container::remove_child_notify(Node *p_child) {return;}- control->disconnect(SceneStringName(size_flags_changed), callable_mp(this, &Container::queue_sort));+ control->disconnect(SceneStringName(size_flags_changed), callable_mp(this, &Container::_child_minsize_changed));control->disconnect(SceneStringName(minimum_size_changed), callable_mp(this, &Container::_child_minsize_changed));control->disconnect(SceneStringName(maximum_size_changed), callable_mp(this, &Container::_child_minsize_changed));control->disconnect("_desired_size_changed", callable_mp(this, &Container::_child_desired_size_changed));@@ -91,6 +91,28 @@ void Container::remove_child_notify(Node *p_child) {queue_sort();}+Size2 Container::get_minimum_size() const {+ Size2 min_size;++ for (Node *child : iterate_children()) {+ Control *c = as_sortable_control(child, SortableVisibilityMode::VISIBLE);+ if (!c) {+ continue;+ }++ Size2 minsize = c->get_bound_minimum_size();+ Size2 maxsize = c->get_custom_maximum_size();++ real_t width = (c->get_h_size_flags().has_flag(SIZE_MAXIMIZE) && maxsize.x >= 0) ? maxsize.x : minsize.x;+ real_t height = (c->get_v_size_flags().has_flag(SIZE_MAXIMIZE) && maxsize.y >= 0) ? maxsize.y : minsize.y;++ min_size.x = MAX(min_size.x, width);+ min_size.y = MAX(min_size.y, height);+ }++ return min_size;+}+void Container::_sort_children() {if (!is_inside_tree()) {pending_sort = false;@@ -194,6 +216,7 @@ Vector<int> Container::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -208,6 +231,7 @@ Vector<int> Container::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/container.h b/scene/gui/container.hindex 1cf1fd24308..fb841e8c9d6 100644--- a/scene/gui/container.h+++ b/scene/gui/container.h@@ -55,6 +55,8 @@ protected:virtual void move_child_notify(Node *p_child) override;virtual void remove_child_notify(Node *p_child) override;+ virtual Size2 get_minimum_size() const override;+GDVIRTUAL0RC(Vector<int>, _get_allowed_size_flags_horizontal)GDVIRTUAL0RC(Vector<int>, _get_allowed_size_flags_vertical)@@ -67,6 +69,9 @@ public:NOTIFICATION_SORT_CHILDREN = 51,};+ // Multiplication factor to be used by Containers when a child has the SIZE_MAXIMIZE flag. Effectively infinite to ensure it gets as much space as possible.+ constexpr static float MAXIMIZE_STRETCH_FACTOR = 1e10;+void fit_child_in_rect(RequiredParam<Control> p_child, const Rect2 &p_rect);virtual Vector<int> get_allowed_size_flags_horizontal() const;diff --git a/scene/gui/control.cpp b/scene/gui/control.cppindex 63ea3b2b78f..2d70118c939 100644--- a/scene/gui/control.cpp+++ b/scene/gui/control.cpp@@ -638,6 +638,12 @@ void Control::_validate_property(PropertyInfo &p_property) const {}hint_string += "Shrink End:8";}+ if (size_flags.has(SIZE_MAXIMIZE)) {+ if (!hint_string.is_empty()) {+ hint_string += ",";+ }+ hint_string += "Maximize:16";+ }if (hint_string.is_empty()) {p_property.hint_string = "";@@ -5022,8 +5028,8 @@ void Control::_bind_methods() {ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pivot_offset_ratio"), "set_pivot_offset_ratio", "get_pivot_offset_ratio");ADD_SUBGROUP("Container Sizing", "size_flags_");- ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_h_size_flags", "get_h_size_flags");- ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_v_size_flags", "get_v_size_flags");+ ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8,Maximize:16"), "set_h_size_flags", "get_h_size_flags");+ ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8,Maximize:16"), "set_v_size_flags", "get_v_size_flags");ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");ADD_GROUP("Offset Transform", "offset_transform_");@@ -5152,6 +5158,7 @@ void Control::_bind_methods() {BIND_BITFIELD_FLAG(SIZE_EXPAND_FILL);BIND_BITFIELD_FLAG(SIZE_SHRINK_CENTER);BIND_BITFIELD_FLAG(SIZE_SHRINK_END);+ BIND_BITFIELD_FLAG(SIZE_MAXIMIZE);BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP);BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS);diff --git a/scene/gui/control.h b/scene/gui/control.hindex 2b0ab740ddf..f1c3dc5702b 100644--- a/scene/gui/control.h+++ b/scene/gui/control.h@@ -82,6 +82,7 @@ public:SIZE_EXPAND = 2,SIZE_SHRINK_CENTER = 4,SIZE_SHRINK_END = 8,+ SIZE_MAXIMIZE = 16,SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,};diff --git a/scene/gui/flow_container.cpp b/scene/gui/flow_container.cppindex b969e174b82..daf4767fc7b 100644--- a/scene/gui/flow_container.cpp+++ b/scene/gui/flow_container.cpp@@ -34,6 +34,14 @@#include "scene/gui/texture_rect.h"#include "scene/theme/theme_db.h"+struct _ChildData {+ Size2i min_size;+ Size2i max_size;+ bool will_stretch = false;+ float stretch_ratio = 0.0;+ int stretch_size = 0;+};+struct _LineData {int child_count = 0;int min_line_height = 0;@@ -51,9 +59,7 @@ void FlowContainer::_resort() {bool rtl = is_layout_rtl();- HashMap<Control *, Size2i> children_minsize_cache;- HashMap<Control *, Size2i> children_maxsize_cache;- HashMap<Control *, int> children_stretch_cache;+ HashMap<Control *, _ChildData> children_data;Vector<_LineData> lines_data;@@ -72,6 +78,7 @@ void FlowContainer::_resort() {continue;}+ _ChildData child_data;// Since we are in a FlowContainer, children will always have up to the full width/height available to them, so we can use the desired size as the minimum size for layout purposes.Size2i child_msc = child->get_bound_desired_size();Size2i child_max_size = child->get_combined_maximum_size();@@ -94,7 +101,11 @@ void FlowContainer::_resort() {line_height = MAX(line_height, child_msc.x);if (child->get_v_size_flags().has_flag(SIZE_EXPAND)) {- line_stretch_ratio_total += child->get_stretch_ratio();+ child_data.stretch_ratio = child->get_stretch_ratio();+ if (child_max_size.y >= 0 && child->get_v_size_flags().has_flag(SIZE_MAX)) {+ child_data.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }+ line_stretch_ratio_total += child_data.stretch_ratio;}ofs.y += child_msc.y;@@ -116,14 +127,19 @@ void FlowContainer::_resort() {line_height = MAX(line_height, child_msc.y);if (child->get_h_size_flags().has_flag(SIZE_EXPAND)) {- line_stretch_ratio_total += child->get_stretch_ratio();+ child_data.stretch_ratio = child->get_stretch_ratio();+ if (child_max_size.x >= 0 && child->get_h_size_flags().has_flag(SIZE_MAX)) {+ child_data.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }+ line_stretch_ratio_total += child_data.stretch_ratio;}ofs.x += child_msc.x;}last_child = child;- children_minsize_cache[child] = child_msc;- children_maxsize_cache[child] = child_max_size;+ child_data.min_size = child_msc;+ child_data.max_size = child_max_size;+ children_data[child] = child_data;children_in_current_line++;}line_length = vertical ? (ofs.y) : (ofs.x);@@ -146,7 +162,8 @@ void FlowContainer::_resort() {if (!child) {continue;}- Size2i child_size = children_minsize_cache[child];+ _ChildData &child_data = children_data[child];+ Size2i child_size = child_data.min_size;_LineData line_data = lines_data[current_line_idx];if (child_idx_in_line >= lines_data[current_line_idx].child_count) {@@ -169,9 +186,10 @@ void FlowContainer::_resort() {if (!line_child) {continue;}+ _ChildData &line_child_data = children_data[line_child];line_children.push_back(line_child);- children_stretch_cache[line_child] = 0;+ line_child_data.stretch_size = 0;}int line_remaining_stretch = line_data.stretch_avail;@@ -181,14 +199,17 @@ void FlowContainer::_resort() {for (int j = 0; j < line_children.size(); j++) {Control *line_child = line_children[j];+ _ChildData &line_child_data = children_data[line_child];bool can_stretch = vertical ? line_child->get_v_size_flags().has_flag(SIZE_EXPAND) : line_child->get_h_size_flags().has_flag(SIZE_EXPAND);if (!can_stretch) {continue;}+ line_child_data.will_stretch = true;stretch_children.push_back(line_child);stretch_children_active.push_back(true);- line_stretch_ratio_total += line_child->get_stretch_ratio();+ line_child_data.stretch_ratio = line_child->get_stretch_ratio();+ line_stretch_ratio_total += line_child_data.stretch_ratio;}while (line_stretch_ratio_total > 0) {@@ -200,17 +221,18 @@ void FlowContainer::_resort() {}Control *line_child = stretch_children[j];- float stretch_ratio = line_child->get_stretch_ratio();+ _ChildData &line_child_data = children_data[line_child];+ float stretch_ratio = line_child_data.stretch_ratio;int child_stretch = line_remaining_stretch * stretch_ratio / line_stretch_ratio_total;- const Size2i &child_min_size = children_minsize_cache[line_child];- const Size2i &child_max_size = children_maxsize_cache[line_child];+ const Size2i &child_min_size = line_child_data.min_size;+ const Size2i &child_max_size = line_child_data.max_size;int child_axis_min = vertical ? child_min_size.height : child_min_size.width;int child_axis_max = vertical ? child_max_size.height : child_max_size.width;int max_stretch = child_axis_max >= 0 ? MAX(child_axis_max - child_axis_min, 0) : INT_MAX;if (child_stretch > max_stretch) {- children_stretch_cache[line_child] = max_stretch;+ line_child_data.stretch_size = max_stretch;stretch_children_active.write[j] = false;line_stretch_ratio_total -= stretch_ratio;line_remaining_stretch -= max_stretch;@@ -226,7 +248,8 @@ void FlowContainer::_resort() {}Control *line_child = stretch_children[j];- children_stretch_cache[line_child] = line_remaining_stretch * line_child->get_stretch_ratio() / line_stretch_ratio_total;+ _ChildData &line_child_data = children_data[line_child];+ line_child_data.stretch_size = line_remaining_stretch * line_child_data.stretch_ratio / line_stretch_ratio_total;}break;}@@ -234,7 +257,7 @@ void FlowContainer::_resort() {int used_stretch = 0;for (int j = 0; j < line_children.size(); j++) {- used_stretch += children_stretch_cache[line_children[j]];+ used_stretch += children_data[line_children[j]].stretch_size;}lines_data.write[current_line_idx].stretch_avail = MAX(line_data.stretch_avail - used_stretch, 0);line_data = lines_data[current_line_idx];@@ -310,7 +333,7 @@ void FlowContainer::_resort() {}if (child->get_v_size_flags().has_flag(SIZE_EXPAND)) {- int stretch = children_stretch_cache.has(child) ? children_stretch_cache[child] : 0;+ int stretch = children_data[child].stretch_size;child_size.height += stretch;}@@ -320,7 +343,7 @@ void FlowContainer::_resort() {}if (child->get_h_size_flags().has_flag(SIZE_EXPAND)) {- int stretch = children_stretch_cache.has(child) ? children_stretch_cache[child] : 0;+ int stretch = children_data[child].stretch_size;child_size.width += stretch;}}@@ -358,7 +381,7 @@ void FlowContainer::_resort() {}Size2 FlowContainer::_get_minimum_size(bool p_use_desired_sizes) const {- Size2i minimum;+ Size2 minimum;for (int i = 0; i < get_child_count(); i++) {Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);@@ -366,18 +389,26 @@ Size2 FlowContainer::_get_minimum_size(bool p_use_desired_sizes) const {continue;}- Size2i size = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();+ Size2 size = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();+ Size2 max_size = c->get_custom_maximum_size();if (vertical) { /* VERTICAL */- minimum.height = MAX(minimum.height, size.height);- minimum.width = cached_size;+ real_t height = (c->get_v_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.height >= 0) ? max_size.height : size.height;+ minimum.height = MAX(minimum.height, height);} else { /* HORIZONTAL */- minimum.width = MAX(minimum.width, size.width);- minimum.height = cached_size;+ real_t width = (c->get_h_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.width >= 0) ? max_size.width : size.width;+ minimum.width = MAX(minimum.width, width);}}+ if (vertical) { /* VERTICAL */+ minimum.width = cached_size;++ } else { /* HORIZONTAL */+ minimum.height = cached_size;+ }+return minimum;}@@ -394,6 +425,7 @@ Vector<int> FlowContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_FILL);if (!vertical) {flags.append(SIZE_EXPAND);+ flags.append(SIZE_MAXIMIZE);}flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);@@ -406,6 +438,7 @@ Vector<int> FlowContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_FILL);if (vertical) {flags.append(SIZE_EXPAND);+ flags.append(SIZE_MAXIMIZE);}flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);diff --git a/scene/gui/foldable_container.cpp b/scene/gui/foldable_container.cppindex 2f3c2614f39..72f3a34aedc 100644--- a/scene/gui/foldable_container.cpp+++ b/scene/gui/foldable_container.cpp@@ -40,15 +40,7 @@ Size2 FoldableContainer::get_minimum_size() const {if (folded) {return title_minimum_size;}- Size2 ms;-- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i));- if (!c) {- continue;- }- ms = ms.max(c->get_bound_minimum_size());- }+ Size2 ms = Container::get_minimum_size();ms += theme_cache.panel_style->get_minimum_size();return Size2(MAX(ms.width, title_minimum_size.width), ms.height + title_minimum_size.height);diff --git a/scene/gui/foldable_container.h b/scene/gui/foldable_container.hindex 097fbe4b72b..869859f1c6a 100644--- a/scene/gui/foldable_container.h+++ b/scene/gui/foldable_container.h@@ -141,8 +141,8 @@ public:virtual Size2 get_desired_size() const override;virtual Size2 get_inner_combined_maximum_size() const override;- virtual Vector<int> get_allowed_size_flags_horizontal() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }- virtual Vector<int> get_allowed_size_flags_vertical() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END }; }+ virtual Vector<int> get_allowed_size_flags_horizontal() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END, SIZE_MAXIMIZE }; }+ virtual Vector<int> get_allowed_size_flags_vertical() const override { return { SIZE_FILL, SIZE_SHRINK_BEGIN, SIZE_SHRINK_CENTER, SIZE_SHRINK_END, SIZE_MAXIMIZE }; }FoldableContainer(const String &p_text = String());~FoldableContainer();diff --git a/scene/gui/graph_element.cpp b/scene/gui/graph_element.cppindex af7c29733a3..757647a705d 100644--- a/scene/gui/graph_element.cpp+++ b/scene/gui/graph_element.cpp@@ -58,22 +58,6 @@ void GraphElement::_resort() {}}-Size2 GraphElement::get_minimum_size() const {- Size2 minsize;- for (int i = 0; i < get_child_count(); i++) {- Control *child = as_sortable_control(get_child(i), SortableVisibilityMode::IGNORE);- if (!child) {- continue;- }-- Size2i size = child->get_bound_minimum_size();-- minsize = minsize.max(size);- }-- return minsize;-}-void GraphElement::_notification(int p_what) {switch (p_what) {case NOTIFICATION_SORT_CHILDREN: {diff --git a/scene/gui/graph_element.h b/scene/gui/graph_element.hindex d7e2e5d3df4..ad9155665e3 100644--- a/scene/gui/graph_element.h+++ b/scene/gui/graph_element.h@@ -89,8 +89,6 @@ public:void set_scaling_menus(bool p_scaling_menus);bool is_scaling_menus() const;- virtual Size2 get_minimum_size() const override;-bool is_resizing() const {return resizing;}diff --git a/scene/gui/graph_frame.cpp b/scene/gui/graph_frame.cppindex d3b26d12c8b..482562cb555 100644--- a/scene/gui/graph_frame.cpp+++ b/scene/gui/graph_frame.cpp@@ -335,11 +335,16 @@ Size2 GraphFrame::_get_minimum_size(bool p_use_desired_sizes) const {continue;}- Size2i size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();- size.width += sb_panel->get_minimum_size().width;+ Size2 size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();+ Size2 max_size = child->get_custom_maximum_size();- minsize.x = MAX(minsize.x, size.x);- minsize.y += MAX(minsize.y, size.y);+ real_t width = (child->get_h_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.width >= 0) ? max_size.width : size.width;+ real_t height = (child->get_v_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.height >= 0) ? max_size.height : size.height;++ width += sb_panel->get_minimum_size().width;++ minsize.width = MAX(minsize.width, width);+ minsize.height += MAX(minsize.height, height);}minsize.height += sb_panel->get_minimum_size().height;diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cppindex 7a2e4be612b..ee25154b7e2 100644--- a/scene/gui/graph_node.cpp+++ b/scene/gui/graph_node.cpp@@ -198,7 +198,11 @@ void GraphNode::_resort() {if (msc.will_stretch) {available_stretch_space += msc.min_size;- stretch_ratio_total += child->get_stretch_ratio();+ msc.stretch_ratio = child->get_stretch_ratio();+ if (child->get_v_size_flags().has_flag(SIZE_MAXIMIZE)) {+ msc.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }+ stretch_ratio_total += msc.stretch_ratio;}children_count++;@@ -232,13 +236,12 @@ void GraphNode::_resort() {_MinSizeCache &msc = min_size_cache[child];if (msc.will_stretch) {- float stretch_ratio = child->get_stretch_ratio();- int final_pixel_size = available_stretch_space * stretch_ratio / stretch_ratio_total;+ int final_pixel_size = available_stretch_space * msc.stretch_ratio / stretch_ratio_total;if (final_pixel_size < msc.min_size) {// If the available stretching area is too small for a Control,// then remove it from stretching area.msc.will_stretch = false;- stretch_ratio_total -= stretch_ratio;+ stretch_ratio_total -= msc.stretch_ratio;refit_successful = false;available_stretch_space -= msc.min_size;msc.final_size = msc.min_size;@@ -247,7 +250,7 @@ void GraphNode::_resort() {// If stretching would exceed the Control's maximum size,// cap it and redistribute its unused share.msc.will_stretch = false;- stretch_ratio_total -= stretch_ratio;+ stretch_ratio_total -= msc.stretch_ratio;refit_successful = false;available_stretch_space -= msc.max_size;msc.final_size = msc.max_size;@@ -1011,14 +1014,20 @@ Size2 GraphNode::_get_minimum_size(bool p_use_desired_sizes) const {continue;}- Size2i size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();- size.width += sb_panel->get_minimum_size().width;- if (slot_table.has(i)) {- size += slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2();- }+ Size2 slot_size = (slot_table.has(i) && slot_table[i].draw_stylebox) ? sb_slot->get_minimum_size() : Size2();++ Size2 size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();+ Size2 max_size = child->get_custom_maximum_size();++ real_t width = (max_size.width >= 0 && child->get_h_size_flags().has_flag(SIZE_MAXIMIZE)) ? max_size.width : size.width;+ real_t height = (max_size.height >= 0 && child->get_v_size_flags().has_flag(SIZE_MAXIMIZE)) ? max_size.height : size.height;++ width += sb_panel->get_minimum_size().width;+ width += slot_size.width;+ height += slot_size.height;- minsize.height += size.height;- minsize.width = MAX(minsize.width, size.width);+ minsize.width = MAX(minsize.width, width);+ minsize.height += height;if (i > 0) {minsize.height += separation;@@ -1234,6 +1243,7 @@ Vector<int> GraphNode::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -1244,6 +1254,7 @@ Vector<int> GraphNode::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.hindex c14aa1eb603..9b2a26aa2cc 100644--- a/scene/gui/graph_node.h+++ b/scene/gui/graph_node.h@@ -67,6 +67,7 @@ class GraphNode : public GraphElement {int max_size = -1;bool will_stretch = false;int final_size = 0;+ float stretch_ratio = 0.0;};enum CustomAccessibilityAction {diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cppindex 52b6c8b8a2b..0ee4e9c27a2 100644--- a/scene/gui/grid_container.cpp+++ b/scene/gui/grid_container.cpp@@ -456,17 +456,22 @@ Size2 GridContainer::_get_minimum_size(bool p_use_desired_sizes) const {int col = valid_controls_index % columns;valid_controls_index++;- Size2i ms = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();+ Size2 min_size = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();+ Size2 max_size = c->get_custom_maximum_size();++ real_t col_width = (c->get_h_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.width >= 0) ? max_size.width : min_size.width;+ real_t row_height = (c->get_v_size_flags().has_flag(SIZE_MAXIMIZE) && max_size.height >= 0) ? max_size.height : min_size.height;+if (col_minw.has(col)) {- col_minw[col] = MAX(col_minw[col], ms.width);+ col_minw[col] = MAX(col_minw[col], col_width);} else {- col_minw[col] = ms.width;+ col_minw[col] = col_width;}if (row_minh.has(row)) {- row_minh[row] = MAX(row_minh[row], ms.height);+ row_minh[row] = MAX(row_minh[row], row_height);} else {- row_minh[row] = ms.height;+ row_minh[row] = row_height;}max_col = MAX(col, max_col);max_row = MAX(row, max_row);diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cppindex 6e9e22acfc6..e185e17f40a 100644--- a/scene/gui/margin_container.cpp+++ b/scene/gui/margin_container.cpp@@ -33,17 +33,7 @@#include "scene/theme/theme_db.h"Size2 MarginContainer::get_minimum_size() const {- Size2 max;-- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);- if (!c) {- continue;- }-- Size2 s = c->get_bound_minimum_size();- max = max.max(s);- }+ Size2 max = Container::get_minimum_size();max.width += (theme_cache.margin_left + theme_cache.margin_right);max.height += (theme_cache.margin_top + theme_cache.margin_bottom);@@ -85,6 +75,7 @@ Vector<int> MarginContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -94,6 +85,7 @@ Vector<int> MarginContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cppindex 3087a51af99..397dfd56f7d 100644--- a/scene/gui/panel_container.cpp+++ b/scene/gui/panel_container.cpp@@ -33,16 +33,7 @@#include "scene/theme/theme_db.h"Size2 PanelContainer::get_minimum_size() const {- Size2 ms;- for (int i = 0; i < get_child_count(); i++) {- Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);- if (!c) {- continue;- }-- Size2 minsize = c->get_bound_minimum_size();- ms = ms.max(minsize);- }+ Size2 ms = Container::get_minimum_size();if (theme_cache.panel_style.is_valid()) {ms += theme_cache.panel_style->get_minimum_size();@@ -84,6 +75,7 @@ Vector<int> PanelContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -93,6 +85,7 @@ Vector<int> PanelContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cppindex e9440f2bff0..112dff29f5d 100644--- a/scene/gui/scroll_container.cpp+++ b/scene/gui/scroll_container.cpp@@ -52,7 +52,12 @@ Size2 ScrollContainer::_get_minimum_size(bool p_use_desired_sizes) const {}Size2 child_min_size = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();- largest_child_min_size = largest_child_min_size.max(child_min_size);+ Size2 child_max_size = c->get_custom_maximum_size();++ real_t width = (child_max_size.width >= 0 && c->get_h_size_flags().has_flag(SIZE_MAXIMIZE)) ? child_max_size.width : child_min_size.width;+ real_t height = (child_max_size.height >= 0 && c->get_v_size_flags().has_flag(SIZE_MAXIMIZE)) ? child_max_size.height : child_min_size.height;++ largest_child_min_size = largest_child_min_size.max(Size2(width, height));}Size2 min_size;diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cppindex 8d7133b6f39..3a376db972a 100644--- a/scene/gui/split_container.cpp+++ b/scene/gui/split_container.cpp@@ -545,6 +545,9 @@ void SplitContainer::_set_desired_sizes(const PackedInt32Array &p_desired_sizes,// Treat the priority child as not expanded, so it doesn't shrink with other expanded children.if (i != p_priority_index && child->get_stretch_ratio() > 0 && (vertical ? child->get_v_size_flags() : child->get_h_size_flags()).has_flag(SIZE_EXPAND)) {sdata.stretch_ratio = child->get_stretch_ratio();+ if ((vertical ? child->get_v_size_flags() : child->get_h_size_flags()).has_flag(SIZE_MAXIMIZE)) {+ sdata.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }stretch_total += sdata.stretch_ratio;}stretch_data.push_back(sdata);@@ -742,6 +745,9 @@ void SplitContainer::_update_default_dragger_positions() {sdata.final_size = sdata.min_size;if ((vertical ? child->get_v_size_flags() : child->get_h_size_flags()).has_flag(SIZE_EXPAND) && child->get_stretch_ratio() > 0) {sdata.stretch_ratio = child->get_stretch_ratio();+ if ((vertical ? child->get_v_size_flags() : child->get_h_size_flags()).has_flag(SIZE_MAXIMIZE)) {+ sdata.stretch_ratio *= MAXIMIZE_STRETCH_FACTOR;+ }stretch_total += sdata.stretch_ratio;sdata.expand_flag = true;sdata.will_stretch = true;@@ -1078,16 +1084,24 @@ Size2 SplitContainer::_get_minimum_size(bool p_use_desired_sizes) const {const int axis = vertical ? 1 : 0;const int other_axis = vertical ? 0 : 1;- Size2i minimum;-- if (valid_children.size() >= 2u) {- minimum[axis] += sep * ((int)valid_children.size() - 1);- }+ Size2 minimum;for (const Control *child : valid_children) {const Size2 min_size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();- minimum[axis] += (int)min_size[axis];- minimum[other_axis] = (int)MAX(minimum[other_axis], min_size[other_axis]);+ const Size2 max_size = child->get_custom_maximum_size();++ const bool maximize_axis = vertical ? child->get_v_size_flags().has_flag(SIZE_MAXIMIZE) : child->get_h_size_flags().has_flag(SIZE_MAXIMIZE);+ const bool maximize_other_axis = vertical ? child->get_h_size_flags().has_flag(SIZE_MAXIMIZE) : child->get_v_size_flags().has_flag(SIZE_MAXIMIZE);++ const real_t axis_size = maximize_axis && max_size[axis] >= 0 ? max_size[axis] : min_size[axis];+ const real_t other_axis_size = maximize_other_axis && max_size[other_axis] >= 0 ? max_size[other_axis] : min_size[other_axis];++ minimum[axis] += axis_size;+ minimum[other_axis] = MAX(minimum[other_axis], other_axis_size);+ }++ if (!valid_children.is_empty()) {+ minimum[axis] += sep * (valid_children.size() - 1u);}return minimum;@@ -1612,6 +1626,7 @@ Vector<int> SplitContainer::get_allowed_size_flags_horizontal() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}@@ -1624,6 +1639,7 @@ Vector<int> SplitContainer::get_allowed_size_flags_vertical() const {flags.append(SIZE_SHRINK_BEGIN);flags.append(SIZE_SHRINK_CENTER);flags.append(SIZE_SHRINK_END);+ flags.append(SIZE_MAXIMIZE);return flags;}diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cppindex 4da07b13bc7..bfcb9f93692 100644--- a/scene/gui/subviewport_container.cpp+++ b/scene/gui/subviewport_container.cpp@@ -38,18 +38,7 @@ Size2 SubViewportContainer::get_minimum_size() const {if (stretch) {return Size2();}- Size2 ms;- for (int i = 0; i < get_child_count(); i++) {- SubViewport *c = Object::cast_to<SubViewport>(get_child(i));- if (!c) {- continue;- }-- Size2 minsize = c->get_size();- ms = ms.max(minsize);- }-- return ms;+ return Container::get_minimum_size();}void SubViewportContainer::set_stretch(bool p_enable) {@@ -101,11 +90,15 @@ int SubViewportContainer::get_stretch_shrink() const {}Vector<int> SubViewportContainer::get_allowed_size_flags_horizontal() const {- return Vector<int>();+ Vector<int> flags;+ flags.append(SIZE_MAXIMIZE);+ return flags;}Vector<int> SubViewportContainer::get_allowed_size_flags_vertical() const {- return Vector<int>();+ Vector<int> flags;+ flags.append(SIZE_MAXIMIZE);+ return flags;}void SubViewportContainer::_notification(int p_what) {diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cppindex 918f680e026..e984c5c7424 100644--- a/scene/gui/tab_container.cpp+++ b/scene/gui/tab_container.cpp@@ -1040,8 +1040,13 @@ Size2 TabContainer::_get_minimum_size(bool p_use_desired_sizes) const {continue;}- Size2 cms = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();- largest_child_min_size = largest_child_min_size.max(cms);+ Size2 min_size = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();+ Size2 max_size = c->get_custom_maximum_size();++ real_t width = (max_size.x >= 0 && c->get_h_size_flags().has_flag(Control::SIZE_MAXIMIZE)) ? max_size.x : min_size.x;+ real_t height = (max_size.y >= 0 && c->get_v_size_flags().has_flag(Control::SIZE_MAXIMIZE)) ? max_size.y : min_size.y;++ largest_child_min_size = largest_child_min_size.max(Size2(width, height));}ms.height += largest_child_min_size.height;@@ -1198,11 +1203,15 @@ bool TabContainer::get_use_hidden_tabs_for_min_size() const {}Vector<int> TabContainer::get_allowed_size_flags_horizontal() const {- return Vector<int>();+ Vector<int> flags;+ flags.append(SIZE_MAXIMIZE);+ return flags;}Vector<int> TabContainer::get_allowed_size_flags_vertical() const {- return Vector<int>();+ Vector<int> flags;+ flags.append(SIZE_MAXIMIZE);+ return flags;}void TabContainer::_bind_methods() {