From 85b80d78fffba48a852c91e5c69d51279bb3738e Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 19 Feb 2023 01:09:16 -0500 Subject: [PATCH] Start on the palette --- hex-grid/src/main.rs | 46 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/hex-grid/src/main.rs b/hex-grid/src/main.rs index 5a55e5a..7830765 100644 --- a/hex-grid/src/main.rs +++ b/hex-grid/src/main.rs @@ -28,13 +28,13 @@ const DRAWING_ORIGIN: (f64, f64) = (1024. / 2., 768. / 2.); #[derive(Clone, Debug)] enum Terrain { - Empty, - Mountain, - Grasslands, - ShallowWater, - DeepWater, Badlands, + DeepWater, Desert, + Empty, + Grasslands, + Mountain, + ShallowWater, Swamp, } @@ -113,6 +113,7 @@ fn main() { #[derive(Default)] pub struct HexGridWindowPrivate { layout: gtk::Box, + palette: gtk::Box, drawing_area: DrawingArea, hex_address: Label, @@ -128,6 +129,7 @@ impl ObjectSubclass for HexGridWindowPrivate { type ParentType = gtk::ApplicationWindow; fn new() -> Self { + println!("hexGridWindowPrivate::new()"); let current_coordinate = Rc::new(RefCell::new(None)); let drawing_area = DrawingArea::builder() @@ -195,8 +197,15 @@ impl ObjectSubclass for HexGridWindowPrivate { hex_address_row.append(&hex_address); + let palette = gtk::Box::builder() + .spacing(8) + .orientation(gtk::Orientation::Vertical) + .hexpand(true) + .build(); + sidebar.append(&canvas_address_row); sidebar.append(&hex_address_row); + sidebar.append(&palette); layout.append(&drawing_area); layout.append(&sidebar); @@ -209,12 +218,14 @@ impl ObjectSubclass for HexGridWindowPrivate { canvas_address, current_coordinate, layout, + palette, } } } impl ObjectImpl for HexGridWindowPrivate { fn constructed(&self) { + println!("HexGridWindowPrivate::constructed()"); self.parent_constructed(); let map_text_resource = resources_lookup_data( @@ -236,14 +247,29 @@ impl ObjectImpl for HexGridWindowPrivate { .unwrap(); let image = reader.decode().unwrap(); - let deep_water = Tile::new(&image, Terrain::DeepWater); - let shallow_water = Tile::new(&image, Terrain::ShallowWater); - let grasslands = Tile::new(&image, Terrain::Grasslands); - let desert = Tile::new(&image, Terrain::Desert); - let mountain = Tile::new(&image, Terrain::Mountain); let badlands = Tile::new(&image, Terrain::Badlands); + let deep_water = Tile::new(&image, Terrain::DeepWater); + let desert = Tile::new(&image, Terrain::Desert); + let grasslands = Tile::new(&image, Terrain::Grasslands); + let mountain = Tile::new(&image, Terrain::Mountain); + let shallow_water = Tile::new(&image, Terrain::ShallowWater); let swamp = Tile::new(&image, Terrain::Swamp); + let badlands_image = gtk::Image::from_pixbuf(Some(&badlands.image)); + self.palette.append(&badlands_image); + self.palette + .append(>k::Image::from_pixbuf(Some(&deep_water.image))); + self.palette + .append(>k::Image::from_pixbuf(Some(&desert.image))); + self.palette + .append(>k::Image::from_pixbuf(Some(&grasslands.image))); + self.palette + .append(>k::Image::from_pixbuf(Some(&mountain.image))); + self.palette + .append(>k::Image::from_pixbuf(Some(&shallow_water.image))); + self.palette + .append(>k::Image::from_pixbuf(Some(&swamp.image))); + let motion_controller = gtk::EventControllerMotion::new(); { let canvas_address = self.canvas_address.clone();