From ad9cad533f34c21d799d1f28dee03e7cb54a4653 Mon Sep 17 00:00:00 2001 From: Artus Date: Wed, 5 Jun 2019 16:35:45 +0200 Subject: [PATCH] working on drag-n-drop --- src/grid.rs | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index 85b781c..6e86a90 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -17,7 +17,8 @@ impl Grid { let cell = grid::Cell::new( CellPosition(x,y) ); - cell.connect_clicked(app_state.clone()); + cell.inner.connect_clicked(app_state.clone()); + cell.inner.connect_drag_drop(app_state.clone()); inner.attach(cell.as_ref(), x, y, 1, 1); } Grid { inner } @@ -37,30 +38,13 @@ impl CellWidget { let cell_src = include_str!("../res/cell.glade"); let builder = gtk::Builder::new_from_string(&cell_src); + // Set up reactivity on buttons let eventbox: gtk::EventBox = builder .get_object("cell") .unwrap(); eventbox.set_events(gdk::EventMask::BUTTON_PRESS_MASK); - // Drag-and-drop capacity - let targets = vec![]; - eventbox.drag_dest_set( - gtk::DestDefaults::ALL, - &targets, - gdk::DragAction::COPY, - ); - eventbox.drag_source_set( - gdk::ModifierType::MODIFIER_MASK, - &targets, - gdk::DragAction::COPY, - ); - eventbox.connect_drag_begin(|_,_| { - println!("Lift..."); - }); - eventbox.connect_drag_end(|_,_| { - println!("Drop !"); - }); let header: gtk::Label = builder .get_object("header") @@ -95,6 +79,33 @@ impl CellWidget { gtk::Inhibit(true) }); } + + pub fn connect_drag_drop(&self, _state: AppState) { + // Drag-and-drop capacity + let targets = vec![]; + self.eventbox.drag_dest_set( + gtk::DestDefaults::ALL, + &targets, + gdk::DragAction::COPY, + ); + self.eventbox.drag_source_set( + gdk::ModifierType::MODIFIER_MASK, + &targets, + gdk::DragAction::COPY, + ); + + //let app_state = state.clone(); + self.eventbox.connect_drag_begin(|_,_| { + println!("Lift..."); + // Copy the current instance data + // inside app_state.pending + }); + self.eventbox.connect_drag_end(|_,_| { + println!("Drop !"); + // Same as clicked, grab data + }); + // TODO: Add failed signal to remove data + } } impl AsRef for CellWidget { @@ -116,10 +127,6 @@ impl Cell { position } } - - fn connect_clicked(&self, state: AppState) { - self.inner.connect_clicked(state); - } } impl AsRef for Cell {