Merge pull request #49148 from reduz/use-bold-fonts

Use bold fonts in editor
This commit is contained in:
Rémi Verschelde 2021-06-02 18:40:58 +02:00 committed by GitHub
commit 4e52b84011
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 102 additions and 25 deletions

View File

@ -175,6 +175,14 @@
Returns the custom color of column [code]column[/code].
</description>
</method>
<method name="get_custom_font" qualifiers="const">
<return type="Font">
</return>
<argument index="0" name="column" type="int">
</argument>
<description>
</description>
</method>
<method name="get_expand_right" qualifiers="const">
<return type="bool">
</return>
@ -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].
</description>
</method>
<method name="set_custom_font">
<return type="void">
</return>
<argument index="0" name="column" type="int">
</argument>
<argument index="1" name="font" type="Font">
</argument>
<description>
</description>
</method>
<method name="set_editable">
<return type="void">
</return>

View File

@ -313,9 +313,14 @@ void editor_register_fonts(Ref<Theme> 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);

View File

@ -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> font = get_theme_font("font", "Tree");
int font_size = get_theme_font_size("font_size", "Tree");
Ref<StyleBox> sb = get_theme_stylebox("prop_category_style", "Editor");
draw_style_box(sb, Rect2(Vector2(), get_size()));
Ref<Font> 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> font = get_theme_font("font", "Tree");
int font_size = get_theme_font_size("font_size", "Tree");
Ref<Font> font = get_theme_font("bold", "EditorFonts");
int font_size = get_theme_font_size("bold_size", "EditorFonts");
Ref<Texture2D> 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> font = get_theme_font("font", "Tree");
int font_size = get_theme_font_size("font_size", "Tree");
Ref<Font> 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)) {

View File

@ -208,7 +208,7 @@ class EditorInspectorCategory : public Control {
friend class EditorInspector;
Ref<Texture2D> icon;
String label;
Color bg_color;
mutable String tooltip_text;
protected:

View File

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

View File

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

View File

@ -464,7 +464,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> 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<Theme> create_editor_theme(const Ref<Theme> 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<StyleBoxEmpty>(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<StyleBoxFlat> style_tree_bg = style_default->duplicate();
@ -884,6 +887,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("prop_subsection", "Editor", prop_subsection_color);
theme->set_color("drop_position_color", "Tree", accent_color);
Ref<StyleBoxFlat> 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<StyleBoxFlat> style_itemlist_bg = style_default->duplicate();
style_itemlist_bg->set_bg_color(dark_color_1);
@ -941,7 +950,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> 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);

View File

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

View File

@ -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<Font> &p_font) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_font = p_font;
}
Ref<Font> TreeItem::get_custom_font(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Font>());
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> 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;
}

View File

@ -112,6 +112,8 @@ private:
Vector<Button> buttons;
Ref<Font> custom_font;
Cell() {
text_buf.instance();
}
@ -291,6 +293,9 @@ public:
Color get_custom_color(int p_column) const;
void clear_custom_color(int p_column);
void set_custom_font(int p_column, const Ref<Font> &p_font);
Ref<Font> get_custom_font(int p_column) const;
void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
void clear_custom_bg_color(int p_column);
Color get_custom_bg_color(int p_column) const;