From 2cd0f3584d03fbc9bc1e0e1d2f641335c9ce18f1 Mon Sep 17 00:00:00 2001 From: passivestar <60579014+passivestar@users.noreply.github.com> Date: Wed, 12 Jun 2024 18:02:24 +0400 Subject: [PATCH] Fix EditorProperty spacing --- editor/editor_inspector.cpp | 35 +++++++++++++++++++++++------------ editor/icons/Key.svg | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 33f460e23db..7f21bb9ca87 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -88,17 +88,17 @@ Size2 EditorProperty::get_minimum_size() const { if (keying) { Ref key = get_editor_theme_icon(SNAME("Key")); - ms.width += key->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (deletable) { Ref key = get_editor_theme_icon(SNAME("Close")); - ms.width += key->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + ms.width += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (checkable) { Ref check = get_theme_icon(SNAME("checked"), SNAME("CheckBox")); - ms.width += check->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("CheckBox")) + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + ms.width += check->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (bottom_editor != nullptr && bottom_editor->is_visible()) { @@ -179,9 +179,9 @@ void EditorProperty::_notification(int p_what) { key = get_editor_theme_icon(SNAME("Key")); } - rect.size.x -= key->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + rect.size.x -= key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); if (is_layout_rtl()) { - rect.position.x += key->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + rect.position.x += key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (no_children) { @@ -194,16 +194,27 @@ void EditorProperty::_notification(int p_what) { close = get_editor_theme_icon(SNAME("Close")); - rect.size.x -= close->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + rect.size.x -= close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); if (is_layout_rtl()) { - rect.position.x += close->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + rect.position.x += close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); } if (no_children) { text_size -= close->get_width() + 4 * EDSCALE; } } + + // Account for the space needed on the outer side + // when any of the icons are visible. + if (keying || deletable) { + int separation = get_theme_constant(SNAME("h_separation"), SNAME("Tree")); + rect.size.x -= separation; + + if (is_layout_rtl()) { + rect.position.x += separation; + } + } } //set children @@ -291,7 +302,7 @@ void EditorProperty::_notification(int p_what) { } else { draw_texture(checkbox, check_rect.position, color2); } - int check_ofs = get_theme_constant(SNAME("hseparator"), SNAME("Tree")) + checkbox->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("CheckBox")); + int check_ofs = checkbox->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); ofs += check_ofs; text_limit -= check_ofs; } else { @@ -300,7 +311,7 @@ void EditorProperty::_notification(int p_what) { if (can_revert && !is_read_only()) { Ref reload_icon = get_editor_theme_icon(SNAME("ReloadSmall")); - text_limit -= reload_icon->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")) * 2; + text_limit -= reload_icon->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); revert_rect = Rect2(ofs + text_limit, (size.height - reload_icon->get_height()) / 2, reload_icon->get_width(), reload_icon->get_height()); Color color2(1, 1, 1); @@ -320,7 +331,7 @@ void EditorProperty::_notification(int p_what) { if (!pin_hidden && pinned) { Ref pinned_icon = get_editor_theme_icon(SNAME("Pin")); - int margin_w = get_theme_constant(SNAME("hseparator"), SNAME("Tree")) * 2; + int margin_w = get_theme_constant(SNAME("h_separation"), SNAME("Tree")); int total_icon_w = margin_w + pinned_icon->get_width(); int text_w = font->get_string_size(label, rtl ? HORIZONTAL_ALIGNMENT_RIGHT : HORIZONTAL_ALIGNMENT_LEFT, text_limit - total_icon_w, font_size).x; int y = (size.height - pinned_icon->get_height()) / 2; @@ -350,7 +361,7 @@ void EditorProperty::_notification(int p_what) { key = get_editor_theme_icon(SNAME("Key")); } - ofs -= key->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + ofs -= key->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); Color color2(1, 1, 1); if (keying_hover) { @@ -374,7 +385,7 @@ void EditorProperty::_notification(int p_what) { close = get_editor_theme_icon(SNAME("Close")); - ofs -= close->get_width() + get_theme_constant(SNAME("hseparator"), SNAME("Tree")); + ofs -= close->get_width() + get_theme_constant(SNAME("h_separation"), SNAME("Tree")); Color color2(1, 1, 1); if (delete_hover) { diff --git a/editor/icons/Key.svg b/editor/icons/Key.svg index fdf51fd72dd..d0838b68cd5 100644 --- a/editor/icons/Key.svg +++ b/editor/icons/Key.svg @@ -1 +1 @@ - + \ No newline at end of file