Skip to content

Commit

Permalink
Add a status bar to the map on the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
seilis committed Jan 15, 2025
1 parent 53bad7e commit 7f92b68
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/bin/rpgmap-gui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Program for making simple RPG maps. This is the Rust language implementation.
use clap::{command, value_parser, Arg};
use egui;

use rpgtools::error::Result;
use rpgtools::map::gridmap::AreaType;
Expand Down Expand Up @@ -198,6 +197,8 @@ impl eframe::App for RpgMapGui {
}
});

let mut cursor_pos: Option<(usize, usize)> = None;

egui::CentralPanel::default().show(ctx, |ui| {
let cell_size = 20.0;

Expand Down Expand Up @@ -247,6 +248,11 @@ impl eframe::App for RpgMapGui {
egui::Stroke::new(1.0, egui::Color32::BLACK),
);

// Test if we're hovering over the cell
if cell.rect.contains(ctx.pointer_hover_pos().unwrap_or_default()) {
cursor_pos = Some((x, y));
}

// If the mouse main button is down then we may need to
// set a cell.
if self.dragging
Expand All @@ -269,5 +275,15 @@ impl eframe::App for RpgMapGui {
}
});
});

egui::TopBottomPanel::bottom("status").show(ctx, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if let Some((x, y)) = cursor_pos {
ui.label(format!("Cell: ({}, {})", x, y));
} else {
ui.label("Cell: (N/A)");
}
});
});
}
}

0 comments on commit 7f92b68

Please sign in to comment.