Skip to content

Commit

Permalink
Merge pull request #75958 from Rindbee/update_size_cache_in_Button
Browse files Browse the repository at this point in the history
Update size or size cache when toggling `expand_icon` in `Button`
  • Loading branch information
akien-mga committed May 17, 2023
2 parents 56fc631 + 9bd1d3b commit 019fef7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void Button::_set_internal_margin(Side p_side, float p_value) {
_internal_margin[p_side] = p_value;
}

void Button::_queue_update_size_cache() {
}

void Button::_update_theme_item_cache() {
BaseButton::_update_theme_item_cache();

Expand Down Expand Up @@ -544,6 +547,7 @@ Ref<Texture2D> Button::get_icon() const {
void Button::set_expand_icon(bool p_enabled) {
if (expand_icon != p_enabled) {
expand_icon = p_enabled;
_queue_update_size_cache();
queue_redraw();
update_minimum_size();
}
Expand Down
1 change: 1 addition & 0 deletions scene/gui/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Button : public BaseButton {
protected:
void _set_internal_margin(Side p_side, float p_value);
virtual void _update_theme_item_cache() override;
virtual void _queue_update_size_cache();
void _notification(int p_what);
static void _bind_methods();

Expand Down
14 changes: 7 additions & 7 deletions scene/gui/option_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool OptionButton::_set(const StringName &p_name, const Variant &p_value) {
}

if (property == "text" || property == "icon") {
_queue_refresh_cache();
_queue_update_size_cache();
}

return valid;
Expand Down Expand Up @@ -243,7 +243,7 @@ void OptionButton::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_l
if (first_selectable) {
select(get_item_count() - 1);
}
_queue_refresh_cache();
_queue_update_size_cache();
}

void OptionButton::add_item(const String &p_label, int p_id) {
Expand All @@ -252,7 +252,7 @@ void OptionButton::add_item(const String &p_label, int p_id) {
if (first_selectable) {
select(get_item_count() - 1);
}
_queue_refresh_cache();
_queue_update_size_cache();
}

void OptionButton::set_item_text(int p_idx, const String &p_text) {
Expand All @@ -261,7 +261,7 @@ void OptionButton::set_item_text(int p_idx, const String &p_text) {
if (current == p_idx) {
set_text(p_text);
}
_queue_refresh_cache();
_queue_update_size_cache();
}

void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
Expand All @@ -270,7 +270,7 @@ void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
if (current == p_idx) {
set_icon(p_icon);
}
_queue_refresh_cache();
_queue_update_size_cache();
}

void OptionButton::set_item_id(int p_idx, int p_id) {
Expand Down Expand Up @@ -456,7 +456,7 @@ void OptionButton::_refresh_size_cache() {
update_minimum_size();
}

void OptionButton::_queue_refresh_cache() {
void OptionButton::_queue_update_size_cache() {
if (cache_refresh_pending) {
return;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ void OptionButton::remove_item(int p_idx) {
if (current == p_idx) {
_select(NONE_SELECTED);
}
_queue_refresh_cache();
_queue_update_size_cache();
}

PopupMenu *OptionButton::get_popup() const {
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/option_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class OptionButton : public Button {
void _select(int p_which, bool p_emit = false);
void _select_int(int p_which);
void _refresh_size_cache();
void _queue_refresh_cache();

virtual void pressed() override;

protected:
Size2 get_minimum_size() const override;
virtual void _update_theme_item_cache() override;
virtual void _queue_update_size_cache() override;
void _notification(int p_what);
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
Expand Down

0 comments on commit 019fef7

Please sign in to comment.