From 6bb58ca5ae4d99ffc956544aace7e0a25cb2fc73 Mon Sep 17 00:00:00 2001 From: passivestar <60579014+passivestar@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:08:00 +0400 Subject: [PATCH] Make inspector spacing more themable --- editor/editor_inspector.cpp | 41 ++++++++++++++++---------- editor/themes/editor_theme_manager.cpp | 5 ++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 55704a38b8f0..6c26231a4bb6 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1239,9 +1239,11 @@ void EditorInspectorCategory::_notification(int p_what) { int ofs = (get_size().width - w) / 2; + float v_margin_offset = sb->get_content_margin(SIDE_TOP) - sb->get_content_margin(SIDE_BOTTOM); + if (icon.is_valid()) { Size2 rect_size = Size2(icon_size, icon_size); - Point2 rect_pos = Point2(ofs, (get_size().height - icon_size) / 2).floor(); + Point2 rect_pos = Point2(ofs, (get_size().height - icon_size) / 2 + v_margin_offset).round(); if (is_layout_rtl()) { rect_pos.x = get_size().width - rect_pos.x - icon_size; } @@ -1255,7 +1257,9 @@ void EditorInspectorCategory::_notification(int p_what) { if (is_layout_rtl()) { ofs = get_size().width - ofs - w; } - draw_string(font, Point2(ofs, font->get_ascent(font_size) + (get_size().height - font->get_height(font_size)) / 2).floor(), label, HORIZONTAL_ALIGNMENT_LEFT, w, font_size, color); + float text_pos_y = font->get_ascent(font_size) + (get_size().height - font->get_height(font_size)) / 2 + v_margin_offset; + Point2 text_pos = Point2(ofs, text_pos_y).round(); + draw_string(font, text_pos, label, HORIZONTAL_ALIGNMENT_LEFT, w, font_size, color); } break; } } @@ -1283,6 +1287,9 @@ Size2 EditorInspectorCategory::get_minimum_size() const { } ms.height += get_theme_constant(SNAME("v_separation"), SNAME("Tree")); + const Ref &bg_style = get_theme_stylebox(SNAME("bg")); + ms.height += bg_style->get_content_margin(SIDE_TOP) + bg_style->get_content_margin(SIDE_BOTTOM); + return ms; } @@ -1425,10 +1432,11 @@ void EditorInspectorSection::_notification(int p_what) { // Draw header title, folding arrow and count of revertable properties. { - int separation = Math::round(2 * EDSCALE); + int outer_margin = Math::round(2 * EDSCALE); + int separation = get_theme_constant(SNAME("h_separation"), SNAME("EditorInspectorSection")); - int margin_start = section_indent + separation; - int margin_end = separation; + int margin_start = section_indent + outer_margin; + int margin_end = outer_margin; // - Arrow. Ref arrow = _get_arrow(); @@ -1441,7 +1449,7 @@ void EditorInspectorSection::_notification(int p_what) { } arrow_position.y = (header_height - arrow->get_height()) / 2; draw_texture(arrow, arrow_position); - margin_start += arrow->get_width(); + margin_start += arrow->get_width() + separation; } int available = get_size().width - (margin_start + margin_end); @@ -1466,27 +1474,25 @@ void EditorInspectorSection::_notification(int p_what) { // 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()); num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x; - if (label_width + separation + num_revertable_width > available) { + if (label_width + outer_margin + num_revertable_width > available) { // We'll have to use the short version. num_revertable_str = vformat("(%d)", revertable_properties.size()); num_revertable_width = light_font->get_string_size(num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, TextServer::JUSTIFICATION_NONE).x; } - Point2 text_offset = Point2( - margin_end, - light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2); + float text_offset_y = light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2; + Point2 text_offset = Point2(margin_end, text_offset_y).round(); if (!rtl) { text_offset.x = get_size().width - (text_offset.x + num_revertable_width); } draw_string(light_font, text_offset, num_revertable_str, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, light_font_size, light_font_color, TextServer::JUSTIFICATION_NONE); - margin_end += num_revertable_width + separation; - available -= num_revertable_width + separation; + margin_end += num_revertable_width + outer_margin; + available -= num_revertable_width + outer_margin; } // - Label. - Point2 text_offset = Point2( - margin_start, - font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2); + float text_offset_y = font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2; + Point2 text_offset = Point2(margin_start, text_offset_y).round(); if (rtl) { text_offset.x = margin_end; } @@ -4077,6 +4083,10 @@ void EditorInspector::_node_removed(Node *p_node) { void EditorInspector::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_THEME_CHANGED: { + main_vbox->add_theme_constant_override("separation", get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"))); + } break; + case NOTIFICATION_READY: { EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed)); set_process(is_visible_in_tree()); @@ -4340,7 +4350,6 @@ EditorInspector::EditorInspector() { object = nullptr; main_vbox = memnew(VBoxContainer); main_vbox->set_h_size_flags(SIZE_EXPAND_FILL); - main_vbox->add_theme_constant_override("separation", 0); add_child(main_vbox); set_horizontal_scroll_mode(SCROLL_MODE_DISABLED); set_follow_focus(true); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index b6697b6d2cd1..86a184903c55 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -2087,6 +2087,9 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme // Editor inspector. { + // Vertical separation between inspector categories and sections. + p_theme->set_constant("v_separation", "EditorInspector", 0); + // EditorProperty. Ref style_property_bg = p_config.base_style->duplicate(); @@ -2128,6 +2131,7 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme Ref inspector_indent_style = make_flat_stylebox(inspector_indent_color, 2.0 * EDSCALE, 0, 2.0 * EDSCALE, 0); p_theme->set_stylebox("indent_box", "EditorInspectorSection", inspector_indent_style); p_theme->set_constant("indent_size", "EditorInspectorSection", 6.0 * EDSCALE); + p_theme->set_constant("h_separation", "EditorInspectorSection", 2.0 * EDSCALE); Color prop_category_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.12); Color prop_section_color = p_config.dark_color_1.lerp(p_config.mono_color, 0.09); @@ -2145,6 +2149,7 @@ void EditorThemeManager::_populate_editor_styles(const Ref &p_theme Ref category_bg = p_config.base_style->duplicate(); category_bg->set_bg_color(prop_category_color); category_bg->set_border_color(prop_category_color); + category_bg->set_content_margin_all(0); p_theme->set_stylebox("bg", "EditorInspectorCategory", category_bg); p_theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE);