Skip to content

Commit

Permalink
Merge pull request godotengine#93128 from bruvzg/button_internal_margin
Browse files Browse the repository at this point in the history
[Button] Do not include internal margins into base button minimum size.
  • Loading branch information
akien-mga committed Jun 13, 2024
2 parents 8c380a0 + 35b4b5f commit 172b4dc
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ Size2 Button::_fit_icon_size(const Size2 &p_size) const {
}

Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const {
// Do not include `_internal_margin`, it's already added in the `get_minimum_size` overrides.

Ref<TextParagraph> paragraph;
if (p_text.is_empty()) {
paragraph = text_buf;
Expand All @@ -500,21 +502,6 @@ Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref<Textu
minsize.width = 0;
}

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 needed).

if (_internal_margin[SIDE_LEFT] > 0.0f) {
left_internal_margin_with_h_separation += theme_cache.h_separation;
}

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

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

if (!expand_icon && p_icon.is_valid()) {
Size2 icon_size = _fit_icon_size(p_icon->get_size());
if (vertical_icon_alignment == VERTICAL_ALIGNMENT_CENTER) {
Expand Down

0 comments on commit 172b4dc

Please sign in to comment.