Skip to content

Commit 0349425

Browse files
committed
Fix issues with property height in the inspector
1 parent f5918a9 commit 0349425

14 files changed

+171
-93
lines changed

editor/gui/editor_spin_slider.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "core/math/expression.h"
3535
#include "core/os/keyboard.h"
3636
#include "core/string/translation_server.h"
37+
#include "editor/editor_string_names.h"
3738
#include "editor/settings/editor_settings.h"
3839
#include "editor/themes/editor_scale.h"
3940
#include "scene/theme/theme_db.h"
@@ -464,6 +465,7 @@ void EditorSpinSlider::_notification(int p_what) {
464465
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
465466
case NOTIFICATION_TRANSLATION_CHANGED:
466467
case NOTIFICATION_THEME_CHANGED: {
468+
set_custom_minimum_size(Size2(0, get_theme_constant(SNAME("inspector_property_height"), EditorStringName(Editor))));
467469
_update_value_input_stylebox();
468470
} break;
469471

@@ -516,17 +518,6 @@ LineEdit *EditorSpinSlider::get_line_edit() {
516518
return value_input;
517519
}
518520

519-
Size2 EditorSpinSlider::get_minimum_size() const {
520-
Ref<StyleBox> sb = get_theme_stylebox(CoreStringName(normal), SNAME("LineEdit"));
521-
Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("LineEdit"));
522-
int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("LineEdit"));
523-
524-
Size2 ms = sb->get_minimum_size();
525-
ms.height += font->get_height(font_size);
526-
527-
return ms;
528-
}
529-
530521
void EditorSpinSlider::set_control_state(ControlState p_state) {
531522
control_state = p_state;
532523
queue_redraw();

editor/gui/editor_spin_slider.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class EditorSpinSlider : public Range {
141141
void setup_and_show() { _focus_entered(); }
142142
LineEdit *get_line_edit();
143143

144-
virtual Size2 get_minimum_size() const override;
145144
EditorSpinSlider();
146145
};
147146

editor/inspector/editor_inspector.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ Size2 EditorProperty::get_minimum_size() const {
219219
return Vector2();
220220
}
221221

222-
Size2 ms;
223-
int separation = 4 * EDSCALE;
224-
ms.height = label.is_empty() ? 0 : theme_cache.font->get_height(theme_cache.font_size) + separation;
225-
222+
Size2 ms = Size2(0, theme_cache.inspector_property_height);
226223
for (int i = 0; i < get_child_count(); i++) {
227224
Control *c = as_sortable_control(get_child(i));
228225
if (!c) {
@@ -316,7 +313,7 @@ void EditorProperty::_notification(int p_what) {
316313
{
317314
int child_room = size.width * (1.0 - split_ratio);
318315
int separation = 4 * EDSCALE;
319-
int height = label.is_empty() ? 0 : theme_cache.font->get_height(theme_cache.font_size) + separation;
316+
int height = theme_cache.inspector_property_height;
320317
int half_padding = theme_cache.padding / 2;
321318
bool no_children = true;
322319

@@ -1982,8 +1979,6 @@ void EditorInspectorSection::_notification(int p_what) {
19821979

19831980
bg_color = theme_cache.prop_subsection;
19841981
bg_color.a /= level;
1985-
1986-
vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
19871982
} break;
19881983

19891984
case NOTIFICATION_SORT_CHILDREN: {
@@ -2546,6 +2541,7 @@ EditorInspectorSection::EditorInspectorSection() {
25462541
set_focus_mode(FOCUS_ACCESSIBILITY);
25472542

25482543
vbox = memnew(VBoxContainer);
2544+
vbox->set_theme_type_variation(SNAME("EditorPropertyContainer"));
25492545

25502546
dropping_unfold_timer = memnew(Timer);
25512547
dropping_unfold_timer->set_wait_time(EDITOR_GET("interface/editor/dragging_hover_wait_seconds"));
@@ -3557,7 +3553,7 @@ void EditorInspector::initialize_section_theme(EditorInspectorSection::ThemeCach
35573553
}
35583554

35593555
p_cache.horizontal_separation = p_control->get_theme_constant(SNAME("h_separation"), SNAME("EditorInspectorSection"));
3560-
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"));
3556+
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("separation"), SNAME("EditorPropertyContainer"));
35613557
p_cache.inspector_margin = p_control->get_theme_constant(SNAME("inspector_margin"), EditorStringName(Editor));
35623558
p_cache.indent_size = p_control->get_theme_constant(SNAME("indent_size"), SNAME("EditorInspectorSection"));
35633559
p_cache.key_padding_size = int(EDITOR_GET("interface/theme/base_spacing")) * 2;
@@ -3596,7 +3592,7 @@ void EditorInspector::initialize_category_theme(EditorInspectorCategory::ThemeCa
35963592
}
35973593

35983594
p_cache.horizontal_separation = p_control->get_theme_constant(SNAME("h_separation"), SNAME("Tree"));
3599-
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"));
3595+
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("separation"), SNAME("EditorPropertyContainer"));
36003596
p_cache.class_icon_size = p_control->get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
36013597

36023598
p_cache.font_color = p_control->get_theme_color(SceneStringName(font_color), SNAME("Tree"));
@@ -3644,8 +3640,9 @@ void EditorInspector::initialize_property_theme(EditorProperty::ThemeCache &p_ca
36443640
p_cache.font_size = p_control->get_theme_font_size(SceneStringName(font_size), SNAME("Tree"));
36453641
p_cache.font_offset = p_control->get_theme_constant(SNAME("font_offset"), SNAME("EditorProperty"));
36463642
p_cache.horizontal_separation = p_control->get_theme_constant(SNAME("h_separation"), SNAME("Tree"));
3647-
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("v_separation"), SNAME("EditorProperty"));
3643+
p_cache.vertical_separation = p_control->get_theme_constant(SNAME("separation"), SNAME("EditorPropertyContainer"));
36483644
p_cache.padding = int(EDITOR_GET("interface/theme/base_spacing")) * 2;
3645+
p_cache.inspector_property_height = p_control->get_theme_constant(SNAME("inspector_property_height"), EditorStringName(Editor));
36493646

36503647
p_cache.property_color = p_control->get_theme_color(SNAME("property_color"), SNAME("EditorProperty"));
36513648
p_cache.readonly_property_color = p_control->get_theme_color(SNAME("readonly_color"), SNAME("EditorProperty"));
@@ -3807,15 +3804,15 @@ bool EditorInspector::_is_property_disabled_by_feature_profile(const StringName
38073804
}
38083805

38093806
void EditorInspector::_add_section_in_tree(EditorInspectorSection *p_section, VBoxContainer *p_current_vbox) {
3810-
// Place adjacent sections in their own vbox with 0 separation
3807+
// Place adjacent sections in their own vbox with a theme-specific separation.
38113808
VBoxContainer *container = nullptr;
38123809
if (p_current_vbox->get_child_count() > 0) {
38133810
Node *last_child = p_current_vbox->get_child(-1);
38143811
container = Object::cast_to<VBoxContainer>(last_child);
38153812
}
38163813
if (!container) {
38173814
container = memnew(VBoxContainer);
3818-
container->add_theme_constant_override("separation", theme_cache.vertical_separation);
3815+
container->set_theme_type_variation(SNAME("EditorInspectorContainer"));
38193816
p_current_vbox->add_child(container);
38203817
}
38213818
container->add_child(p_section);
@@ -3919,13 +3916,15 @@ void EditorInspector::update_tree() {
39193916
bool sub_inspectors_enabled = EDITOR_GET("interface/inspector/open_resources_in_current_inspector");
39203917

39213918
if (!valid_plugins.is_empty()) {
3922-
begin_vbox->show();
3923-
3924-
// Get the lists of editors to add the beginning.
39253919
for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
39263920
ped->parse_begin(object);
39273921
_parse_added_editors(begin_vbox, nullptr, ped);
39283922
}
3923+
3924+
// Show if any of the editors were added to the beginning.
3925+
if (begin_vbox->get_child_count() > 0) {
3926+
begin_vbox->show();
3927+
}
39293928
}
39303929

39313930
StringName doc_name;
@@ -4217,7 +4216,7 @@ void EditorInspector::update_tree() {
42174216
// Recreate the category vbox if it was reset.
42184217
if (category_vbox == nullptr) {
42194218
category_vbox = memnew(VBoxContainer);
4220-
category_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
4219+
category_vbox->set_theme_type_variation(SNAME("EditorPropertyContainer"));
42214220
category_vbox->hide();
42224221
main_vbox->add_child(category_vbox);
42234222
}
@@ -4684,6 +4683,8 @@ void EditorInspector::update_tree() {
46844683
String tooltip;
46854684
VBoxContainer *parent_vbox = favorites_vbox;
46864685
if (!section_name.is_empty()) {
4686+
favorites_groups_vbox->show();
4687+
46874688
if (is_localized) {
46884689
label = EditorPropertyNameProcessor::get_singleton()->translate_group_name(section_name);
46894690
tooltip = section_name;
@@ -4785,6 +4786,10 @@ void EditorInspector::update_tree() {
47854786
}
47864787
}
47874788
}
4789+
4790+
if (favorites_vbox->get_child_count() > 0) {
4791+
favorites_vbox->show();
4792+
}
47884793
}
47894794

47904795
// Show a separator if there's no category to clearly divide the properties.
@@ -4863,9 +4868,11 @@ void EditorInspector::_clear(bool p_hide_plugins) {
48634868
}
48644869

48654870
favorites_section->hide();
4871+
favorites_vbox->hide();
48664872
while (favorites_vbox->get_child_count()) {
48674873
memdelete(favorites_vbox->get_child(0));
48684874
}
4875+
favorites_groups_vbox->hide();
48694876
while (favorites_groups_vbox->get_child_count()) {
48704877
memdelete(favorites_groups_vbox->get_child(0));
48714878
}
@@ -5648,19 +5655,11 @@ void EditorInspector::_notification(int p_what) {
56485655
break;
56495656
}
56505657

5651-
theme_cache.vertical_separation = get_theme_constant(SNAME("v_separation"), SNAME("EditorInspector"));
56525658
theme_cache.prop_subsection = get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor));
5653-
theme_cache.icon_add = get_editor_theme_icon(SNAME("Add"));
56545659

56555660
initialize_section_theme(section_theme_cache, this);
56565661
initialize_category_theme(category_theme_cache, this);
56575662
initialize_property_theme(property_theme_cache, this);
5658-
5659-
base_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
5660-
begin_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
5661-
favorites_section->add_theme_constant_override("separation", theme_cache.vertical_separation);
5662-
favorites_groups_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
5663-
main_vbox->add_theme_constant_override("separation", theme_cache.vertical_separation);
56645663
} break;
56655664

56665665
case NOTIFICATION_READY: {
@@ -5893,14 +5892,17 @@ EditorInspector::EditorInspector() {
58935892
object = nullptr;
58945893

58955894
base_vbox = memnew(VBoxContainer);
5895+
base_vbox->set_theme_type_variation(SNAME("EditorInspectorContainer"));
58965896
base_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
58975897
add_child(base_vbox);
58985898

58995899
begin_vbox = memnew(VBoxContainer);
5900+
begin_vbox->set_theme_type_variation(SNAME("EditorInspectorContainer"));
59005901
base_vbox->add_child(begin_vbox);
59015902
begin_vbox->hide();
59025903

59035904
favorites_section = memnew(VBoxContainer);
5905+
favorites_section->set_theme_type_variation(SNAME("EditorInspectorContainer"));
59045906
base_vbox->add_child(favorites_section);
59055907
favorites_section->hide();
59065908

@@ -5910,15 +5912,20 @@ EditorInspector::EditorInspector() {
59105912
favorites_section->add_child(favorites_category);
59115913

59125914
favorites_vbox = memnew(VBoxContainer);
5915+
favorites_vbox->set_theme_type_variation(SNAME("EditorPropertyContainer"));
59135916
favorites_section->add_child(favorites_vbox);
5917+
favorites_vbox->hide();
59145918
favorites_groups_vbox = memnew(VBoxContainer);
5919+
favorites_groups_vbox->set_theme_type_variation(SNAME("EditorInspectorContainer"));
59155920
favorites_section->add_child(favorites_groups_vbox);
5921+
favorites_groups_vbox->hide();
59165922

59175923
favorites_separator = memnew(HSeparator);
59185924
favorites_section->add_child(favorites_separator);
59195925
favorites_separator->hide();
59205926

59215927
main_vbox = memnew(VBoxContainer);
5928+
main_vbox->set_theme_type_variation(SNAME("EditorInspectorContainer"));
59225929
base_vbox->add_child(main_vbox);
59235930

59245931
set_horizontal_scroll_mode(SCROLL_MODE_DISABLED);

editor/inspector/editor_inspector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class EditorProperty : public Container {
102102
int horizontal_separation = 0;
103103
int vertical_separation = 0;
104104
int padding = 0;
105+
int inspector_property_height = 0;
105106

106107
Color property_color;
107108
Color readonly_property_color;
@@ -701,9 +702,7 @@ class EditorInspector : public ScrollContainer {
701702
static int inspector_plugin_count;
702703

703704
struct ThemeCache {
704-
int vertical_separation = 0;
705705
Color prop_subsection;
706-
Ref<Texture2D> icon_add;
707706
} theme_cache;
708707

709708
EditorInspectorSection::ThemeCache section_theme_cache;

0 commit comments

Comments
 (0)