Skip to content

Commit 93d342b

Browse files
committed
Allow dragging items onto array property editor Add Element button
Instead of having to first click the button, then drag the item into the new slot, this allows just dragging the item onto the button directly. The button is highlighted as a valid drop target to signal this.
1 parent b557840 commit 93d342b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

editor/editor_properties_array_dict.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ void EditorPropertyArray::update_property() {
460460
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element"));
461461
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
462462
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element));
463+
button_add_item->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyArray::_button_add_item_draw));
464+
SET_DRAG_FORWARDING_CD(button_add_item, EditorPropertyArray);
463465
button_add_item->set_disabled(is_read_only());
464466
vbox->add_child(button_add_item);
465467

@@ -551,6 +553,13 @@ void EditorPropertyArray::_button_draw() {
551553
}
552554
}
553555

556+
void EditorPropertyArray::_button_add_item_draw() {
557+
if (dropping) {
558+
Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
559+
button_add_item->draw_rect(Rect2(Point2(), button_add_item->get_size()), color, false);
560+
}
561+
}
562+
554563
bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
555564
if (is_read_only()) {
556565
return false;
@@ -766,6 +775,9 @@ void EditorPropertyArray::_notification(int p_what) {
766775
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
767776
dropping = true;
768777
edit->queue_redraw();
778+
if (button_add_item) {
779+
button_add_item->queue_redraw();
780+
}
769781
}
770782
}
771783
} break;
@@ -774,6 +786,9 @@ void EditorPropertyArray::_notification(int p_what) {
774786
if (dropping) {
775787
dropping = false;
776788
edit->queue_redraw();
789+
if (button_add_item) {
790+
button_add_item->queue_redraw();
791+
}
777792
}
778793
} break;
779794
}

editor/editor_properties_array_dict.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class EditorPropertyArray : public EditorProperty {
163163
virtual void _remove_pressed(int p_index);
164164

165165
virtual void _button_draw();
166+
virtual void _button_add_item_draw();
166167
virtual bool _is_drop_valid(const Dictionary &p_drag_data) const;
167168
virtual bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
168169
virtual void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);

0 commit comments

Comments
 (0)