Skip to content

Commit 5a09650

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 fa65582 commit 5a09650

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
@@ -461,6 +461,8 @@ void EditorPropertyArray::update_property() {
461461
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element"));
462462
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
463463
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element));
464+
button_add_item->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyArray::_button_add_item_draw));
465+
SET_DRAG_FORWARDING_CD(button_add_item, EditorPropertyArray);
464466
button_add_item->set_disabled(is_read_only());
465467
vbox->add_child(button_add_item);
466468

@@ -552,6 +554,13 @@ void EditorPropertyArray::_button_draw() {
552554
}
553555
}
554556

557+
void EditorPropertyArray::_button_add_item_draw() {
558+
if (button_add_item && dropping) {
559+
Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
560+
button_add_item->draw_rect(Rect2(Point2(), button_add_item->get_size()), color, false);
561+
}
562+
}
563+
555564
bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
556565
if (is_read_only()) {
557566
return false;
@@ -770,6 +779,9 @@ void EditorPropertyArray::_notification(int p_what) {
770779
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
771780
dropping = true;
772781
edit->queue_redraw();
782+
if (button_add_item) {
783+
button_add_item->queue_redraw();
784+
}
773785
}
774786
}
775787
} break;
@@ -778,6 +790,9 @@ void EditorPropertyArray::_notification(int p_what) {
778790
if (dropping) {
779791
dropping = false;
780792
edit->queue_redraw();
793+
if (button_add_item) {
794+
button_add_item->queue_redraw();
795+
}
781796
}
782797
} break;
783798
}

editor/editor_properties_array_dict.h

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

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

0 commit comments

Comments
 (0)