From b2d372f8a785cf51ba6737392fc5503be34c4d54 Mon Sep 17 00:00:00 2001 From: Artus Date: Fri, 7 Jun 2019 16:27:52 +0200 Subject: [PATCH] improves ui, cleans up a little --- res/cell.glade | 12 +++++++--- res/main.glade | 60 +++++++++++++++++++++++++++++++++++++------------- res/pawn.glade | 28 ++++++++++++++++++----- src/grid.rs | 49 ++++++++++++++++++----------------------- 4 files changed, 97 insertions(+), 52 deletions(-) diff --git a/res/cell.glade b/res/cell.glade index d3e5d33..05c649a 100644 --- a/res/cell.glade +++ b/res/cell.glade @@ -27,11 +27,11 @@ vertical True - + True False GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON2_MOTION_MASK | GDK_BUTTON3_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK | GDK_STRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK | GDK_VISIBILITY_NOTIFY_MASK | GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_SUBSTRUCTURE_MASK | GDK_SCROLL_MASK | GDK_TOUCH_MASK | GDK_SMOOTH_SCROLL_MASK | GDK_TOUCHPAD_GESTURE_MASK | GDK_TABLET_PAD_MASK - Cell + Name right @@ -53,10 +53,16 @@ end 5 5 + none none desc_sheet - + + True + False + accessories-dictionary-symbolic + 3 + diff --git a/res/main.glade b/res/main.glade index 9ddc8a3..bd14bfe 100644 --- a/res/main.glade +++ b/res/main.glade @@ -16,30 +16,55 @@ False Play Mat version 0.1 - 0 + 10 True - + True - True - True - start - start - app.panel_switch - show_list_img - True - True + False + expand + + + True + True + True + app.panel_switch + show_list_img + True + True + + + True + True + 0 + + + + + True + True + True + add_pawn_img + True + + + True + True + 1 + + - + True True True - start - center - add_pawn_img + image1 True + 1 @@ -51,7 +76,7 @@ True True - 80 + 160 True @@ -135,6 +160,11 @@ + + True + False + preferences-system-symbolic + True False diff --git a/res/pawn.glade b/res/pawn.glade index b945130..91a0ff7 100644 --- a/res/pawn.glade +++ b/res/pawn.glade @@ -2,15 +2,26 @@ + + True + False + send-to-symbolic + + + True + False + accessories-calculator-symbolic + True False + 10 + True True False 10 - True Name @@ -24,16 +35,19 @@ True False end - 8 - 3 - start + center + 5 + True + expand - Place True True True + end + image1 half + True False @@ -43,11 +57,13 @@ - Stats True True True + end + image2 half + True True diff --git a/src/grid.rs b/src/grid.rs index 6c21f50..d7d3cb9 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -33,7 +33,7 @@ struct Cell { impl Cell { fn new(position: CellPosition) -> Self { Cell { - inner: CellWidget::new(position, ""), + inner: CellWidget::new(position), position, } } @@ -47,6 +47,7 @@ impl AsRef for Cell { } + /// The cell widget is either empty or has a pawn /// Pawn can be moved around cells using drag-n-drop. However, due to my inability /// to dynamically change the behavior with set/unset methods, all cells are always @@ -57,41 +58,33 @@ impl AsRef for Cell { struct CellWidget { eventbox: gtk::EventBox, position: gtk::Label, - header: gtk::Label, + name: gtk::Label, desc_btn: gtk::Button, + targets: Vec, } impl CellWidget { - fn new(pos: CellPosition, header_text: &str) -> Self { + fn new(pos: CellPosition) -> Self { let cell_src = include_str!("../res/cell.glade"); let builder = gtk::Builder::new_from_string(cell_src); // Retrieve children - let eventbox: gtk::EventBox = builder.get_object("cell").unwrap(); - let header: gtk::Label = builder.get_object("header").unwrap(); - header.set_text(header_text); - let position: gtk::Label = builder.get_object("position").unwrap(); - position.set_text(&format!("{}x{}", pos.0, pos.1)); - let desc_btn: gtk::Button = builder.get_object("desc_btn").unwrap(); - desc_btn.set_visible(false); let cell = CellWidget { - eventbox, - position, - header, - desc_btn, + eventbox: builder.get_object("cell").unwrap(), + position: builder.get_object("position").unwrap(), + name: builder.get_object("name").unwrap(), + desc_btn: builder.get_object("desc_btn").unwrap(), + targets: vec![ + gtk::TargetEntry::new("text/plain", gtk::TargetFlags::SAME_APP, 0), + ], }; - Self::set_content(&cell, None); + cell.desc_btn.set_visible(false); + cell.position.set_text(&format!("{}x{}", pos.0, pos.1)); cell.set_drag(); cell.set_drop(); + Self::set_content(&cell, None); cell } - // The data to be sent - fn targets() -> Vec { - vec![ - gtk::TargetEntry::new("text/plain", gtk::TargetFlags::SAME_APP, 0) - ] - } - fn unset_drag(&self) { dbg!("Unset drag"); self.eventbox.drag_source_unset(); } fn set_drag(&self) { @@ -99,7 +92,7 @@ impl CellWidget { // Acting as source self.eventbox.drag_source_set( gdk::ModifierType::MODIFIER_MASK, - &Self::targets(), + &self.targets, gdk::DragAction::MOVE, ); let c = self.clone(); @@ -109,7 +102,7 @@ impl CellWidget { println!("Send..."); // TODO: Refactoring, this is the inverse of 'placing', // building a PawnData instead of destructuring it. - if let Some(to_send) = c.header.get_text() { + if let Some(to_send) = c.name.get_text() { data.set_text(&to_send); } else { dbg!("Should not happen !!"); @@ -130,7 +123,7 @@ impl CellWidget { // Acting as destination self.eventbox.drag_dest_set( gtk::DestDefaults::ALL, - &Self::targets(), + &self.targets, gdk::DragAction::MOVE, ); // Retrieve data from the source @@ -138,7 +131,7 @@ impl CellWidget { self.eventbox .connect_drag_data_received(move |w, _, _, _, data, _, _| { // Check if cell is not already occupied - if !(c.header.get_text().unwrap().as_str() == "") { + if !(c.name.get_text().unwrap().as_str() == "") { // TODO: Find what to do to abort, since // DragContext methods don't seem to work... println!("Overriding !!"); @@ -158,10 +151,10 @@ impl CellWidget { println!("Set content to {:?}", &data); // TODO: there is surely something cleaner... if let Some(name) = data { - self.header.set_text(name); + self.name.set_text(name); self.desc_btn.set_visible(true); } else { - self.header.set_text(""); + self.name.set_text(""); self.desc_btn.set_visible(false); }; }