Figure out the selected terrain from the palette
This commit is contained in:
parent
1b61689de6
commit
7afae36b0d
|
@ -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_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 canvas_address = self.canvas_address.clone();
|
||||
|
|
|
@ -49,4 +49,8 @@ impl PaletteEntry {
|
|||
|
||||
row
|
||||
}
|
||||
|
||||
pub fn terrain(&self) -> tile::Terrain {
|
||||
self.imp().terrain.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue