Merge pull request #75958 from Rindbee/update_size_cache_in_Button

Update size or size cache when toggling `expand_icon` in `Button`
This commit is contained in:
Rémi Verschelde 2023-05-17 11:25:16 +02:00
commit 019fef758f
No known key found for this signature in database
GPG key ID: C3336907360768E1
4 changed files with 13 additions and 8 deletions

View file

@ -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();
@ -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();
}

View file

@ -100,6 +100,7 @@ private:
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();

View file

@ -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;
@ -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) {
@ -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) {
@ -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) {
@ -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) {
@ -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;
}
@ -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 {

View file

@ -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;