drag and drop basics

This commit is contained in:
Erica Z 2024-10-19 13:55:25 +02:00
parent ba1a5f3f39
commit 8966c5fff4
2 changed files with 26 additions and 1 deletions

View file

@ -10,6 +10,16 @@ class Ui.PlayQueueSong : Gtk.ListBoxRow {
[GtkCallback] private string star_button_icon_name (DateTime? starred) {
return starred == null ? "non-starred" : "starred";
}
[GtkCallback] private Gdk.ContentProvider? on_drag_prepare (double x, double y) {
return new Gdk.ContentProvider.for_value (this);
}
[GtkCallback] private bool on_drop (Value value, double x, double y) {
var source = value as PlayQueueSong;
print ("dropped %u on %u", source.position, this.position);
return false;
}
}
[GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue.ui")]

View file

@ -8,7 +8,7 @@ template $UiPlayQueueSong: ListBoxRow {
spacing: 6;
Image {
visible: false;
//visible: false;
icon-name: "list-drag-handle";
styles [ "drag-handle" ]
}
@ -113,6 +113,21 @@ template $UiPlayQueueSong: ListBoxRow {
styles [ "flat" ]
}
}
DragSource {
actions: move;
propagation-phase: capture;
prepare => $on_drag_prepare ();
}
DropTarget {
actions: move;
formats: UiPlayQueueSong;
preload: true;
drop => $on_drop ();
}
}
SizeGroup {