Split theme generation logic into several subroutines
This change introduces a new theme configuration struct to be passed to the aforementioned routines to better control reuse of styles and definitions in the generator. Everything not passed and not explicitly shared is scoped so it is not automatically accessible throughout the routine. This should ensure that the decision to share styles is a conscious one. In the future we will try to reduce the number of unique definitions and share most of it. This PR is a stepping stone on this path. This also puts the effort into separating redefinitions of default theme items vs custom types introduced only by the editor. In a few cases where editor-specific definitions need to reference default definitions we simply fetch them from the theme. It's not ideal and hides the dependency a bit, but hopefully these cases will be abstracted properly in due time.
This commit is contained in:
parent
95b27fe8c7
commit
635b8a1474
|
@ -334,7 +334,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
|||
}
|
||||
}
|
||||
|
||||
Color dc = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor));
|
||||
Color dc = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));
|
||||
|
||||
Ref<Texture2D> remove = get_editor_theme_icon(SNAME("Remove"));
|
||||
float remove_hpos = limit - hsep - remove->get_width();
|
||||
|
|
|
@ -1921,7 +1921,7 @@ void AnimationTrackEdit::_notification(int p_what) {
|
|||
Color linecolor = color;
|
||||
linecolor.a = 0.2;
|
||||
|
||||
Color dc = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor));
|
||||
Color dc = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));
|
||||
|
||||
// NAMES AND ICONS //
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String
|
|||
|
||||
r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type));
|
||||
if (!instantiable) {
|
||||
r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
r_item->set_custom_color(0, search_options->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
}
|
||||
|
||||
HashMap<String, DocData::ClassDoc>::Iterator class_doc = EditorHelp::get_doc_data()->class_list.find(p_type);
|
||||
|
|
|
@ -601,7 +601,7 @@ void EditorBuildProfileManager::_fill_classes_from(TreeItem *p_parent, const Str
|
|||
|
||||
bool disabled = edited->is_class_disabled(p_class);
|
||||
if (disabled) {
|
||||
class_item->set_custom_color(0, class_list->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
class_item->set_custom_color(0, class_list->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
}
|
||||
|
||||
class_item->set_text(0, text);
|
||||
|
|
|
@ -503,7 +503,7 @@ void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const S
|
|||
bool disabled_editor = edited->is_class_editor_disabled(p_class);
|
||||
bool disabled_properties = edited->has_class_properties_disabled(p_class);
|
||||
if (disabled) {
|
||||
class_item->set_custom_color(0, class_list->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
class_item->set_custom_color(0, class_list->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
} else if (disabled_editor && disabled_properties) {
|
||||
text += " " + TTR("(Editor Disabled, Properties Disabled)");
|
||||
} else if (disabled_properties) {
|
||||
|
|
|
@ -698,5 +698,5 @@ EditorHelpSearch::Runner::Runner(Control *p_icon_service, Tree *p_results_tree,
|
|||
results_tree(p_results_tree),
|
||||
term((p_search_flags & SEARCH_CASE_SENSITIVE) == 0 ? p_term.strip_edges().to_lower() : p_term.strip_edges()),
|
||||
search_flags(p_search_flags),
|
||||
disabled_color(ui_service->get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor))) {
|
||||
disabled_color(ui_service->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))) {
|
||||
}
|
||||
|
|
|
@ -1357,7 +1357,7 @@ void EditorInspectorSection::_notification(int p_what) {
|
|||
|
||||
Ref<Font> light_font = get_theme_font(SNAME("main"), EditorStringName(EditorFonts));
|
||||
int light_font_size = get_theme_font_size(SNAME("main_size"), EditorStringName(EditorFonts));
|
||||
Color light_font_color = get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor));
|
||||
Color light_font_color = get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor));
|
||||
|
||||
// Can we fit the long version of the revertable count text?
|
||||
num_revertable_str = vformat(TTRN("(%d change)", "(%d changes)", revertable_properties.size()), revertable_properties.size());
|
||||
|
|
|
@ -5978,6 +5978,7 @@ void EditorNode::_bottom_panel_raise_toggled(bool p_pressed) {
|
|||
void EditorNode::_update_renderer_color() {
|
||||
String rendering_method = renderer->get_selected_metadata();
|
||||
|
||||
// TODO: Use theme colors instead of hardcoded values.
|
||||
if (rendering_method == "forward_plus") {
|
||||
renderer->add_theme_color_override("font_color", Color::hex(0x5d8c3fff));
|
||||
}
|
||||
|
|
|
@ -992,12 +992,12 @@ void EditorPropertyLayersGrid::_notification(int p_what) {
|
|||
const int bsize = (grid_size.height * 80 / 100) / 2;
|
||||
const int h = bsize * 2 + 1;
|
||||
|
||||
Color color = get_theme_color(read_only ? SNAME("disabled_highlight_color") : SNAME("highlight_color"), EditorStringName(Editor));
|
||||
Color color = get_theme_color(read_only ? SNAME("highlight_disabled_color") : SNAME("highlight_color"), EditorStringName(Editor));
|
||||
|
||||
Color text_color = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_color"), EditorStringName(Editor));
|
||||
Color text_color = get_theme_color(read_only ? SNAME("font_disabled_color") : SNAME("font_color"), EditorStringName(Editor));
|
||||
text_color.a *= 0.5;
|
||||
|
||||
Color text_color_on = get_theme_color(read_only ? SNAME("disabled_font_color") : SNAME("font_hover_color"), EditorStringName(Editor));
|
||||
Color text_color_on = get_theme_color(read_only ? SNAME("font_disabled_color") : SNAME("font_hover_color"), EditorStringName(Editor));
|
||||
text_color_on.a *= 0.7;
|
||||
|
||||
const int vofs = (grid_size.height - h) / 2;
|
||||
|
@ -2073,7 +2073,7 @@ void EditorPropertyQuaternion::_notification(int p_what) {
|
|||
euler[i]->add_theme_color_override("label_color", colors[i]);
|
||||
}
|
||||
edit_button->set_icon(get_editor_theme_icon(SNAME("Edit")));
|
||||
euler_label->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("property_color"), EditorStringName(Editor)));
|
||||
euler_label->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("property_color"), SNAME("EditorProperty")));
|
||||
warning->set_icon(get_editor_theme_icon(SNAME("NodeWarning")));
|
||||
warning->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
|
||||
} break;
|
||||
|
|
|
@ -758,7 +758,7 @@ void ExportTemplateManager::_notification(int p_what) {
|
|||
case NOTIFICATION_THEME_CHANGED: {
|
||||
current_value->add_theme_font_override("font", get_theme_font(SNAME("main"), EditorStringName(EditorFonts)));
|
||||
current_missing_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
|
||||
current_installed_label->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
current_installed_label->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
|
||||
mirror_options_button->set_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
|
||||
} break;
|
||||
|
|
|
@ -824,7 +824,7 @@ void ProjectExportDialog::_setup_item_for_file_mode(TreeItem *p_item, EditorExpo
|
|||
p_item->set_cell_mode(1, TreeItem::CELL_MODE_STRING);
|
||||
p_item->set_editable(1, false);
|
||||
p_item->set_selectable(1, false);
|
||||
p_item->set_custom_color(1, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
p_item->set_custom_color(1, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
} else {
|
||||
p_item->set_checked(0, true);
|
||||
p_item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM);
|
||||
|
|
|
@ -235,7 +235,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||
item->add_button(0, get_editor_theme_icon(SNAME("Script")), BUTTON_SCRIPT);
|
||||
} else {
|
||||
//has no script (or script is a custom type)
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
item->set_selectable(0, false);
|
||||
|
||||
if (!scr.is_null()) { // make sure to mark the script if a custom type
|
||||
|
@ -267,7 +267,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||
item->set_selectable(0, marked_selectable);
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("accent_color"), EditorStringName(Editor)));
|
||||
} else if (!p_node->can_process()) {
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
} else if (!marked_selectable && !marked_children_selectable) {
|
||||
Node *node = p_node;
|
||||
while (node) {
|
||||
|
@ -492,7 +492,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
|
|||
}
|
||||
|
||||
if (!valid) {
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
_set_item_custom_color(item, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
item->set_selectable(0, false);
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +718,7 @@ bool SceneTreeEditor::_update_filter(TreeItem *p_parent, bool p_scroll_to_select
|
|||
}
|
||||
p_parent->set_selectable(0, true);
|
||||
} else if (keep_for_children) {
|
||||
p_parent->set_custom_color(0, get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
p_parent->set_custom_color(0, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
p_parent->set_selectable(0, false);
|
||||
p_parent->deselect(0);
|
||||
}
|
||||
|
|
|
@ -417,7 +417,6 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse
|
|||
|
||||
void EditorAssetLibraryItemDownload::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("AssetLib")));
|
||||
status->add_theme_color_override("font_color", get_theme_color(SNAME("status_color"), SNAME("AssetLib")));
|
||||
|
|
|
@ -852,10 +852,9 @@ bool ThemeItemImportTree::has_selected_items() const {
|
|||
|
||||
void ThemeItemImportTree::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
select_icons_warning_icon->set_texture(get_editor_theme_icon(SNAME("StatusWarning")));
|
||||
select_icons_warning->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
select_icons_warning->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
|
||||
import_items_filter->set_right_icon(get_editor_theme_icon(SNAME("Search")));
|
||||
|
||||
|
@ -2470,7 +2469,7 @@ HBoxContainer *ThemeTypeEditor::_create_property_control(Theme::DataType p_data_
|
|||
item_rename_cancel_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_rename_canceled).bind(p_data_type, p_item_name, item_name_container));
|
||||
item_rename_cancel_button->hide();
|
||||
} else {
|
||||
item_name->add_theme_color_override("font_color", get_theme_color(SNAME("disabled_font_color"), EditorStringName(Editor)));
|
||||
item_name->add_theme_color_override("font_color", get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
|
||||
|
||||
Button *item_override_button = memnew(Button);
|
||||
item_override_button->set_icon(get_editor_theme_icon(SNAME("Add")));
|
||||
|
|
|
@ -735,7 +735,7 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() {
|
|||
tile_data_editors["probability"] = tile_data_probability_editor;
|
||||
}
|
||||
|
||||
Color disabled_color = get_theme_color("disabled_font_color", EditorStringName(Editor));
|
||||
Color disabled_color = get_theme_color("font_disabled_color", EditorStringName(Editor));
|
||||
|
||||
// --- Physics ---
|
||||
ADD_TILE_DATA_EDITOR_GROUP(TTR("Physics"));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -31,11 +31,111 @@
|
|||
#ifndef EDITOR_THEME_MANAGER_H
|
||||
#define EDITOR_THEME_MANAGER_H
|
||||
|
||||
#include "scene/resources/style_box_flat.h"
|
||||
#include "scene/resources/theme.h"
|
||||
|
||||
class EditorThemeManager {
|
||||
struct ThemeConfiguration {
|
||||
// Basic properties.
|
||||
|
||||
String preset;
|
||||
bool dark_theme = false;
|
||||
|
||||
Color base_color;
|
||||
Color accent_color;
|
||||
float contrast = 1.0;
|
||||
float icon_saturation = 1.0;
|
||||
|
||||
// Extra properties.
|
||||
|
||||
float extra_spacing = 0.0;
|
||||
int border_width = 0;
|
||||
int corner_radius = 3;
|
||||
|
||||
bool draw_extra_borders = false;
|
||||
float relationship_line_opacity = 1.0;
|
||||
int thumb_size = 16;
|
||||
int class_icon_size = 16;
|
||||
bool increase_scrollbar_touch_area = false;
|
||||
float gizmo_handle_scale = 1.0;
|
||||
int color_picker_button_height = 28;
|
||||
|
||||
float default_contrast = 1.0;
|
||||
|
||||
// Generated properties.
|
||||
|
||||
int base_margin = 4;
|
||||
int increased_margin = 4;
|
||||
|
||||
int popup_margin = 12;
|
||||
int window_border_margin = 8;
|
||||
int top_bar_separation = 8;
|
||||
int forced_even_separation = 0;
|
||||
|
||||
Color mono_color;
|
||||
Color dark_color_1;
|
||||
Color dark_color_2;
|
||||
Color dark_color_3;
|
||||
Color contrast_color_1;
|
||||
Color contrast_color_2;
|
||||
Color highlight_color;
|
||||
Color highlight_disabled_color;
|
||||
Color success_color;
|
||||
Color warning_color;
|
||||
Color error_color;
|
||||
Color extra_border_color_1;
|
||||
Color extra_border_color_2;
|
||||
|
||||
Color font_color;
|
||||
Color font_focus_color;
|
||||
Color font_hover_color;
|
||||
Color font_pressed_color;
|
||||
Color font_hover_pressed_color;
|
||||
Color font_disabled_color;
|
||||
Color font_readonly_color;
|
||||
Color font_placeholder_color;
|
||||
Color font_outline_color;
|
||||
|
||||
Color icon_normal_color;
|
||||
Color icon_focus_color;
|
||||
Color icon_hover_color;
|
||||
Color icon_pressed_color;
|
||||
Color icon_disabled_color;
|
||||
|
||||
Color shadow_color;
|
||||
Color selection_color;
|
||||
Color disabled_border_color;
|
||||
Color disabled_bg_color;
|
||||
Color separator_color;
|
||||
|
||||
Ref<StyleBoxFlat> base_style;
|
||||
Ref<StyleBoxEmpty> base_empty_style;
|
||||
|
||||
Ref<StyleBoxFlat> button_style;
|
||||
Ref<StyleBoxFlat> button_style_disabled;
|
||||
Ref<StyleBoxFlat> button_style_focus;
|
||||
Ref<StyleBoxFlat> button_style_pressed;
|
||||
Ref<StyleBoxFlat> button_style_hover;
|
||||
|
||||
Ref<StyleBoxFlat> popup_style;
|
||||
Ref<StyleBoxFlat> window_style;
|
||||
Ref<StyleBoxFlat> dialog_style;
|
||||
Ref<StyleBoxFlat> panel_container_style;
|
||||
Ref<StyleBoxFlat> content_panel_style;
|
||||
Ref<StyleBoxFlat> tree_panel_style;
|
||||
|
||||
Vector2 widget_margin;
|
||||
};
|
||||
|
||||
static Ref<Theme> _create_base_theme(const Ref<Theme> &p_old_theme = nullptr);
|
||||
static ThemeConfiguration _create_theme_config(const Ref<Theme> &p_theme);
|
||||
|
||||
static void _create_shared_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config);
|
||||
static void _populate_standard_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config);
|
||||
static void _populate_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config);
|
||||
|
||||
static void _generate_text_editor_defaults(ThemeConfiguration &p_config);
|
||||
static void _populate_text_editor_styles(const Ref<Theme> &p_theme, ThemeConfiguration &p_config);
|
||||
|
||||
public:
|
||||
static Ref<Theme> generate_theme(const Ref<Theme> &p_old_theme = nullptr);
|
||||
|
|
Loading…
Reference in New Issue