pits and exits
This commit is contained in:
@@ -72,10 +72,40 @@
|
|||||||
<property name="hexpand">True</property>
|
<property name="hexpand">True</property>
|
||||||
<property name="vexpand">True</property>
|
<property name="vexpand">True</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<object class="GtkEventBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<signal name="drag-begin" handler="drag_begin" swapped="no"/>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">label</property>
|
||||||
|
<signal name="drag-begin" handler="drag_begin" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<object class="GtkEventBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">label</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">1</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
|
|||||||
67
src/grid.rs
67
src/grid.rs
@@ -18,7 +18,7 @@ impl Grid {
|
|||||||
CellPosition(x,y)
|
CellPosition(x,y)
|
||||||
);
|
);
|
||||||
cell.inner.connect_clicked(app_state.clone());
|
cell.inner.connect_clicked(app_state.clone());
|
||||||
cell.inner.connect_drag_drop(app_state.clone());
|
cell.inner.connect_dragging(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 }
|
||||||
@@ -43,7 +43,6 @@ impl CellWidget {
|
|||||||
builder
|
builder
|
||||||
.get_object("cell")
|
.get_object("cell")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
eventbox.set_events(gdk::EventMask::BUTTON_PRESS_MASK);
|
|
||||||
|
|
||||||
let header: gtk::Label =
|
let header: gtk::Label =
|
||||||
builder
|
builder
|
||||||
@@ -55,6 +54,19 @@ impl CellWidget {
|
|||||||
.get_object("position")
|
.get_object("position")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
position.set_text(&format!("{}x{}", pos.0, pos.1));
|
position.set_text(&format!("{}x{}", pos.0, pos.1));
|
||||||
|
// Drag-and-drop capacity
|
||||||
|
let targets = vec![];
|
||||||
|
eventbox.drag_source_set(
|
||||||
|
gdk::ModifierType::MODIFIER_MASK,
|
||||||
|
&targets,
|
||||||
|
gdk::DragAction::COPY,
|
||||||
|
);
|
||||||
|
eventbox.drag_dest_set(
|
||||||
|
gtk::DestDefaults::ALL,
|
||||||
|
&targets,
|
||||||
|
gdk::DragAction::COPY,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
let cell = CellWidget {
|
let cell = CellWidget {
|
||||||
eventbox,
|
eventbox,
|
||||||
@@ -80,32 +92,47 @@ impl CellWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn connect_drag_drop(&self, _state: AppState) {
|
pub fn connect_dragging(&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();
|
// TODO: start over.
|
||||||
self.eventbox.connect_drag_begin(|_,_| {
|
// Use this for reference :
|
||||||
|
// https://python-gtk-3-tutorial.readthedocs.io/en/latest/drag_and_drop.html
|
||||||
|
|
||||||
|
// For starters, avoid using app_state and just copy the content of
|
||||||
|
// source cell inside dest cell.
|
||||||
|
|
||||||
|
let state1 = state.clone();
|
||||||
|
self.eventbox.connect_drag_begin(move |_,_| {
|
||||||
println!("Lift...");
|
println!("Lift...");
|
||||||
|
let mut state = state1.borrow_mut();
|
||||||
|
state.pending = Some(pawn::PawnData{name: "Dropped".to_string(), position: None});
|
||||||
// Copy the current instance data
|
// Copy the current instance data
|
||||||
// inside app_state.pending
|
// inside app_state.pending
|
||||||
});
|
});
|
||||||
self.eventbox.connect_drag_end(|_,_| {
|
// TODO: Add failed signal to remove data
|
||||||
|
let state2 = state.clone();
|
||||||
|
let content = self.content.clone();
|
||||||
|
self.eventbox.connect_drag_end(move |_,_| {
|
||||||
println!("Drop !");
|
println!("Drop !");
|
||||||
|
let mut state = state2.borrow_mut();
|
||||||
|
if state.pending.is_none() {
|
||||||
|
content.set_text("Emptied");
|
||||||
|
}
|
||||||
|
state.pending = None;
|
||||||
// Same as clicked, grab data
|
// Same as clicked, grab data
|
||||||
});
|
});
|
||||||
// TODO: Add failed signal to remove data
|
let state3 = state.clone();
|
||||||
}
|
let content = self.content.clone();
|
||||||
|
self.eventbox.connect_drag_drop(move |_,drag_ctx,_,_,time| {
|
||||||
|
println!("Got ! {:?}", "");
|
||||||
|
let mut state = state3.borrow_mut();
|
||||||
|
if let Some(data) = state.pending.take() {
|
||||||
|
content.set_text(&data.name);
|
||||||
|
};
|
||||||
|
drag_ctx.drag_finish(true, true, time);
|
||||||
|
gtk::Inhibit(true)
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<gtk::EventBox> for CellWidget {
|
impl AsRef<gtk::EventBox> for CellWidget {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
/// A wrapper around gtk::ListBox for Pawns
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
pub struct PawnList {
|
pub struct PawnList {
|
||||||
inner: gtk::ListBox,
|
inner: gtk::ListBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PawnList {
|
impl PawnList {
|
||||||
|
/// Initialize from the given existing ListBox
|
||||||
pub fn init(inner: gtk::ListBox) -> Self {
|
pub fn init(inner: gtk::ListBox) -> Self {
|
||||||
PawnList{ inner }
|
PawnList{ inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds a Pawn to the list
|
||||||
pub fn add(&self, pawn: &Pawn) {
|
pub fn add(&self, pawn: &Pawn) {
|
||||||
let row = gtk::ListBoxRow::new();
|
let row = gtk::ListBoxRow::new();
|
||||||
row.add(pawn.as_ref());
|
row.add(pawn.as_ref());
|
||||||
@@ -18,12 +21,14 @@ impl PawnList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Application data related to a Pawn
|
||||||
#[derive(Debug,Clone)]
|
#[derive(Debug,Clone)]
|
||||||
pub struct PawnData {
|
pub struct PawnData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub position: Option<String>, // Content of label from CellWidget
|
pub position: Option<String>, // Content of label from CellWidget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper widget for pawns.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Pawn {
|
pub struct Pawn {
|
||||||
data: PawnData,
|
data: PawnData,
|
||||||
|
|||||||
Reference in New Issue
Block a user