Merge pull request #93435 from passivestar/themable-inspector

Make inspector spacing more themable
This commit is contained in:
Rémi Verschelde 2024-06-24 11:14:14 +02:00
commit d4d123c8a1
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 30 additions and 16 deletions

View file

@ -1239,9 +1239,11 @@ void EditorInspectorCategory::_notification(int p_what) {
int ofs = (get_size().width - w) / 2; 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()) { if (icon.is_valid()) {
Size2 rect_size = Size2(icon_size, icon_size); 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()) { if (is_layout_rtl()) {
rect_pos.x = get_size().width - rect_pos.x - icon_size; 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()) { if (is_layout_rtl()) {
ofs = get_size().width - ofs - w; 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; } break;
} }
} }
@ -1283,6 +1287,9 @@ Size2 EditorInspectorCategory::get_minimum_size() const {
} }
ms.height += get_theme_constant(SNAME("v_separation"), SNAME("Tree")); ms.height += get_theme_constant(SNAME("v_separation"), SNAME("Tree"));
const Ref<StyleBox> &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; return ms;
} }
@ -1425,10 +1432,11 @@ void EditorInspectorSection::_notification(int p_what) {
// Draw header title, folding arrow and count of revertable properties. // 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_start = section_indent + outer_margin;
int margin_end = separation; int margin_end = outer_margin;
// - Arrow. // - Arrow.
Ref<Texture2D> arrow = _get_arrow(); Ref<Texture2D> arrow = _get_arrow();
@ -1441,7 +1449,7 @@ void EditorInspectorSection::_notification(int p_what) {
} }
arrow_position.y = (header_height - arrow->get_height()) / 2; arrow_position.y = (header_height - arrow->get_height()) / 2;
draw_texture(arrow, arrow_position); 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); 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? // 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_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; 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. // We'll have to use the short version.
num_revertable_str = vformat("(%d)", revertable_properties.size()); 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; 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( float text_offset_y = light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2;
margin_end, Point2 text_offset = Point2(margin_end, text_offset_y).round();
light_font->get_ascent(light_font_size) + (header_height - light_font->get_height(light_font_size)) / 2);
if (!rtl) { if (!rtl) {
text_offset.x = get_size().width - (text_offset.x + num_revertable_width); 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); 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; margin_end += num_revertable_width + outer_margin;
available -= num_revertable_width + separation; available -= num_revertable_width + outer_margin;
} }
// - Label. // - Label.
Point2 text_offset = Point2( float text_offset_y = font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2;
margin_start, Point2 text_offset = Point2(margin_start, text_offset_y).round();
font->get_ascent(font_size) + (header_height - font->get_height(font_size)) / 2);
if (rtl) { if (rtl) {
text_offset.x = margin_end; text_offset.x = margin_end;
} }
@ -4077,6 +4083,10 @@ void EditorInspector::_node_removed(Node *p_node) {
void EditorInspector::_notification(int p_what) { void EditorInspector::_notification(int p_what) {
switch (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: { case NOTIFICATION_READY: {
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed)); EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &EditorInspector::_feature_profile_changed));
set_process(is_visible_in_tree()); set_process(is_visible_in_tree());
@ -4340,7 +4350,6 @@ EditorInspector::EditorInspector() {
object = nullptr; object = nullptr;
main_vbox = memnew(VBoxContainer); main_vbox = memnew(VBoxContainer);
main_vbox->set_h_size_flags(SIZE_EXPAND_FILL); main_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
main_vbox->add_theme_constant_override("separation", 0);
add_child(main_vbox); add_child(main_vbox);
set_horizontal_scroll_mode(SCROLL_MODE_DISABLED); set_horizontal_scroll_mode(SCROLL_MODE_DISABLED);
set_follow_focus(true); set_follow_focus(true);

View file

@ -2087,6 +2087,9 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme
// Editor inspector. // Editor inspector.
{ {
// Vertical separation between inspector categories and sections.
p_theme->set_constant("v_separation", "EditorInspector", 0);
// EditorProperty. // EditorProperty.
Ref<StyleBoxFlat> style_property_bg = p_config.base_style->duplicate(); Ref<StyleBoxFlat> style_property_bg = p_config.base_style->duplicate();
@ -2128,6 +2131,7 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme
Ref<StyleBoxFlat> inspector_indent_style = make_flat_stylebox(inspector_indent_color, 2.0 * EDSCALE, 0, 2.0 * EDSCALE, 0); Ref<StyleBoxFlat> 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_stylebox("indent_box", "EditorInspectorSection", inspector_indent_style);
p_theme->set_constant("indent_size", "EditorInspectorSection", 6.0 * EDSCALE); 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_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); 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<EditorTheme> &p_theme
Ref<StyleBoxFlat> category_bg = p_config.base_style->duplicate(); Ref<StyleBoxFlat> category_bg = p_config.base_style->duplicate();
category_bg->set_bg_color(prop_category_color); category_bg->set_bg_color(prop_category_color);
category_bg->set_border_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_stylebox("bg", "EditorInspectorCategory", category_bg);
p_theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE); p_theme->set_constant("inspector_margin", EditorStringName(Editor), 12 * EDSCALE);