Skip to content

Commit

Permalink
Merge pull request godotengine#87474 from Rindbee/fix-forgetting-h_se…
Browse files Browse the repository at this point in the history
…paration-when-internal_elements-exist

Fix forgetting `h_separation` when internal elements exist
  • Loading branch information
YuriSizov committed Jan 22, 2024
2 parents b5f0334 + 567e76f commit a07df64
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,21 @@ void Button::_notification(int p_what) {

const int h_separation = MAX(0, theme_cache.h_separation);

float left_internal_margin_with_h_separation = _internal_margin[SIDE_LEFT];
float right_internal_margin_with_h_separation = _internal_margin[SIDE_RIGHT];
{ // The width reserved for internal element in derived classes (and h_separation if need).
float internal_margin = _internal_margin[SIDE_LEFT] + _internal_margin[SIDE_RIGHT];

if (!xl_text.is_empty() || h_separation_is_valid_when_no_text) {
if (_internal_margin[SIDE_LEFT] > 0.0f) {
internal_margin += h_separation;
left_internal_margin_with_h_separation += h_separation;
}

if (_internal_margin[SIDE_RIGHT] > 0.0f) {
internal_margin += h_separation;
right_internal_margin_with_h_separation += h_separation;
}
}

drawable_size_remained.width -= internal_margin; // The size after the internal element is stripped.
drawable_size_remained.width -= left_internal_margin_with_h_separation + right_internal_margin_with_h_separation; // The size after the internal element is stripped.
}

HorizontalAlignment icon_align_rtl_checked = horizontal_icon_alignment;
Expand Down Expand Up @@ -308,12 +309,12 @@ void Button::_notification(int p_what) {
case HORIZONTAL_ALIGNMENT_FILL:
case HORIZONTAL_ALIGNMENT_LEFT: {
icon_ofs.x += style_margin_left;
icon_ofs.x += _internal_margin[SIDE_LEFT];
icon_ofs.x += left_internal_margin_with_h_separation;
} break;

case HORIZONTAL_ALIGNMENT_RIGHT: {
icon_ofs.x = size.x - style_margin_right;
icon_ofs.x -= _internal_margin[SIDE_RIGHT];
icon_ofs.x -= right_internal_margin_with_h_separation;
icon_ofs.x -= icon_size.width;
} break;
}
Expand Down Expand Up @@ -368,7 +369,7 @@ void Button::_notification(int p_what) {
case HORIZONTAL_ALIGNMENT_LEFT:
case HORIZONTAL_ALIGNMENT_RIGHT: {
text_ofs.x += style_margin_left;
text_ofs.x += _internal_margin[SIDE_LEFT];
text_ofs.x += left_internal_margin_with_h_separation;
if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
// Offset by the space's width that occupied by icon and h_separation together.
text_ofs.x += custom_element_size.width - drawable_size_remained.width;
Expand Down

0 comments on commit a07df64

Please sign in to comment.