From d4ac3fabac437ab194b5666392db97f34e1306a0 Mon Sep 17 00:00:00 2001 From: Matt Enad Date: Wed, 6 Mar 2024 22:00:10 -0500 Subject: [PATCH] Fix main button margins in custom themes Defined more theme variations and styleboxes for those variations to work around an issue where external editor themes would apply incorrect margins to certain buttons. This should eliminate clipping/alignment issues while a custom theme is in use. Also simplified the step where margins are copied over thanks to @Rindbee 's suggestion --- editor/editor_node.cpp | 5 ++-- editor/gui/editor_bottom_panel.cpp | 6 +--- editor/themes/editor_theme_manager.cpp | 41 ++++++++++++++++---------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 89e5e3f3b07..3abf0582bca 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -517,9 +517,8 @@ void EditorNode::_update_theme(bool p_skip_creation) { scene_root_parent->add_theme_style_override("panel", theme->get_stylebox(SNAME("Content"), EditorStringName(EditorStyles))); bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles))); - main_menu->add_theme_style_override("pressed", theme->get_stylebox(SNAME("MenuTransparent"), EditorStringName(EditorStyles))); distraction_free->set_icon(theme->get_icon(SNAME("DistractionFree"), EditorStringName(EditorIcons))); - distraction_free->add_theme_style_override("pressed", theme->get_stylebox(SNAME("MenuTransparent"), EditorStringName(EditorStyles))); + distraction_free->add_theme_style_override("pressed", theme->get_stylebox("normal", "FlatMenuButton")); help_menu->set_item_icon(help_menu->get_item_index(HELP_SEARCH), theme->get_icon(SNAME("HelpSearch"), EditorStringName(EditorIcons))); help_menu->set_item_icon(help_menu->get_item_index(HELP_COPY_SYSTEM_INFO), theme->get_icon(SNAME("ActionCopy"), EditorStringName(EditorIcons))); @@ -6638,7 +6637,7 @@ EditorNode::EditorNode() { main_menu = memnew(MenuBar); title_bar->add_child(main_menu); - main_menu->set_theme_type_variation("FlatMenuButton"); + main_menu->set_theme_type_variation("MainMenuBar"); main_menu->set_start_index(0); // Main menu, add to the start of global menu. main_menu->set_prefer_global_menu(global_menu); main_menu->set_switch_on_hover(true); diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index e567e42bdb6..1c95b546f47 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -50,10 +50,6 @@ void EditorBottomPanel::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { expand_button->set_icon(get_editor_theme_icon(SNAME("ExpandBottomDock"))); - for (int i = 0; i < items.size(); i++) { - items.write[i].button->add_theme_style_override("pressed", get_theme_stylebox(SNAME("MenuTransparent"), EditorStringName(EditorStyles))); - items.write[i].button->add_theme_style_override("hover_pressed", get_theme_stylebox(SNAME("MenuHover"), EditorStringName(EditorStyles))); - } } break; } } @@ -160,7 +156,7 @@ void EditorBottomPanel::load_layout_from_config(Ref p_config_file, c Button *EditorBottomPanel::add_item(String p_text, Control *p_item, const Ref &p_shortcut, bool p_at_front) { Button *tb = memnew(Button); - tb->set_theme_type_variation("FlatMenuButton"); + tb->set_theme_type_variation("BottomPanelButton"); tb->connect("toggled", callable_mp(this, &EditorBottomPanel::_switch_by_control).bind(p_item)); tb->set_drag_forwarding(Callable(), callable_mp(this, &EditorBottomPanel::_button_drag_hover).bind(tb, p_item), Callable()); tb->set_text(p_text); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 1f451487cb6..bb4dce808c8 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -1742,29 +1742,40 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme p_theme->set_stylebox("ScriptEditorPanelFloating", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); p_theme->set_stylebox("ScriptEditor", EditorStringName(EditorStyles), make_empty_stylebox(0, 0, 0, 0)); - // Bottom panel. - Ref style_bottom_panel = p_config.content_panel_style->duplicate(); - style_bottom_panel->set_corner_radius_all(p_config.corner_radius * EDSCALE); - p_theme->set_stylebox("BottomPanel", EditorStringName(EditorStyles), style_bottom_panel); - // Main menu. Ref menu_transparent_style = p_config.button_style->duplicate(); menu_transparent_style->set_bg_color(Color(1, 1, 1, 0)); menu_transparent_style->set_border_width_all(0); - Ref main_screen_button_transparent = menu_transparent_style->duplicate(); + Ref main_screen_button_hover = p_config.button_style_hover->duplicate(); for (int i = 0; i < 4; i++) { - menu_transparent_style->set_content_margin((Side)i, p_config.button_style->get_margin((Side)i) + p_config.button_style->get_border_width((Side)i)); + menu_transparent_style->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i)); + main_screen_button_hover->set_content_margin((Side)i, p_config.button_style_hover->get_content_margin((Side)i)); } - p_theme->set_stylebox("MenuTransparent", EditorStringName(EditorStyles), menu_transparent_style); - p_theme->set_stylebox("MenuHover", EditorStringName(EditorStyles), p_config.button_style_hover); - p_theme->set_stylebox("normal", "MainScreenButton", main_screen_button_transparent); - p_theme->set_stylebox("pressed", "MainScreenButton", main_screen_button_transparent); - p_theme->set_stylebox("hover_pressed", "MainScreenButton", p_config.button_style_hover); + p_theme->set_stylebox("normal", "MainScreenButton", menu_transparent_style); + p_theme->set_stylebox("pressed", "MainScreenButton", menu_transparent_style); + p_theme->set_stylebox("hover", "MainScreenButton", main_screen_button_hover); + p_theme->set_stylebox("hover_pressed", "MainScreenButton", main_screen_button_hover); + + p_theme->set_type_variation("MainMenuBar", "FlatMenuButton"); + p_theme->set_stylebox("normal", "MainMenuBar", menu_transparent_style); + p_theme->set_stylebox("pressed", "MainMenuBar", main_screen_button_hover); + p_theme->set_stylebox("hover", "MainMenuBar", main_screen_button_hover); + p_theme->set_stylebox("hover_pressed", "MainMenuBar", main_screen_button_hover); // Run bar. p_theme->set_type_variation("RunBarButton", "FlatMenuButton"); p_theme->set_stylebox("disabled", "RunBarButton", menu_transparent_style); p_theme->set_stylebox("pressed", "RunBarButton", menu_transparent_style); + + // Bottom panel. + Ref style_bottom_panel = p_config.content_panel_style->duplicate(); + style_bottom_panel->set_corner_radius_all(p_config.corner_radius * EDSCALE); + p_theme->set_stylebox("BottomPanel", EditorStringName(EditorStyles), style_bottom_panel); + p_theme->set_type_variation("BottomPanelButton", "FlatMenuButton"); + p_theme->set_stylebox("normal", "BottomPanelButton", menu_transparent_style); + p_theme->set_stylebox("pressed", "BottomPanelButton", menu_transparent_style); + p_theme->set_stylebox("hover_pressed", "BottomPanelButton", main_screen_button_hover); + p_theme->set_stylebox("hover", "BottomPanelButton", main_screen_button_hover); } // Editor GUI widgets. @@ -1821,9 +1832,9 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme Ref style_flat_button_pressed = p_config.button_style_pressed->duplicate(); for (int i = 0; i < 4; i++) { - style_flat_button->set_content_margin((Side)i, p_config.button_style->get_margin((Side)i) + p_config.button_style->get_border_width((Side)i)); - style_flat_button_hover->set_content_margin((Side)i, p_config.button_style->get_margin((Side)i) + p_config.button_style->get_border_width((Side)i)); - style_flat_button_pressed->set_content_margin((Side)i, p_config.button_style->get_margin((Side)i) + p_config.button_style->get_border_width((Side)i)); + style_flat_button->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i)); + style_flat_button_hover->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i)); + style_flat_button_pressed->set_content_margin((Side)i, p_config.button_style->get_content_margin((Side)i)); } Color flat_pressed_color = p_config.dark_color_1.lightened(0.24).lerp(p_config.accent_color, 0.2) * Color(0.8, 0.8, 0.8, 0.85); if (p_config.dark_theme) {