summaryrefslogtreecommitdiff
path: root/src/renderer/ui.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-23 14:33:23 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-23 14:33:23 -0700
commitda45c5a7dbb017c8e579d0ab66a2259a70b28f40 (patch)
tree938c0be6bd6b938cb8788456ce759b784ee74f5c /src/renderer/ui.rs
parentc4c26f03e3eb18a76f9c2756076030dc52a667fa (diff)
input manager
Diffstat (limited to 'src/renderer/ui.rs')
-rw-r--r--src/renderer/ui.rs81
1 files changed, 44 insertions, 37 deletions
diff --git a/src/renderer/ui.rs b/src/renderer/ui.rs
index a7395a0..46fb853 100644
--- a/src/renderer/ui.rs
+++ b/src/renderer/ui.rs
@@ -1,8 +1,9 @@
use egui::{Color32, Stroke, Ui, epaint::CircleShape};
use crate::{
- Camera, Config, Diagnostics, Input,
+ Camera, Config, Diagnostics,
content::materials::MaterialId,
+ input::InputManager,
sim::{rb_manager::DebugRenderMode, sim_manager::SimManager},
};
@@ -20,7 +21,7 @@ pub fn draw_egui<'a>(
config: &mut Config,
camera: &mut Camera,
diagnostics: &Diagnostics,
- input: &Input,
+ input_manager: &InputManager,
sim: &SimManager,
) {
puffin::profile_function!();
@@ -104,44 +105,50 @@ pub fn draw_egui<'a>(
ui.add(egui::Slider::new(&mut camera.zoom, 0.0..=10.0).text("Zoom"));
ui.heading("Input");
- input
- .last_mouse_world_pos
- .map(|p| ui.label(format!("Mouse (world): x,y=({x}, {y})", x = p.0, y = p.1,)));
+ ui.label(format!(
+ "Mouse (world): x,y=({x}, {y})",
+ x = input_manager.world_mouse_pos.x,
+ y = input_manager.world_mouse_pos.y
+ ));
- if let Some(p) = input.last_mouse_chunk_pos {
- ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,));
- if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&p) {
- ui.label(format!(
- "Sleeping={}",
- sim.cell_manager.chunks[chunk].sleeping
- ));
- }
+ ui.label(format!(
+ "Mouse (chunk): x,y=({x}, {y})",
+ x = input_manager.chunk_mouse_pos.x,
+ y = input_manager.chunk_mouse_pos.y
+ ));
+
+ if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&(
+ input_manager.chunk_mouse_pos.x,
+ input_manager.chunk_mouse_pos.y,
+ )) {
+ ui.label(format!(
+ "Sleeping={}",
+ sim.cell_manager.chunks[chunk].sleeping
+ ));
}
- input
- .last_mouse_local_pos
- .map(|p| ui.label(format!("Mouse (local): x,y=({x}, {y})", x = p.0, y = p.1,)));
+ ui.label(format!(
+ "Mouse (local): x,y=({x}, {y})",
+ x = input_manager.local_mouse_pos.x,
+ y = input_manager.local_mouse_pos.y
+ ));
- if let Some((x, y)) = input.last_mouse_world_pos {
- ui.heading("Entity");
- if let Some(cell) = sim
- .cell_manager
- .get_cell_from_game_position(x.round() as i32, y.round() as i32)
- {
- let material = cell.material.def();
- let cell_label = ui.label(
- egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),
- );
- ui.painter().add(egui::Shape::Circle(CircleShape {
- center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0),
- radius: cell_label.rect.height() / 2.5,
- stroke: Stroke::NONE,
- fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
- }));
- ui.label(
- egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW),
- );
- ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED));
- }
+ ui.heading("Entity");
+ if let Some(cell) = sim.cell_manager.get_cell_from_game_position(
+ input_manager.world_mouse_pos.x.round() as i32,
+ input_manager.world_mouse_pos.y.round() as i32,
+ ) {
+ let material = cell.material.def();
+ let cell_label = ui.label(
+ egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE),
+ );
+ ui.painter().add(egui::Shape::Circle(CircleShape {
+ center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0),
+ radius: cell_label.rect.height() / 2.5,
+ stroke: Stroke::NONE,
+ fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2),
+ }));
+ ui.label(egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW));
+ ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED));
}
}