Merge pull request #89462 from RobProductions/fix-external-theme-margin

Fix main editor button margins while using a custom theme
This commit is contained in:
Rémi Verschelde 2024-03-14 22:35:11 +01:00
commit 520ff5cb17
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 29 additions and 23 deletions

View File

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

View File

@ -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<ConfigFile> p_config_file, c
Button *EditorBottomPanel::add_item(String p_text, Control *p_item, const Ref<Shortcut> &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);

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) {