adds pawn creation
This commit is contained in:
16
src/pawn.rs
16
src/pawn.rs
@@ -17,6 +17,7 @@ impl PawnList {
|
||||
let row = gtk::ListBoxRow::new();
|
||||
row.add(pawn.as_ref());
|
||||
self.inner.add(&row);
|
||||
self.inner.show_all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ impl PawnList {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PawnData {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub position: Option<String>, // Content of label from CellWidget
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ pub struct Pawn {
|
||||
}
|
||||
|
||||
impl Pawn {
|
||||
pub fn new<S: Into<String>>(name: S) -> Self {
|
||||
pub fn new<S: Into<String>>(name: S, description: S) -> Self {
|
||||
let pawn_src = include_str!("../res/pawn.glade");
|
||||
let builder = gtk::Builder::new_from_string(pawn_src);
|
||||
let name = name.into();
|
||||
@@ -47,6 +49,7 @@ impl Pawn {
|
||||
Pawn {
|
||||
data: PawnData {
|
||||
name,
|
||||
description: description.into(),
|
||||
position: None,
|
||||
},
|
||||
widget,
|
||||
@@ -55,13 +58,16 @@ impl Pawn {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_data(data: PawnData) -> Self {
|
||||
Self::new(data.name, data.description)
|
||||
}
|
||||
|
||||
pub fn connect_place(&self, state: AppState) {
|
||||
let name = self.data.name.clone();
|
||||
let data = self.data.clone();
|
||||
self.place_btn.connect_clicked(move |_| {
|
||||
println!("Placing {}...", name);
|
||||
println!("Placing {}...", &data.name);
|
||||
let mut state = state.0.borrow_mut();
|
||||
state.pending = Some(data.clone()); // ???
|
||||
let _ = state.pending.replace(data.clone()); // ???
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,7 +87,7 @@ impl AsRef<gtk::Box> for Pawn {
|
||||
pub fn pawn_factory() -> Vec<Pawn> {
|
||||
let mut pawns = Vec::with_capacity(3);
|
||||
for name in &["Lomion", "Oilosse", "Fefi"] {
|
||||
pawns.push(Pawn::new(*name));
|
||||
pawns.push(Pawn::new(*name, ""));
|
||||
}
|
||||
pawns
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user