From 4a3a15c30433f1c9b28873a74c23bec6564a3bc8 Mon Sep 17 00:00:00 2001 From: Rindbee Date: Fri, 12 Aug 2022 19:39:22 +0800 Subject: [PATCH] Fix case where `h_separation` might not work in `Button` This patch mainly solves two things: 1. The typo of `h_separation`; 2. Negative values of `h_separation` will be treated as `0` when used, to prevent the button's minimum `width` from being reduced by `h_separation`. --- doc/classes/Button.xml | 2 +- doc/classes/CheckBox.xml | 2 +- doc/classes/CheckButton.xml | 2 +- doc/classes/MenuButton.xml | 2 +- doc/classes/OptionButton.xml | 2 +- scene/gui/button.cpp | 10 ++++------ scene/gui/check_box.cpp | 2 +- scene/gui/check_button.cpp | 2 +- scene/gui/option_button.cpp | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/doc/classes/Button.xml b/doc/classes/Button.xml index 1cd9ca0afb3a..e78cdfc95111 100644 --- a/doc/classes/Button.xml +++ b/doc/classes/Button.xml @@ -114,7 +114,7 @@ Icon modulate [Color] used when the [Button] is being pressed. - The horizontal space between [Button]'s icon and text. + The horizontal space between [Button]'s icon and text. Negative values will be treated as [code]0[/code] when used. The size of the text outline. diff --git a/doc/classes/CheckBox.xml b/doc/classes/CheckBox.xml index 6483faf7632b..d39b75ae5291 100644 --- a/doc/classes/CheckBox.xml +++ b/doc/classes/CheckBox.xml @@ -39,7 +39,7 @@ The vertical offset used when rendering the check icons (in pixels). - The separation between the check icon and the text (in pixels). + The separation between the check icon and the text (in pixels). Negative values will be treated as [code]0[/code] when used. The size of the text outline. diff --git a/doc/classes/CheckButton.xml b/doc/classes/CheckButton.xml index 51b0411f4e54..f49da6992608 100644 --- a/doc/classes/CheckButton.xml +++ b/doc/classes/CheckButton.xml @@ -39,7 +39,7 @@ The vertical offset used when rendering the toggle icons (in pixels). - The separation between the toggle icon and the text (in pixels). + The separation between the toggle icon and the text (in pixels). Negative values will be treated as [code]0[/code] when used. The size of the text outline. diff --git a/doc/classes/MenuButton.xml b/doc/classes/MenuButton.xml index 8baa7242924d..1f38510e83e8 100644 --- a/doc/classes/MenuButton.xml +++ b/doc/classes/MenuButton.xml @@ -65,7 +65,7 @@ Text [Color] used when the [MenuButton] is being pressed. - The horizontal space between [MenuButton]'s icon and text. + The horizontal space between [MenuButton]'s icon and text. Negative values will be treated as [code]0[/code] when used. The size of the text outline. diff --git a/doc/classes/OptionButton.xml b/doc/classes/OptionButton.xml index 8f2660ad613f..801ab2dcddc5 100644 --- a/doc/classes/OptionButton.xml +++ b/doc/classes/OptionButton.xml @@ -246,7 +246,7 @@ The horizontal space between the arrow icon and the right edge of the button. - The horizontal space between [OptionButton]'s icon and text. + The horizontal space between [OptionButton]'s icon and text. Negative values will be treated as [code]0[/code] when used. If different than [code]0[/code], the arrow icon will be modulated to the font color. diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 0a163b65ff1a..e163f4355c2f 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -34,11 +34,9 @@ #include "servers/rendering_server.h" Size2 Button::get_minimum_size() const { - Ref _icon; - if (icon.is_null() && has_theme_icon(SNAME("icon"))) { + Ref _icon = icon; + if (_icon.is_null() && has_theme_icon(SNAME("icon"))) { _icon = Control::get_theme_icon(SNAME("icon")); - } else { - _icon = icon; } return get_minimum_size_for_text_and_icon("", _icon); @@ -342,13 +340,13 @@ Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Refget_height()); if (icon_alignment != HORIZONTAL_ALIGNMENT_CENTER) { minsize.width += p_icon->get_width(); if (!xl_text.is_empty() || !p_text.is_empty()) { - minsize.width += get_theme_constant(SNAME("hseparation")); + minsize.width += MAX(0, get_theme_constant(SNAME("h_separation"))); } } else { minsize.width = MAX(minsize.width, p_icon->get_width()); diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index cb80f5b5ef9d..26edc1f1b077 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -75,7 +75,7 @@ Size2 CheckBox::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_theme_constant(SNAME("h_separation")); + minsize.width += MAX(0, get_theme_constant(SNAME("h_separation"))); } Ref sb = get_theme_stylebox(SNAME("normal")); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM)); diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index a09873ea4f20..b9674ca41ec8 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -52,7 +52,7 @@ Size2 CheckButton::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_theme_constant(SNAME("h_separation")); + minsize.width += MAX(0, get_theme_constant(SNAME("h_separation"))); } Ref sb = get_theme_stylebox(SNAME("normal")); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM)); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index b26410e31855..b8799c3a5b3d 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -47,7 +47,7 @@ Size2 OptionButton::get_minimum_size() const { const Size2 arrow_size = Control::get_theme_icon(SNAME("arrow"))->get_size(); Size2 content_size = minsize - padding; - content_size.width += arrow_size.width + get_theme_constant(SNAME("h_separation")); + content_size.width += arrow_size.width + MAX(0, get_theme_constant(SNAME("h_separation"))); content_size.height = MAX(content_size.height, arrow_size.height); minsize = content_size + padding;