Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case where h_separation might not work in Button #64218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/classes/Button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
Icon modulate [Color] used when the [Button] is being pressed.
</theme_item>
<theme_item name="h_separation" data_type="constant" type="int" default="2">
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.
</theme_item>
<theme_item name="outline_size" data_type="constant" type="int" default="0">
The size of the text outline.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CheckBox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
The vertical offset used when rendering the check icons (in pixels).
</theme_item>
<theme_item name="h_separation" data_type="constant" type="int" default="4">
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.
</theme_item>
<theme_item name="outline_size" data_type="constant" type="int" default="0">
The size of the text outline.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CheckButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
The vertical offset used when rendering the toggle icons (in pixels).
</theme_item>
<theme_item name="h_separation" data_type="constant" type="int" default="4">
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.
</theme_item>
<theme_item name="outline_size" data_type="constant" type="int" default="0">
The size of the text outline.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/MenuButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
Text [Color] used when the [MenuButton] is being pressed.
</theme_item>
<theme_item name="h_separation" data_type="constant" type="int" default="3">
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.
</theme_item>
<theme_item name="outline_size" data_type="constant" type="int" default="0">
The size of the text outline.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/OptionButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
The horizontal space between the arrow icon and the right edge of the button.
</theme_item>
<theme_item name="h_separation" data_type="constant" type="int" default="2">
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.
</theme_item>
<theme_item name="modulate_arrow" data_type="constant" type="int" default="0">
If different than [code]0[/code], the arrow icon will be modulated to the font color.
Expand Down
10 changes: 4 additions & 6 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
#include "servers/rendering_server.h"

Size2 Button::get_minimum_size() const {
Ref<Texture2D> _icon;
if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
Ref<Texture2D> _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);
Expand Down Expand Up @@ -342,13 +340,13 @@ Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref<Textu
minsize.width = 0;
}

if (!expand_icon && !p_icon.is_null()) {
if (!expand_icon && p_icon.is_valid()) {
minsize.height = MAX(minsize.height, p_icon->get_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")));
KoBeWi marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
minsize.width = MAX(minsize.width, p_icon->get_width());
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/check_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM));
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/check_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM));
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/option_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down