Skip to content

Commit 5345910

Browse files
committed
Merge pull request #103257 from dugramen/simplify-array-inspector
Condense Inspector layout for Arrays
2 parents 2b3c397 + 7df65de commit 5345910

File tree

4 files changed

+151
-17
lines changed

4 files changed

+151
-17
lines changed

editor/inspector/editor_inspector.cpp

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ Size2 EditorProperty::get_minimum_size() const {
232232
if (c == bottom_editor) {
233233
continue;
234234
}
235+
if (c == left_container) {
236+
continue;
237+
}
238+
if (c == right_container) {
239+
continue;
240+
}
235241

236242
Size2 minsize = c->get_combined_minimum_size();
237243
ms = ms.max(minsize);
@@ -249,6 +255,14 @@ Size2 EditorProperty::get_minimum_size() const {
249255
ms.width += theme_cache.checked_icon->get_width() + theme_cache.padding + theme_cache.horizontal_separation;
250256
}
251257

258+
Size2 ls = left_container->get_combined_minimum_size();
259+
ms.width += ls.x;
260+
ms.height = MAX(ms.height, ls.y);
261+
262+
Size2 rs = right_container->get_combined_minimum_size();
263+
ms.width += rs.x;
264+
ms.height = MAX(ms.height, rs.y);
265+
252266
if (bottom_editor != nullptr && bottom_editor->is_visible()) {
253267
ms.height += label.is_empty() ? 0 : _get_v_separation();
254268
Size2 bems = bottom_editor->get_combined_minimum_size();
@@ -318,9 +332,11 @@ void EditorProperty::_notification(int p_what) {
318332
}
319333

320334
Size2 minsize = c->get_combined_minimum_size();
321-
child_room = MAX(child_room, minsize.width);
335+
if (c != left_container && c != right_container) {
336+
child_room = MAX(child_room, minsize.width);
337+
no_children = false;
338+
}
322339
height = MAX(height, minsize.height);
323-
no_children = false;
324340
}
325341

326342
if (no_children) {
@@ -338,6 +354,13 @@ void EditorProperty::_notification(int p_what) {
338354
}
339355
}
340356

357+
if (rect.size.x > 1) {
358+
rect.size.x -= right_container->get_combined_minimum_size().x;
359+
if (is_layout_rtl()) {
360+
rect.position.x += right_container->get_combined_minimum_size().x;
361+
}
362+
}
363+
341364
if (bottom_editor) {
342365
int v_offset = label.is_empty() ? 0 : _get_v_separation();
343366
bottom_rect = Rect2(0, rect.size.height + v_offset, size.width, bottom_editor->get_combined_minimum_size().height);
@@ -396,6 +419,12 @@ void EditorProperty::_notification(int p_what) {
396419
if (c == bottom_editor) {
397420
continue;
398421
}
422+
if (c == left_container) {
423+
continue;
424+
}
425+
if (c == right_container) {
426+
continue;
427+
}
399428

400429
fit_child_in_rect(c, rect);
401430
right_child_rect = rect;
@@ -406,6 +435,21 @@ void EditorProperty::_notification(int p_what) {
406435
bottom_child_rect = bottom_rect;
407436
}
408437

438+
Size2 rs = right_container->get_combined_minimum_size();
439+
if (is_layout_rtl()) {
440+
fit_child_in_rect(right_container, Rect2(0, 0, rs.width, rs.y));
441+
} else {
442+
fit_child_in_rect(right_container, Rect2(size.width - rs.width, 0, rs.width, rs.y));
443+
}
444+
445+
Size2 ls = left_container->get_combined_minimum_size();
446+
real_t right_size = rect.size.x + rs.x;
447+
if (is_layout_rtl()) {
448+
fit_child_in_rect(left_container, Rect2(right_size, 0, size.x - right_size, ls.y));
449+
} else {
450+
fit_child_in_rect(left_container, Rect2(0, 0, size.x - right_size, ls.y));
451+
}
452+
409453
queue_redraw(); //need to redraw text
410454
} break;
411455

@@ -419,6 +463,8 @@ void EditorProperty::_notification(int p_what) {
419463
size.height = bottom_editor->get_offset(SIDE_TOP) - _get_v_separation();
420464
} else if (label_reference) {
421465
size.height = label_reference->get_size().height;
466+
} else if (label_overlayed) {
467+
size.height = left_container->get_size().height;
422468
}
423469

424470
// Only draw the label if it's not empty.
@@ -456,6 +502,10 @@ void EditorProperty::_notification(int p_what) {
456502
int half_padding = EDITOR_GET("interface/theme/base_spacing");
457503
int padding = half_padding * 2;
458504

505+
int left_ofs = left_container->get_combined_minimum_size().x;
506+
ofs += left_ofs;
507+
text_limit -= left_ofs;
508+
459509
if (checkable) {
460510
Ref<Texture2D> checkbox;
461511
if (checked) {
@@ -549,6 +599,7 @@ void EditorProperty::_notification(int p_what) {
549599
}
550600

551601
ofs = size.width;
602+
ofs -= right_container->get_minimum_size().x;
552603

553604
if (keying) {
554605
Ref<Texture2D> key;
@@ -963,6 +1014,22 @@ bool EditorProperty::is_selected() const {
9631014
return selected;
9641015
}
9651016

1017+
void EditorProperty::add_inline_control(Control *p_control, InlineControlSide p_side) {
1018+
Node *parent = p_control->get_parent();
1019+
if (parent != nullptr) {
1020+
parent->remove_child(p_control);
1021+
}
1022+
if (p_side == INLINE_CONTROL_LEFT) {
1023+
left_container->add_child(p_control);
1024+
} else {
1025+
right_container->add_child(p_control);
1026+
}
1027+
}
1028+
1029+
void EditorProperty::set_label_overlayed(bool p_overlay) {
1030+
label_overlayed = p_overlay;
1031+
}
1032+
9661033
void EditorProperty::gui_input(const Ref<InputEvent> &p_event) {
9671034
ERR_FAIL_COND(p_event.is_null());
9681035

@@ -1143,6 +1210,14 @@ void EditorProperty::set_label_reference(Control *p_control) {
11431210
label_reference = p_control;
11441211
}
11451212

1213+
HBoxContainer *EditorProperty::get_inline_container(InlineControlSide p_side) {
1214+
if (p_side == INLINE_CONTROL_LEFT) {
1215+
return left_container;
1216+
} else {
1217+
return right_container;
1218+
}
1219+
}
1220+
11461221
void EditorProperty::set_bottom_editor(Control *p_control) {
11471222
bottom_editor = p_control;
11481223
if (has_borders) {
@@ -1467,6 +1542,15 @@ EditorProperty::EditorProperty() {
14671542
label_reference = nullptr;
14681543
bottom_editor = nullptr;
14691544
menu = nullptr;
1545+
1546+
left_container = memnew(HBoxContainer);
1547+
left_container->add_theme_constant_override(SNAME("separation"), 0);
1548+
add_child(left_container);
1549+
1550+
right_container = memnew(HBoxContainer);
1551+
right_container->add_theme_constant_override(SNAME("separation"), 0);
1552+
add_child(right_container);
1553+
14701554
set_process_shortcut_input(true);
14711555
}
14721556

editor/inspector/editor_inspector.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ class EditorProperty : public Container {
136136
COLORATION_EXTERNAL,
137137
};
138138

139+
enum InlineControlSide {
140+
INLINE_CONTROL_LEFT,
141+
INLINE_CONTROL_RIGHT
142+
};
143+
139144
private:
140145
String label;
141146
int text_size;
@@ -158,6 +163,7 @@ class EditorProperty : public Container {
158163
bool draw_prop_warning = false;
159164
bool keying = false;
160165
bool deletable = false;
166+
bool label_overlayed = false;
161167

162168
Rect2 right_child_rect;
163169
Rect2 bottom_child_rect;
@@ -198,6 +204,8 @@ class EditorProperty : public Container {
198204
Control *label_reference = nullptr;
199205
Control *bottom_editor = nullptr;
200206
PopupMenu *menu = nullptr;
207+
HBoxContainer *left_container = nullptr;
208+
HBoxContainer *right_container = nullptr;
201209

202210
HashMap<StringName, Variant> cache;
203211

@@ -284,6 +292,10 @@ class EditorProperty : public Container {
284292
void deselect();
285293
bool is_selected() const;
286294

295+
void add_inline_control(Control *p_control, InlineControlSide p_side);
296+
HBoxContainer *get_inline_container(InlineControlSide p_side);
297+
void set_label_overlayed(bool p_overlay);
298+
287299
void set_label_reference(Control *p_control);
288300
void set_bottom_editor(Control *p_control);
289301

editor/inspector/editor_properties_array_dict.cpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -305,35 +305,38 @@ void EditorPropertyArray::_create_new_property_slot() {
305305
int idx = slots.size();
306306
HBoxContainer *hbox = memnew(HBoxContainer);
307307

308+
EditorProperty *prop = memnew(EditorPropertyNil);
309+
308310
Button *reorder_button = memnew(Button);
309311
reorder_button->set_accessibility_name(TTRC("Reorder"));
310312
reorder_button->set_button_icon(get_editor_theme_icon(SNAME("TripleBar")));
311313
reorder_button->set_default_cursor_shape(Control::CURSOR_MOVE);
312314
reorder_button->set_disabled(is_read_only());
315+
reorder_button->set_theme_type_variation(SceneStringName(FlatButton));
313316
reorder_button->connect(SceneStringName(gui_input), callable_mp(this, &EditorPropertyArray::_reorder_button_gui_input));
314317
reorder_button->connect(SNAME("button_up"), callable_mp(this, &EditorPropertyArray::_reorder_button_up));
315318
reorder_button->connect(SNAME("button_down"), callable_mp(this, &EditorPropertyArray::_reorder_button_down).bind(idx));
316319

317-
hbox->add_child(reorder_button);
318-
EditorProperty *prop = memnew(EditorPropertyNil);
319320
hbox->add_child(prop);
320321

321322
bool is_untyped_array = object->get_array().get_type() == Variant::ARRAY && subtype == Variant::NIL;
322323

324+
Button *edit_btn = nullptr;
325+
Button *remove_btn = nullptr;
323326
if (is_untyped_array) {
324-
Button *edit_btn = memnew(Button);
327+
edit_btn = memnew(Button);
325328
edit_btn->set_accessibility_name(TTRC("Edit"));
326329
edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
327330
edit_btn->set_disabled(is_read_only());
331+
edit_btn->set_theme_type_variation(SceneStringName(FlatButton));
328332
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_change_type).bind(edit_btn, idx));
329-
hbox->add_child(edit_btn);
330333
} else {
331-
Button *remove_btn = memnew(Button);
334+
remove_btn = memnew(Button);
332335
remove_btn->set_accessibility_name(TTRC("Remove"));
333336
remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
334337
remove_btn->set_disabled(is_read_only());
338+
remove_btn->set_theme_type_variation(SceneStringName(FlatButton));
335339
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_remove_pressed).bind(idx));
336-
hbox->add_child(remove_btn);
337340
}
338341
property_vbox->add_child(hbox);
339342

@@ -342,6 +345,8 @@ void EditorPropertyArray::_create_new_property_slot() {
342345
slot.object = object;
343346
slot.container = hbox;
344347
slot.reorder_button = reorder_button;
348+
slot.edit_button = edit_btn;
349+
slot.remove_button = remove_btn;
345350
slot.set_index(idx + page_index * page_length);
346351
slots.push_back(slot);
347352
}
@@ -513,6 +518,17 @@ void EditorPropertyArray::update_property() {
513518
new_prop->connect(SNAME("object_id_selected"), callable_mp(this, &EditorPropertyArray::_object_id_selected));
514519
new_prop->set_h_size_flags(SIZE_EXPAND_FILL);
515520
new_prop->set_read_only(is_read_only());
521+
522+
if (slot.reorder_button) {
523+
new_prop->add_inline_control(slot.reorder_button, INLINE_CONTROL_LEFT);
524+
slot.reorder_button->get_parent()->move_child(slot.reorder_button, 0);
525+
}
526+
if (slot.edit_button) {
527+
new_prop->add_inline_control(slot.edit_button, INLINE_CONTROL_RIGHT);
528+
} else if (slot.remove_button) {
529+
new_prop->add_inline_control(slot.remove_button, INLINE_CONTROL_RIGHT);
530+
}
531+
516532
slot.prop->add_sibling(new_prop, false);
517533
slot.prop->queue_free();
518534
slot.prop = new_prop;
@@ -1047,33 +1063,34 @@ void EditorPropertyDictionary::_create_new_property_slot(int p_idx) {
10471063
EditorProperty *prop_key = nullptr;
10481064
if (p_idx != EditorPropertyDictionaryObject::NEW_KEY_INDEX && p_idx != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
10491065
prop_key = memnew(EditorPropertyNil);
1050-
hbox->add_child(prop_key);
10511066
}
10521067

10531068
EditorProperty *prop = memnew(EditorPropertyNil);
10541069
prop->set_h_size_flags(SIZE_EXPAND_FILL);
1055-
if (p_idx != EditorPropertyDictionaryObject::NEW_KEY_INDEX && p_idx != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
1056-
prop->set_draw_label(false);
1057-
}
10581070
hbox->add_child(prop);
1071+
if (prop_key) {
1072+
prop->add_inline_control(prop_key, INLINE_CONTROL_LEFT);
1073+
}
10591074

10601075
bool use_key = p_idx == EditorPropertyDictionaryObject::NEW_KEY_INDEX;
10611076
bool is_untyped_dict = (use_key ? key_subtype : value_subtype) == Variant::NIL;
10621077

1078+
Button *edit_btn = nullptr;
1079+
Button *remove_btn = nullptr;
10631080
if (is_untyped_dict) {
1064-
Button *edit_btn = memnew(Button);
1081+
edit_btn = memnew(Button);
10651082
edit_btn->set_accessibility_name(TTRC("Edit"));
10661083
edit_btn->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
10671084
edit_btn->set_disabled(is_read_only());
1085+
edit_btn->set_theme_type_variation(SceneStringName(FlatButton));
10681086
edit_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_change_type).bind(edit_btn, slots.size()));
1069-
hbox->add_child(edit_btn);
10701087
} else if (p_idx >= 0) {
1071-
Button *remove_btn = memnew(Button);
1088+
remove_btn = memnew(Button);
10721089
remove_btn->set_accessibility_name(TTRC("Remove"));
10731090
remove_btn->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
10741091
remove_btn->set_disabled(is_read_only());
1092+
remove_btn->set_theme_type_variation(SceneStringName(FlatButton));
10751093
remove_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_remove_pressed).bind(slots.size()));
1076-
hbox->add_child(remove_btn);
10771094
}
10781095

10791096
if (add_panel) {
@@ -1087,6 +1104,8 @@ void EditorPropertyDictionary::_create_new_property_slot(int p_idx) {
10871104
slot.prop_key = prop_key;
10881105
slot.object = object;
10891106
slot.container = hbox;
1107+
slot.edit_button = edit_btn;
1108+
slot.remove_button = remove_btn;
10901109
int index = p_idx + (p_idx >= 0 ? page_index * page_length : 0);
10911110
slot.set_index(index);
10921111
slots.push_back(slot);
@@ -1360,6 +1379,9 @@ void EditorPropertyDictionary::update_property() {
13601379
dict_prop->set_preview_value(true);
13611380
}
13621381
slot.set_key_prop(new_prop);
1382+
if (slot.prop) {
1383+
slot.prop->add_inline_control(new_prop, INLINE_CONTROL_LEFT);
1384+
}
13631385
}
13641386
}
13651387

@@ -1395,10 +1417,22 @@ void EditorPropertyDictionary::update_property() {
13951417
new_prop->connect(SNAME("object_id_selected"), callable_mp(this, &EditorPropertyDictionary::_object_id_selected));
13961418
new_prop->set_h_size_flags(SIZE_EXPAND_FILL);
13971419
if (slot.index != EditorPropertyDictionaryObject::NEW_KEY_INDEX && slot.index != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
1398-
new_prop->set_draw_label(false);
1420+
new_prop->set_label(" ");
1421+
new_prop->set_label_overlayed(true);
13991422
}
14001423
new_prop->set_read_only(is_read_only());
1424+
if (slot.remove_button) {
1425+
new_prop->add_inline_control(slot.remove_button, INLINE_CONTROL_RIGHT);
1426+
}
1427+
if (slot.edit_button) {
1428+
new_prop->add_inline_control(slot.edit_button, INLINE_CONTROL_RIGHT);
1429+
}
1430+
if (slot.prop_key) {
1431+
new_prop->add_inline_control(slot.prop_key, INLINE_CONTROL_LEFT);
1432+
}
1433+
14011434
slot.set_prop(new_prop);
1435+
14021436
} else if (slot.index != EditorPropertyDictionaryObject::NEW_KEY_INDEX && slot.index != EditorPropertyDictionaryObject::NEW_VALUE_INDEX) {
14031437
Variant key = dict.get_key_at_index(slot.index);
14041438
String cs = key.get_construct_string();

editor/inspector/editor_properties_array_dict.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class EditorPropertyArray : public EditorProperty {
100100
bool as_id = false;
101101
EditorProperty *prop = nullptr;
102102
Button *reorder_button = nullptr;
103+
Button *edit_button = nullptr;
104+
Button *remove_button = nullptr;
103105

104106
void set_index(int p_idx) {
105107
String prop_name = "indices/" + itos(p_idx);
@@ -186,6 +188,8 @@ class EditorPropertyDictionary : public EditorProperty {
186188
bool key_as_id = false;
187189
EditorProperty *prop = nullptr;
188190
EditorProperty *prop_key = nullptr;
191+
Button *edit_button = nullptr;
192+
Button *remove_button = nullptr;
189193
String prop_name;
190194
String key_name;
191195

0 commit comments

Comments
 (0)