From d95bc3fa6705af7976e58e21d548c790b8ac4ce7 Mon Sep 17 00:00:00 2001 From: reduz Date: Thu, 27 May 2021 12:32:30 -0300 Subject: [PATCH] Use bold fonts in editor * Labels are now bold * Categories in trees are bold * Main editor buttons are bold * Fixed section folding arrows in inspector --- doc/classes/TreeItem.xml | 18 ++++++++++++ editor/editor_fonts.cpp | 7 ++++- editor/editor_inspector.cpp | 42 +++++++++++++++++---------- editor/editor_inspector.h | 2 +- editor/editor_node.cpp | 8 +++++ editor/editor_sectioned_inspector.cpp | 3 +- editor/editor_themes.cpp | 17 ++++++++--- editor/filesystem_dock.cpp | 1 + scene/gui/tree.cpp | 24 +++++++++++++-- scene/gui/tree.h | 5 ++++ 10 files changed, 102 insertions(+), 25 deletions(-) diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index 7d375805044..0256d83fead 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -175,6 +175,14 @@ Returns the custom color of column [code]column[/code]. + + + + + + + + @@ -579,6 +587,16 @@ The [code]callback[/code] should accept two arguments: the [TreeItem] that is drawn and its position and size as a [Rect2]. + + + + + + + + + + diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 96869ae6fd7..8a5142459c8 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -313,9 +313,14 @@ void editor_register_fonts(Ref p_theme) { p_theme->set_font("bold", "EditorFonts", df_bold); // Title font - p_theme->set_font_size("title_size", "EditorFonts", default_font_size + 2 * EDSCALE); + p_theme->set_font_size("title_size", "EditorFonts", default_font_size + 1 * EDSCALE); p_theme->set_font("title", "EditorFonts", df_bold); + p_theme->set_font_size("main_button_font_size", "EditorFonts", default_font_size + 1 * EDSCALE); + p_theme->set_font("main_button_font", "EditorFonts", df_bold); + + p_theme->set_font("font", "Label", df_bold); + // Documentation fonts MAKE_SOURCE_FONT(df_code); p_theme->set_font_size("doc_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index f8690314460..20abe72750a 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1097,9 +1097,12 @@ void EditorInspectorPlugin::_bind_methods() { void EditorInspectorCategory::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - draw_rect(Rect2(Vector2(), get_size()), bg_color); - Ref font = get_theme_font("font", "Tree"); - int font_size = get_theme_font_size("font_size", "Tree"); + Ref sb = get_theme_stylebox("prop_category_style", "Editor"); + + draw_style_box(sb, Rect2(Vector2(), get_size())); + + Ref font = get_theme_font("bold", "EditorFonts"); + int font_size = get_theme_font_size("bold_size", "EditorFonts"); int hs = get_theme_constant("hseparation", "Tree"); @@ -1181,8 +1184,9 @@ void EditorInspectorSection::_test_unfold() { void EditorInspectorSection::_notification(int p_what) { if (p_what == NOTIFICATION_SORT_CHILDREN) { - Ref font = get_theme_font("font", "Tree"); - int font_size = get_theme_font_size("font_size", "Tree"); + Ref font = get_theme_font("bold", "EditorFonts"); + int font_size = get_theme_font_size("bold_size", "EditorFonts"); + Ref arrow; if (foldable) { @@ -1233,15 +1237,19 @@ void EditorInspectorSection::_notification(int p_what) { bool rtl = is_layout_rtl(); if (foldable) { - if (rtl) { - arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree"); + if (object->editor_is_section_unfolded(section)) { + arrow = get_theme_icon("arrow", "Tree"); } else { - arrow = get_theme_icon("arrow_collapsed", "Tree"); + if (is_layout_rtl()) { + arrow = get_theme_icon("arrow_collapsed_mirrored", "Tree"); + } else { + arrow = get_theme_icon("arrow_collapsed", "Tree"); + } } } - Ref font = get_theme_font("font", "Tree"); - int font_size = get_theme_font_size("font_size", "Tree"); + Ref font = get_theme_font("bold", "EditorFonts"); + int font_size = get_theme_font_size("bold_size", "EditorFonts"); int h = font->get_height(font_size); if (arrow.is_valid()) { @@ -1249,12 +1257,15 @@ void EditorInspectorSection::_notification(int p_what) { } h += get_theme_constant("vseparation", "Tree"); - draw_rect(Rect2(Vector2(), Vector2(get_size().width, h)), bg_color); + Color c = bg_color; + c.a *= 0.4; + draw_rect(Rect2(Vector2(), Vector2(get_size().width, h)), c); - const int arrow_margin = 3; - Color color = get_theme_color("font_color", "Tree"); - float text_width = get_size().width - Math::round((16 + arrow_margin) * EDSCALE); - draw_string(font, Point2(rtl ? 0 : Math::round((16 + arrow_margin) * EDSCALE), font->get_ascent(font_size) + (h - font->get_height(font_size)) / 2).floor(), label, rtl ? HALIGN_RIGHT : HALIGN_LEFT, text_width, font_size, color); + const int arrow_margin = 2; + const int arrow_width = arrow.is_valid() ? arrow->get_width() : 0; + Color color = get_theme_color("font_color"); + float text_width = get_size().width - Math::round(arrow_width + arrow_margin * EDSCALE); + draw_string(font, Point2(rtl ? 0 : Math::round(arrow_width + arrow_margin * EDSCALE), font->get_ascent(font_size) + (h - font->get_height(font_size)) / 2).floor(), label, rtl ? HALIGN_RIGHT : HALIGN_LEFT, text_width, font_size, color); if (arrow.is_valid()) { if (rtl) { @@ -1737,7 +1748,6 @@ void EditorInspector::update_tree() { } category->label = type; - category->bg_color = get_theme_color("prop_category", "Editor"); if (use_doc_hints) { StringName type2 = p.name; if (!class_descr_cache.has(type2)) { diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 18250780be4..348dea7086a 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -208,7 +208,7 @@ class EditorInspectorCategory : public Control { friend class EditorInspector; Ref icon; String label; - Color bg_color; + mutable String tooltip_text; protected: diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index aa632b90ad3..9c77f9d25c0 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -707,6 +707,11 @@ void EditorNode::_notification(int p_what) { p->set_item_icon(p->get_item_index(HELP_ABOUT), gui_base->get_theme_icon("Godot", "EditorIcons")); p->set_item_icon(p->get_item_index(HELP_SUPPORT_GODOT_DEVELOPMENT), gui_base->get_theme_icon("Heart", "EditorIcons")); + for (int i = 0; i < main_editor_buttons.size(); i++) { + main_editor_buttons.write[i]->add_theme_font_override("font", gui_base->get_theme_font("main_button_font", "EditorFonts")); + main_editor_buttons.write[i]->add_theme_font_size_override("font_size", gui_base->get_theme_font_size("main_button_font_size", "EditorFonts")); + } + _update_update_spinner(); } break; @@ -3059,6 +3064,9 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed tb->set_icon(singleton->gui_base->get_theme_icon(p_editor->get_name(), "EditorIcons")); } + tb->add_theme_font_override("font", singleton->gui_base->get_theme_font("main_button_font", "EditorFonts")); + tb->add_theme_font_size_override("font_size", singleton->gui_base->get_theme_font_size("main_button_font_size", "EditorFonts")); + tb->set_name(p_editor->get_name()); singleton->main_editor_buttons.push_back(tb); singleton->main_editor_button_vb->add_child(tb); diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp index 7532f1c7961..6bfb17f9c2a 100644 --- a/editor/editor_sectioned_inspector.cpp +++ b/editor/editor_sectioned_inspector.cpp @@ -250,7 +250,8 @@ void SectionedInspector::update_category_list() { for (int i = 0; i < sc; i++) { TreeItem *parent = section_map[metasection]; - parent->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor")); + //parent->set_custom_bg_color(0, get_theme_color("prop_subsection", "Editor")); + parent->set_custom_font(0, get_theme_font("bold", "EditorFonts")); if (i > 0) { metasection += "/" + sectionarr[i]; diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 7971dfc313b..5efb7cdbf29 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -464,7 +464,7 @@ Ref create_editor_theme(const Ref p_theme) { // Ensure borders are visible when using an editor scale below 100%. const int border_width = CLAMP(border_size, 0, 2) * MAX(1, EDSCALE); - const int corner_width = CLAMP(corner_radius, 0, 6) * EDSCALE; + const int corner_width = CLAMP(corner_radius, 0, 6); const int default_margin_size = 4; const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 2); @@ -785,14 +785,17 @@ Ref create_editor_theme(const Ref p_theme) { style_property_bg->set_bg_color(highlight_color); style_property_bg->set_border_width_all(0); - theme->set_constant("font_offset", "EditorProperty", 1 * EDSCALE); + theme->set_constant("font_offset", "EditorProperty", 8 * EDSCALE); theme->set_stylebox("bg_selected", "EditorProperty", style_property_bg); theme->set_stylebox("bg", "EditorProperty", Ref(memnew(StyleBoxEmpty))); theme->set_constant("vseparation", "EditorProperty", (extra_spacing + default_margin_size) * EDSCALE); theme->set_color("error_color", "EditorProperty", error_color); theme->set_color("property_color", "EditorProperty", property_color); - theme->set_constant("inspector_margin", "Editor", 8 * EDSCALE); + Color inspector_section_color = font_color.lerp(Color(0.5, 0.5, 0.5), 0.35); + theme->set_color("font_color", "EditorInspectorSection", inspector_section_color); + + theme->set_constant("inspector_margin", "Editor", 12 * EDSCALE); // Tree & ItemList background Ref style_tree_bg = style_default->duplicate(); @@ -884,6 +887,12 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_color("prop_subsection", "Editor", prop_subsection_color); theme->set_color("drop_position_color", "Tree", accent_color); + Ref category_bg = style_default->duplicate(); + // Make Trees easier to distinguish from other controls by using a darker background color. + category_bg->set_bg_color(prop_category_color); + category_bg->set_border_color(prop_category_color); + theme->set_stylebox("prop_category_style", "Editor", category_bg); + // ItemList Ref style_itemlist_bg = style_default->duplicate(); style_itemlist_bg->set_bg_color(dark_color_1); @@ -941,7 +950,7 @@ Ref create_editor_theme(const Ref p_theme) { style_content_panel->set_border_color(dark_color_3); style_content_panel->set_border_width_all(border_width); // compensate the border - style_content_panel->set_default_margin(SIDE_TOP, margin_size_extra * EDSCALE); + style_content_panel->set_default_margin(SIDE_TOP, (2 + margin_size_extra) * EDSCALE); style_content_panel->set_default_margin(SIDE_RIGHT, margin_size_extra * EDSCALE); style_content_panel->set_default_margin(SIDE_BOTTOM, margin_size_extra * EDSCALE); style_content_panel->set_default_margin(SIDE_LEFT, margin_size_extra * EDSCALE); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index a21a33a44a3..ce98f699aef 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2834,6 +2834,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { button_toggle_display_mode->connect("toggled", callable_mp(this, &FileSystemDock::_toggle_split_mode)); button_toggle_display_mode->set_focus_mode(FOCUS_NONE); button_toggle_display_mode->set_tooltip(TTR("Toggle Split Mode")); + button_toggle_display_mode->set_flat(true); toolbar_hbc->add_child(button_toggle_display_mode); toolbar2_hbc = memnew(HBoxContainer); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 50e7ba97bcb..f66cc13af5e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -870,6 +870,15 @@ void TreeItem::clear_custom_color(int p_column) { _changed_notify(p_column); } +void TreeItem::set_custom_font(int p_column, const Ref &p_font) { + ERR_FAIL_INDEX(p_column, cells.size()); + cells.write[p_column].custom_font = p_font; +} +Ref TreeItem::get_custom_font(int p_column) const { + ERR_FAIL_INDEX_V(p_column, cells.size(), Ref()); + return cells[p_column].custom_font; +} + void TreeItem::set_tooltip(int p_column, const String &p_tooltip) { ERR_FAIL_INDEX(p_column, cells.size()); cells.write[p_column].tooltip = p_tooltip; @@ -1050,8 +1059,11 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("is_editable", "column"), &TreeItem::is_editable); ClassDB::bind_method(D_METHOD("set_custom_color", "column", "color"), &TreeItem::set_custom_color); - ClassDB::bind_method(D_METHOD("clear_custom_color", "column"), &TreeItem::clear_custom_color); ClassDB::bind_method(D_METHOD("get_custom_color", "column"), &TreeItem::get_custom_color); + ClassDB::bind_method(D_METHOD("clear_custom_color", "column"), &TreeItem::clear_custom_color); + + ClassDB::bind_method(D_METHOD("set_custom_font", "column", "font"), &TreeItem::set_custom_font); + ClassDB::bind_method(D_METHOD("get_custom_font", "column"), &TreeItem::get_custom_font); ClassDB::bind_method(D_METHOD("set_custom_bg_color", "column", "color", "just_outline"), &TreeItem::set_custom_bg_color, DEFVAL(false)); ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color); @@ -1372,6 +1384,7 @@ void Tree::update_column(int p_col) { } else { columns.write[p_col].text_buf->set_direction((TextServer::Direction)columns[p_col].text_direction); } + columns.write[p_col].text_buf->add_string(columns[p_col].title, cache.font, cache.font_size, columns[p_col].opentype_features, (columns[p_col].language != "") ? columns[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); } @@ -1416,7 +1429,14 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) { } else { p_item->cells.write[p_col].text_buf->set_direction((TextServer::Direction)p_item->cells[p_col].text_direction); } - p_item->cells.write[p_col].text_buf->add_string(valtext, cache.font, cache.font_size, p_item->cells[p_col].opentype_features, (p_item->cells[p_col].language != "") ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); + + Ref font; + if (p_item->cells[p_col].custom_font.is_valid()) { + font = p_item->cells[p_col].custom_font; + } else { + font = cache.font; + } + p_item->cells.write[p_col].text_buf->add_string(valtext, font, cache.font_size, p_item->cells[p_col].opentype_features, (p_item->cells[p_col].language != "") ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(p_item->cells[p_col].text_buf->get_rid(), structured_text_parser(p_item->cells[p_col].st_parser, p_item->cells[p_col].st_args, valtext)); p_item->cells.write[p_col].dirty = false; } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index c0948f1b80b..5176d014975 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -112,6 +112,8 @@ private: Vector