Figure out the selected terrain from the palette

This commit is contained in:
Savanni D'Gerinel 2023-03-11 21:35:57 -05:00
parent 1b61689de6
commit 7afae36b0d
2 changed files with 12 additions and 6 deletions

View File

@ -44,7 +44,7 @@ fn main() {
pub struct HexGridWindowPrivate { pub struct HexGridWindowPrivate {
layout: gtk::Box, layout: gtk::Box,
palette: gtk::Box, palette: gtk::ListBox,
drawing_area: DrawingArea, drawing_area: DrawingArea,
hex_address: labeled_field::LabeledField, hex_address: labeled_field::LabeledField,
@ -95,11 +95,7 @@ impl ObjectSubclass for HexGridWindowPrivate {
let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----"); let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----");
let hex_address = labeled_field::LabeledField::new("Hex Address", "-----"); let hex_address = labeled_field::LabeledField::new("Hex Address", "-----");
let palette = gtk::Box::builder() let palette = gtk::ListBox::builder().hexpand(true).build();
.spacing(8)
.orientation(gtk::Orientation::Vertical)
.hexpand(true)
.build();
sidebar.append(&canvas_address); sidebar.append(&canvas_address);
sidebar.append(&hex_address); sidebar.append(&hex_address);
@ -169,6 +165,12 @@ impl ObjectImpl for HexGridWindowPrivate {
self.palette self.palette
.append(&palette_entry::PaletteEntry::new(&swamp)); .append(&palette_entry::PaletteEntry::new(&swamp));
self.palette.connect_selected_rows_changed(|palette| {
let row: Option<palette_entry::PaletteEntry> =
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 motion_controller = gtk::EventControllerMotion::new();
{ {
let canvas_address = self.canvas_address.clone(); let canvas_address = self.canvas_address.clone();

View File

@ -49,4 +49,8 @@ impl PaletteEntry {
row row
} }
pub fn terrain(&self) -> tile::Terrain {
self.imp().terrain.borrow().clone()
}
} }