1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-18 14:21:41 +00:00

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
This commit is contained in:
Matt Enad
2024-03-06 22:00:10 -05:00
parent 006f5bc11c
commit d4ac3fabac
3 changed files with 29 additions and 23 deletions

View File

@@ -1742,29 +1742,40 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &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<StyleBoxFlat> 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<StyleBoxFlat> 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<StyleBoxFlat> main_screen_button_transparent = menu_transparent_style->duplicate();
Ref<StyleBoxFlat> 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<StyleBoxFlat> 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<EditorTheme> &p_theme
Ref<StyleBoxFlat> 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) {