Skip to content

Commit

Permalink
Allow dragging items onto array property editor Add Element button
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ttencate committed Feb 7, 2025
1 parent 31433e8 commit 4e6d4fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ void EditorPropertyArray::update_property() {
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element"));
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element));
button_add_item->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyArray::_button_add_item_draw));
SET_DRAG_FORWARDING_CD(button_add_item, EditorPropertyArray);
button_add_item->set_disabled(is_read_only());
vbox->add_child(button_add_item);

Expand Down Expand Up @@ -552,6 +554,13 @@ void EditorPropertyArray::_button_draw() {
}
}

void EditorPropertyArray::_button_add_item_draw() {
if (button_add_item && dropping) {
Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
button_add_item->draw_rect(Rect2(Point2(), button_add_item->get_size()), color, false);
}
}

bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
if (is_read_only()) {
return false;
Expand Down Expand Up @@ -767,6 +776,9 @@ void EditorPropertyArray::_notification(int p_what) {
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
dropping = true;
edit->queue_redraw();
if (button_add_item) {
button_add_item->queue_redraw();
}
}
}
} break;
Expand All @@ -775,6 +787,9 @@ void EditorPropertyArray::_notification(int p_what) {
if (dropping) {
dropping = false;
edit->queue_redraw();
if (button_add_item) {
button_add_item->queue_redraw();
}
}
} break;
}
Expand Down
1 change: 1 addition & 0 deletions editor/editor_properties_array_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class EditorPropertyArray : public EditorProperty {
virtual void _remove_pressed(int p_index);

virtual void _button_draw();
virtual void _button_add_item_draw();
virtual bool _is_drop_valid(const Dictionary &p_drag_data) const;
virtual bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
virtual void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
Expand Down

0 comments on commit 4e6d4fc

Please sign in to comment.