Godot Engine – Multi-platform 2D and 3D game engine
Make the OptionButton match the width of the pop-up menu
风青山b887d57671d8
diff --git a/editor/animation/animation_player_editor_plugin.cpp b/editor/animation/animation_player_editor_plugin.cppindex a186955be77..3a562c427ff 100644--- a/editor/animation/animation_player_editor_plugin.cpp+++ b/editor/animation/animation_player_editor_plugin.cpp@@ -2158,6 +2158,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_pluganimation->set_h_size_flags(SIZE_EXPAND_FILL);animation->set_tooltip_text(TTRC("Display list of animations in player."));animation->set_clip_text(true);+ animation->set_fit_to_longest_item(false);animation->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);autoplay = memnew(Button);diff --git a/editor/asset_library/asset_library_editor_plugin.cpp b/editor/asset_library/asset_library_editor_plugin.cppindex 4addbfb06c0..3378c732ef3 100644--- a/editor/asset_library/asset_library_editor_plugin.cpp+++ b/editor/asset_library/asset_library_editor_plugin.cpp@@ -2127,6 +2127,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {sort->set_h_size_flags(Control::SIZE_EXPAND_FILL);sort->set_clip_text(true);+ sort->set_fit_to_longest_item(false);sort->connect(SceneStringName(item_selected), callable_mp(this, &EditorAssetLibrary::_search).bind(1).unbind(1));search_hb2->add_child(memnew(Label(TTRC("Category:"))));@@ -2138,6 +2139,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {}categories->set_disabled(true);categories->set_clip_text(true);+ categories->set_fit_to_longest_item(false);categories->set_h_size_flags(Control::SIZE_EXPAND_FILL);search_hb2->add_child(categories);categories->connect(SceneStringName(item_selected), callable_mp(this, &EditorAssetLibrary::_search).bind(1).unbind(1));@@ -2146,6 +2148,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {repository = memnew(OptionButton);repository->set_h_size_flags(Control::SIZE_EXPAND_FILL);repository->set_clip_text(true);+ repository->set_fit_to_longest_item(false);search_hb2->add_child(repository);repository->connect(SceneStringName(item_selected), callable_mp(this, &EditorAssetLibrary::_repository_changed));_update_repository_options();diff --git a/editor/audio/editor_audio_buses.cpp b/editor/audio/editor_audio_buses.cppindex bd8934fcede..cd94423af55 100644--- a/editor/audio/editor_audio_buses.cpp+++ b/editor/audio/editor_audio_buses.cpp@@ -1142,6 +1142,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {send->set_accessibility_name(TTRC("Send"));send->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);send->set_clip_text(true);+ send->set_fit_to_longest_item(false);send->connect(SceneStringName(item_selected), callable_mp(this, &EditorAudioBus::_send_selected));vb->add_child(send);diff --git a/editor/inspector/editor_properties.cpp b/editor/inspector/editor_properties.cppindex e537db06c3c..1b6ad68f067 100644--- a/editor/inspector/editor_properties.cpp+++ b/editor/inspector/editor_properties.cpp@@ -585,6 +585,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() {option_button->set_accessibility_name(TTRC("Enum Options"));option_button->set_h_size_flags(SIZE_EXPAND_FILL);option_button->set_clip_text(true);+ option_button->set_fit_to_longest_item(false);option_button->set_flat(true);option_button->set_search_bar_enabled(true);option_button->set_search_bar_min_item_count(10);@@ -997,6 +998,7 @@ OptionButton *EditorPropertyEnum::get_option_button() {EditorPropertyEnum::EditorPropertyEnum() {options = memnew(OptionButton);options->set_clip_text(true);+ options->set_fit_to_longest_item(false);options->set_flat(true);options->set_theme_type_variation(SNAME("EditorInspectorButton"));options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);diff --git a/editor/project_manager/project_manager.cpp b/editor/project_manager/project_manager.cppindex 8b3db0e82a1..b43b7c30841 100644--- a/editor/project_manager/project_manager.cpp+++ b/editor/project_manager/project_manager.cpp@@ -1568,6 +1568,7 @@ ProjectManager::ProjectManager() {filter_option = memnew(OptionButton);filter_option->set_clip_text(true);+ filter_option->set_fit_to_longest_item(false);filter_option->set_h_size_flags(Control::SIZE_EXPAND_FILL);filter_option->set_stretch_ratio(0.3);filter_option->set_accessibility_name(TTRC("Sort:"));diff --git a/editor/scene/gui/control_editor_plugin.cpp b/editor/scene/gui/control_editor_plugin.cppindex e40f2720850..bc46f7b0593 100644--- a/editor/scene/gui/control_editor_plugin.cpp+++ b/editor/scene/gui/control_editor_plugin.cpp@@ -244,6 +244,7 @@ void EditorPropertyAnchorsPreset::setup(const Vector<String> &p_options) {EditorPropertyAnchorsPreset::EditorPropertyAnchorsPreset() {options = memnew(OptionButton);options->set_clip_text(true);+ options->set_fit_to_longest_item(false);options->set_flat(true);options->set_theme_type_variation(SNAME("EditorInspectorButton"));add_child(options);@@ -427,6 +428,7 @@ EditorPropertySizeFlags::EditorPropertySizeFlags() {flag_presets = memnew(OptionButton);flag_presets->set_clip_text(true);+ flag_presets->set_fit_to_longest_item(false);flag_presets->set_flat(true);flag_presets->set_theme_type_variation(SNAME("EditorInspectorButton"));vb->add_child(flag_presets);diff --git a/editor/version_control/version_control_editor_plugin.cpp b/editor/version_control/version_control_editor_plugin.cppindex 59289c326a8..a96a81f2a1f 100644--- a/editor/version_control/version_control_editor_plugin.cpp+++ b/editor/version_control/version_control_editor_plugin.cpp@@ -1403,6 +1403,7 @@ VersionControlEditorPlugin::VersionControlEditorPlugin() {branch_select->set_tooltip_text(TTR("Branches"));branch_select->set_h_size_flags(Control::SIZE_EXPAND_FILL);branch_select->set_clip_text(true);+ branch_select->set_fit_to_longest_item(false);branch_select->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_branch_item_selected));branch_select->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_branch_list));menu_bar->add_child(branch_select);@@ -1450,6 +1451,7 @@ VersionControlEditorPlugin::VersionControlEditorPlugin() {remote_select->set_tooltip_text(TTR("Remotes"));remote_select->set_h_size_flags(Control::SIZE_EXPAND_FILL);remote_select->set_clip_text(true);+ remote_select->set_fit_to_longest_item(false);remote_select->connect(SceneStringName(item_selected), callable_mp(this, &VersionControlEditorPlugin::_remote_selected));remote_select->connect(SceneStringName(pressed), callable_mp(this, &VersionControlEditorPlugin::_refresh_remote_list));menu_bar->add_child(remote_select);diff --git a/modules/openxr/editor/openxr_binding_modifier_editor.cpp b/modules/openxr/editor/openxr_binding_modifier_editor.cppindex d4da9b4ab28..d54c56948f3 100644--- a/modules/openxr/editor/openxr_binding_modifier_editor.cpp+++ b/modules/openxr/editor/openxr_binding_modifier_editor.cpp@@ -85,6 +85,7 @@ void EditorPropertyActionSet::set_option_button_clip(bool p_enable) {EditorPropertyActionSet::EditorPropertyActionSet() {options = memnew(OptionButton);options->set_clip_text(true);+ options->set_fit_to_longest_item(false);options->set_flat(true);options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);add_child(options);@@ -155,6 +156,7 @@ void EditorPropertyBindingPath::set_option_button_clip(bool p_enable) {EditorPropertyBindingPath::EditorPropertyBindingPath() {options = memnew(OptionButton);options->set_clip_text(true);+ options->set_fit_to_longest_item(false);options->set_flat(true);options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);add_child(options);diff --git a/modules/visual_shader/editor/visual_shader_editor_plugin.cpp b/modules/visual_shader/editor/visual_shader_editor_plugin.cppindex 6384fc97988..27d81d21197 100644--- a/modules/visual_shader/editor/visual_shader_editor_plugin.cpp+++ b/modules/visual_shader/editor/visual_shader_editor_plugin.cpp@@ -8368,6 +8368,7 @@ EditorPropertyVisualShaderMode::EditorPropertyVisualShaderMode() {options = memnew(OptionButton);options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);options->set_clip_text(true);+ options->set_fit_to_longest_item(false);add_child(options);add_focusable(options);options->connect(SceneStringName(item_selected), callable_mp(this, &EditorPropertyVisualShaderMode::_option_selected));diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cppindex 06c1f4444c1..eaa1c707613 100644--- a/scene/gui/file_dialog.cpp+++ b/scene/gui/file_dialog.cpp@@ -2627,6 +2627,7 @@ FileDialog::FileDialog() {filter->set_stretch_ratio(3);filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);filter->set_clip_text(true); // Too many extensions overflows it.+ filter->set_fit_to_longest_item(false);file_box->add_child(filter);filter->connect(SceneStringName(item_selected), callable_mp(this, &FileDialog::_filter_selected));diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cppindex b37f0330bce..4e7731cbd24 100644--- a/scene/gui/option_button.cpp+++ b/scene/gui/option_button.cpp@@ -71,6 +71,11 @@ Size2 OptionButton::get_minimum_size() const {minsize = content_size + padding;}+ if (fit_to_longest_item) {+ // Make the width at least the width of the popup.+ minsize.width = MAX(minsize.width, popup->get_contents_minimum_size().width);+ }+return minsize;}