working on drag-n-drop
This commit is contained in:
53
src/grid.rs
53
src/grid.rs
@@ -17,7 +17,8 @@ impl Grid {
|
|||||||
let cell = grid::Cell::new(
|
let cell = grid::Cell::new(
|
||||||
CellPosition(x,y)
|
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);
|
inner.attach(cell.as_ref(), x, y, 1, 1);
|
||||||
}
|
}
|
||||||
Grid { inner }
|
Grid { inner }
|
||||||
@@ -37,30 +38,13 @@ impl CellWidget {
|
|||||||
let cell_src = include_str!("../res/cell.glade");
|
let cell_src = include_str!("../res/cell.glade");
|
||||||
let builder = gtk::Builder::new_from_string(&cell_src);
|
let builder = gtk::Builder::new_from_string(&cell_src);
|
||||||
|
|
||||||
|
// Set up reactivity on buttons
|
||||||
let eventbox: gtk::EventBox =
|
let eventbox: gtk::EventBox =
|
||||||
builder
|
builder
|
||||||
.get_object("cell")
|
.get_object("cell")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
eventbox.set_events(gdk::EventMask::BUTTON_PRESS_MASK);
|
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 =
|
let header: gtk::Label =
|
||||||
builder
|
builder
|
||||||
.get_object("header")
|
.get_object("header")
|
||||||
@@ -95,6 +79,33 @@ impl CellWidget {
|
|||||||
gtk::Inhibit(true)
|
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<gtk::EventBox> for CellWidget {
|
impl AsRef<gtk::EventBox> for CellWidget {
|
||||||
@@ -116,10 +127,6 @@ impl Cell {
|
|||||||
position
|
position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect_clicked(&self, state: AppState) {
|
|
||||||
self.inner.connect_clicked(state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<gtk::EventBox> for Cell {
|
impl AsRef<gtk::EventBox> for Cell {
|
||||||
|
|||||||
Reference in New Issue
Block a user