refactors cell content updating
This commit is contained in:
30
src/grid.rs
30
src/grid.rs
@@ -18,7 +18,6 @@ impl Grid {
|
|||||||
CellPosition(x,y)
|
CellPosition(x,y)
|
||||||
);
|
);
|
||||||
cell.inner.connect_clicked(app_state.clone());
|
cell.inner.connect_clicked(app_state.clone());
|
||||||
cell.inner.desc_btn.set_visible(false);
|
|
||||||
inner.attach(cell.as_ref(), x, y, 1, 1);
|
inner.attach(cell.as_ref(), x, y, 1, 1);
|
||||||
}
|
}
|
||||||
Grid { inner }
|
Grid { inner }
|
||||||
@@ -86,8 +85,7 @@ impl CellWidget {
|
|||||||
eventbox.connect_drag_data_delete(
|
eventbox.connect_drag_data_delete(
|
||||||
move |w,drag| {
|
move |w,drag| {
|
||||||
println!("Cleaning... {:#?}", (&drag.drag_drop_succeeded()));
|
println!("Cleaning... {:#?}", (&drag.drag_drop_succeeded()));
|
||||||
h.set_text("");
|
Self::set_content((&h,&b), None);
|
||||||
b.set_visible(false);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -100,23 +98,19 @@ impl CellWidget {
|
|||||||
let h = header.clone();
|
let h = header.clone();
|
||||||
let b = desc_btn.clone();
|
let b = desc_btn.clone();
|
||||||
eventbox.connect_drag_data_received(
|
eventbox.connect_drag_data_received(
|
||||||
move |_,drag,_,_,data,info,time| {
|
move |w,_,_,_,data,_,_| {
|
||||||
let del =
|
|
||||||
// Check if cell is not already occupied
|
// Check if cell is not already occupied
|
||||||
if !(h.get_text().unwrap().as_str() == "") {
|
if !(h.get_text().unwrap().as_str() == "") {
|
||||||
// TODO: Find what to do to abort, since
|
// TODO: Find what to do to abort, since
|
||||||
// DragContext methods don't seem to work...
|
// DragContext methods don't seem to work...
|
||||||
println!("Overriding !!");
|
println!("Overriding !!");
|
||||||
false
|
|
||||||
} else {
|
} else {
|
||||||
println!("Dropped !");
|
println!("Dropped !");
|
||||||
if let Some(text) = data.get_text() {
|
if let Some(text) = data.get_text() {
|
||||||
h.set_text(&text);
|
Self::set_content((&h,&b), Some(text.as_str()));
|
||||||
b.set_visible(true);
|
|
||||||
} else {
|
} else {
|
||||||
eprintln!("No data !");
|
eprintln!("No data !");
|
||||||
}
|
}
|
||||||
true
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -129,14 +123,28 @@ impl CellWidget {
|
|||||||
cell
|
cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates content of the Cell
|
||||||
|
fn set_content(widgets: (>k::Label, >k::Button), data: Option<&str>) {
|
||||||
|
println!("Set content to {:?}", &data);
|
||||||
|
// TODO: there is surely something cleaner...
|
||||||
|
if let Some(name) = data {
|
||||||
|
widgets.0.set_text(name);
|
||||||
|
widgets.1.set_visible(true);
|
||||||
|
} else {
|
||||||
|
widgets.0.set_text("");
|
||||||
|
widgets.1.set_visible(false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn connect_clicked(&self, state: AppState) {
|
pub fn connect_clicked(&self, state: AppState) {
|
||||||
let header = self.header.clone();
|
let header = self.header.clone();
|
||||||
|
let btn = self.desc_btn.clone();
|
||||||
self.eventbox
|
self.eventbox
|
||||||
.connect_button_press_event(move |_,_| {
|
.connect_button_press_event(move |_,_| {
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
if let Some(data) = state.pending.take() {
|
if let Some(ref data) = state.pending.take() {
|
||||||
println!("{:?}", data);
|
println!("{:?}", data);
|
||||||
header.set_text(&data.name);
|
Self::set_content((&header,&btn), Some(&data.name));
|
||||||
};
|
};
|
||||||
gtk::Inhibit(true)
|
gtk::Inhibit(true)
|
||||||
});
|
});
|
||||||
|
|||||||
23
src/main.rs
23
src/main.rs
@@ -68,7 +68,6 @@ impl App {
|
|||||||
.get_object("app")
|
.get_object("app")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
win.set_application(app);
|
win.set_application(app);
|
||||||
|
|
||||||
// Set up a simple switch for the Pawn list panel
|
// Set up a simple switch for the Pawn list panel
|
||||||
let panel: gtk::Paned = builder.get_object("panel").unwrap();
|
let panel: gtk::Paned = builder.get_object("panel").unwrap();
|
||||||
Self::new_action(app, "panel_switch", move |_,_| {
|
Self::new_action(app, "panel_switch", move |_,_| {
|
||||||
@@ -78,18 +77,7 @@ impl App {
|
|||||||
panel.set_position(0);
|
panel.set_position(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// Pawn list
|
||||||
// Initialize grid
|
|
||||||
let grid: gtk::Grid = builder.get_object("map").unwrap();
|
|
||||||
// TODO: implement drag-drop events
|
|
||||||
// * From pawn_list to cell : place pawn on dest cell
|
|
||||||
// * From cell to cell : move pawn from source to dest cell
|
|
||||||
let _grid = grid::Grid::init(grid, 10, app_state.clone());
|
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// * Display creature description when hovering over its position (cell)
|
|
||||||
|
|
||||||
// TODO: Pawn list
|
|
||||||
let pawn_list = builder.get_object("pawn_list").unwrap();
|
let pawn_list = builder.get_object("pawn_list").unwrap();
|
||||||
let pawn_list = pawn::PawnList::init(pawn_list);
|
let pawn_list = pawn::PawnList::init(pawn_list);
|
||||||
|
|
||||||
@@ -99,7 +87,14 @@ impl App {
|
|||||||
pawn.connect_stats();
|
pawn.connect_stats();
|
||||||
app_state.borrow_mut().pawns.push(pawn);
|
app_state.borrow_mut().pawns.push(pawn);
|
||||||
}
|
}
|
||||||
win.show_all();
|
win.show_all(); // Before grid because we want to hide some widgets there
|
||||||
|
// Initialize grid
|
||||||
|
let grid: gtk::Grid = builder.get_object("map").unwrap();
|
||||||
|
// TODO: implement drag-drop events
|
||||||
|
// * From pawn_list to cell : place pawn on dest cell
|
||||||
|
// * From cell to cell : move pawn from source to dest cell
|
||||||
|
let _grid = grid::Grid::init(grid, 10, app_state.clone());
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user