From 7496f99060d7655cbf974dba3851838faba629d4 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Tue, 30 Jan 2024 17:35:46 +0100 Subject: [PATCH] Create a MainScreenButton theme variation This turns custom font theme properties into a proper variation, which makes applying it simpler. --- editor/editor_node.cpp | 15 +++++---------- editor/themes/editor_fonts.cpp | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e676d24c67e..579b526b5eb 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -519,11 +519,6 @@ void EditorNode::_update_theme(bool p_skip_creation) { help_menu->set_item_icon(help_menu->get_item_index(HELP_ABOUT), theme->get_icon(SNAME("Godot"), EditorStringName(EditorIcons))); help_menu->set_item_icon(help_menu->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), theme->get_icon(SNAME("Heart"), EditorStringName(EditorIcons))); - for (int i = 0; i < main_editor_buttons.size(); i++) { - main_editor_buttons.write[i]->add_theme_font_override("font", theme->get_font(SNAME("main_button_font"), EditorStringName(EditorFonts))); - main_editor_buttons.write[i]->add_theme_font_size_override("font_size", theme->get_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts))); - } - if (EditorDebuggerNode::get_singleton()->is_visible()) { bottom_panel->add_theme_style_override("panel", theme->get_stylebox(SNAME("BottomPanelDebuggerOverride"), EditorStringName(EditorStyles))); } @@ -3279,21 +3274,21 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed Button *tb = memnew(Button); tb->set_flat(true); tb->set_toggle_mode(true); - tb->connect("pressed", callable_mp(singleton, &EditorNode::editor_select).bind(singleton->main_editor_buttons.size())); + tb->set_theme_type_variation("MainScreenButton"); tb->set_name(p_editor->get_name()); tb->set_text(p_editor->get_name()); Ref icon = p_editor->get_icon(); + if (icon.is_null() && singleton->theme->has_icon(p_editor->get_name(), EditorStringName(EditorIcons))) { + icon = singleton->theme->get_icon(p_editor->get_name(), EditorStringName(EditorIcons)); + } if (icon.is_valid()) { tb->set_icon(icon); // Make sure the control is updated if the icon is reimported. icon->connect_changed(callable_mp((Control *)tb, &Control::update_minimum_size)); - } else if (singleton->theme->has_icon(p_editor->get_name(), EditorStringName(EditorIcons))) { - tb->set_icon(singleton->theme->get_icon(p_editor->get_name(), EditorStringName(EditorIcons))); } - tb->add_theme_font_override("font", singleton->theme->get_font(SNAME("main_button_font"), EditorStringName(EditorFonts))); - tb->add_theme_font_size_override("font_size", singleton->theme->get_font_size(SNAME("main_button_font_size"), EditorStringName(EditorFonts))); + tb->connect("pressed", callable_mp(singleton, &EditorNode::editor_select).bind(singleton->main_editor_buttons.size())); singleton->main_editor_buttons.push_back(tb); singleton->main_editor_button_hb->add_child(tb); diff --git a/editor/themes/editor_fonts.cpp b/editor/themes/editor_fonts.cpp index ee613877027..a4f72b26e3e 100644 --- a/editor/themes/editor_fonts.cpp +++ b/editor/themes/editor_fonts.cpp @@ -390,8 +390,9 @@ void editor_register_fonts(const Ref &p_theme) { p_theme->set_font("title", EditorStringName(EditorFonts), bold_fc); p_theme->set_font_size("title_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE); - p_theme->set_font("main_button_font", EditorStringName(EditorFonts), bold_fc); - p_theme->set_font_size("main_button_font_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE); + p_theme->set_type_variation("MainScreenButton", "Button"); + p_theme->set_font("font", "MainScreenButton", bold_fc); + p_theme->set_font_size("font_size", "MainScreenButton", default_font_size + 2 * EDSCALE); p_theme->set_font("font", "Label", default_fc);