Skip to content

Commit

Permalink
Merge pull request #93435 from passivestar/themable-inspector
Browse files Browse the repository at this point in the history
Make inspector spacing more themable
  • Loading branch information
akien-mga committed Jun 24, 2024
2 parents f9c5118 + 6bb58ca commit d4d123c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
41 changes: 25 additions & 16 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -1283,6 +1287,9 @@ Size2 EditorInspectorCategory::get_minimum_size() const {
}
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;
}

Expand Down Expand Up @@ -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<Texture2D> arrow = _get_arrow();
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,9 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme

// Editor inspector.
{
// Vertical separation between inspector categories and sections.
p_theme->set_constant("v_separation", "EditorInspector", 0);

// EditorProperty.

Ref<StyleBoxFlat> style_property_bg = p_config.base_style->duplicate();
Expand Down Expand Up @@ -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);
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);
Expand All @@ -2145,6 +2149,7 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme
Ref<StyleBoxFlat> 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);
Expand Down

0 comments on commit d4d123c

Please sign in to comment.