From 7afae36b0d39b80c28d61c38952c1770fee1495c Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sat, 11 Mar 2023 21:35:57 -0500 Subject: [PATCH] Figure out the selected terrain from the palette --- hex-grid/src/main.rs | 14 ++++++++------ hex-grid/src/palette_entry.rs | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hex-grid/src/main.rs b/hex-grid/src/main.rs index 61f0b54..111150b 100644 --- a/hex-grid/src/main.rs +++ b/hex-grid/src/main.rs @@ -44,7 +44,7 @@ fn main() { pub struct HexGridWindowPrivate { layout: gtk::Box, - palette: gtk::Box, + palette: gtk::ListBox, drawing_area: DrawingArea, hex_address: labeled_field::LabeledField, @@ -95,11 +95,7 @@ impl ObjectSubclass for HexGridWindowPrivate { let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----"); let hex_address = labeled_field::LabeledField::new("Hex Address", "-----"); - let palette = gtk::Box::builder() - .spacing(8) - .orientation(gtk::Orientation::Vertical) - .hexpand(true) - .build(); + let palette = gtk::ListBox::builder().hexpand(true).build(); sidebar.append(&canvas_address); sidebar.append(&hex_address); @@ -169,6 +165,12 @@ impl ObjectImpl for HexGridWindowPrivate { self.palette .append(&palette_entry::PaletteEntry::new(&swamp)); + self.palette.connect_selected_rows_changed(|palette| { + let row: Option = + palette.selected_row().and_then(|r| r.downcast().ok()); + println!("selected rows changed to: {:?}", row.map(|r| r.terrain())); + }); + let motion_controller = gtk::EventControllerMotion::new(); { let canvas_address = self.canvas_address.clone(); diff --git a/hex-grid/src/palette_entry.rs b/hex-grid/src/palette_entry.rs index 6942202..e9d7dd1 100644 --- a/hex-grid/src/palette_entry.rs +++ b/hex-grid/src/palette_entry.rs @@ -49,4 +49,8 @@ impl PaletteEntry { row } + + pub fn terrain(&self) -> tile::Terrain { + self.imp().terrain.borrow().clone() + } }