refactors cell content updating
This commit is contained in:
52
src/grid.rs
52
src/grid.rs
@@ -18,7 +18,6 @@ impl Grid {
|
||||
CellPosition(x,y)
|
||||
);
|
||||
cell.inner.connect_clicked(app_state.clone());
|
||||
cell.inner.desc_btn.set_visible(false);
|
||||
inner.attach(cell.as_ref(), x, y, 1, 1);
|
||||
}
|
||||
Grid { inner }
|
||||
@@ -86,8 +85,7 @@ impl CellWidget {
|
||||
eventbox.connect_drag_data_delete(
|
||||
move |w,drag| {
|
||||
println!("Cleaning... {:#?}", (&drag.drag_drop_succeeded()));
|
||||
h.set_text("");
|
||||
b.set_visible(false);
|
||||
Self::set_content((&h,&b), None);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -100,24 +98,20 @@ impl CellWidget {
|
||||
let h = header.clone();
|
||||
let b = desc_btn.clone();
|
||||
eventbox.connect_drag_data_received(
|
||||
move |_,drag,_,_,data,info,time| {
|
||||
let del =
|
||||
// Check if cell is not already occupied
|
||||
if !(h.get_text().unwrap().as_str() == "") {
|
||||
// TODO: Find what to do to abort, since
|
||||
// DragContext methods don't seem to work...
|
||||
println!("Overriding !!");
|
||||
false
|
||||
move |w,_,_,_,data,_,_| {
|
||||
// Check if cell is not already occupied
|
||||
if !(h.get_text().unwrap().as_str() == "") {
|
||||
// TODO: Find what to do to abort, since
|
||||
// DragContext methods don't seem to work...
|
||||
println!("Overriding !!");
|
||||
} else {
|
||||
println!("Dropped !");
|
||||
if let Some(text) = data.get_text() {
|
||||
Self::set_content((&h,&b), Some(text.as_str()));
|
||||
} else {
|
||||
println!("Dropped !");
|
||||
if let Some(text) = data.get_text() {
|
||||
h.set_text(&text);
|
||||
b.set_visible(true);
|
||||
} else {
|
||||
eprintln!("No data !");
|
||||
}
|
||||
true
|
||||
};
|
||||
eprintln!("No data !");
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
let cell = CellWidget {
|
||||
@@ -129,14 +123,28 @@ impl CellWidget {
|
||||
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) {
|
||||
let header = self.header.clone();
|
||||
let btn = self.desc_btn.clone();
|
||||
self.eventbox
|
||||
.connect_button_press_event(move |_,_| {
|
||||
let mut state = state.borrow_mut();
|
||||
if let Some(data) = state.pending.take() {
|
||||
if let Some(ref data) = state.pending.take() {
|
||||
println!("{:?}", data);
|
||||
header.set_text(&data.name);
|
||||
Self::set_content((&header,&btn), Some(&data.name));
|
||||
};
|
||||
gtk::Inhibit(true)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user