From 5dd854513eb90d4923f3822c3cb6e9b348ad5936 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Mon, 7 Aug 2023 17:25:10 +0800 Subject: [PATCH] Fix OptionButton min size when fit longest item is enabled --- scene/gui/option_button.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 8138a66f640..2b8c85c823d 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -78,6 +78,7 @@ void OptionButton::_update_theme_item_cache() { void OptionButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_POSTINITIALIZE: { + _refresh_size_cache(); if (has_theme_icon(SNAME("arrow"))) { if (is_layout_rtl()) { _set_internal_margin(SIDE_LEFT, theme_cache.arrow_icon->get_width()); @@ -446,7 +447,7 @@ void OptionButton::_refresh_size_cache() { cache_refresh_pending = false; if (fit_to_longest_item) { - _cached_size = Vector2(); + _cached_size = theme_cache.normal->get_minimum_size(); for (int i = 0; i < get_item_count(); i++) { _cached_size = _cached_size.max(get_minimum_size_for_text_and_icon(popup->get_item_xl_text(i), get_item_icon(i))); } @@ -595,7 +596,6 @@ OptionButton::OptionButton(const String &p_text) : popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected)); popup->connect("id_focused", callable_mp(this, &OptionButton::_focused)); popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed).bind(false)); - _refresh_size_cache(); } OptionButton::~OptionButton() {