diff --git a/src/grid.rs b/src/grid.rs index eb1bf90..7e9e9e7 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -36,13 +36,11 @@ impl CellWidget { fn new(pos: CellPosition, header_text: &str) -> Self { let cell_src = include_str!("../res/cell.glade"); let builder = gtk::Builder::new_from_string(cell_src); - - // Set up reactivity on buttons + // Retrieve children let eventbox: gtk::EventBox = builder .get_object("cell") .unwrap(); - let header: gtk::Label = builder .get_object("header") @@ -53,34 +51,35 @@ impl CellWidget { .get_object("position") .unwrap(); position.set_text(&format!("{}x{}", pos.0, pos.1)); - - // Drag-and-drop capacity let desc_btn: gtk::Button = builder .get_object("desc_btn") .unwrap(); desc_btn.set_visible(false); - // The data to be send - let targets = vec![ - gtk::TargetEntry::new("text/plain", gtk::TargetFlags::SAME_APP, 0) - ]; - eventbox.drag_source_set( - gdk::ModifierType::MODIFIER_MASK, - &targets, - gdk::DragAction::MOVE, - ); let cell = CellWidget { eventbox, position, header, - desc_btn + desc_btn, }; - + // Drag-and-drop capacity + // The data to be sent + let targets = vec![ + gtk::TargetEntry::new("text/plain", gtk::TargetFlags::SAME_APP, 0) + ]; + // Acting as source + cell.eventbox.drag_source_set( + gdk::ModifierType::MODIFIER_MASK, + &targets, + gdk::DragAction::MOVE, + ); let h = cell.header.clone(); // Send data to the drop site cell.eventbox.connect_drag_data_get( move |_,_,data,info,time| { println!("Send..."); + // TODO: Refactoring, this is the inverse of 'placing', + // building a PawnData instead of destructuring it. if let Some(to_send) = h.get_text() { data.set_text(&to_send); } @@ -94,7 +93,7 @@ impl CellWidget { Self::set_content(&c, None); } ); - + // Acting as destination cell.eventbox.drag_dest_set( gtk::DestDefaults::ALL, &targets,