diff --git a/src/bin/topola-egui/app.rs b/src/bin/topola-egui/app.rs index 30605a2..159622c 100644 --- a/src/bin/topola-egui/app.rs +++ b/src/bin/topola-egui/app.rs @@ -40,7 +40,10 @@ use topola::{ specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata}, }; -use crate::{layers::Layers, overlay::Overlay, painter::Painter, top::Top, viewport::Viewport}; +use crate::{ + bottom::Bottom, layers::Layers, overlay::Overlay, painter::Painter, top::Top, + viewport::Viewport, +}; #[derive(Debug, Default)] pub struct SharedData { @@ -74,6 +77,9 @@ pub struct App { #[serde(skip)] top: Top, + #[serde(skip)] + bottom: Bottom, + #[serde(skip)] layers: Option, } @@ -87,6 +93,7 @@ impl Default for App { text_channel: channel(), viewport: Viewport::new(), top: Top::new(), + bottom: Bottom::new(), layers: None, } } @@ -198,7 +205,7 @@ impl eframe::App for App { } } - self.viewport.update( + let viewport_rect = self.viewport.update( ctx, &self.top, self.shared_data.clone(), @@ -207,6 +214,8 @@ impl eframe::App for App { &self.layers, ); + self.bottom.update(ctx, &self.viewport, viewport_rect); + if ctx.input(|i| i.key_pressed(egui::Key::Escape)) { ctx.send_viewport_cmd(egui::ViewportCommand::Close); } diff --git a/src/bin/topola-egui/bottom.rs b/src/bin/topola-egui/bottom.rs new file mode 100644 index 0000000..fa865bd --- /dev/null +++ b/src/bin/topola-egui/bottom.rs @@ -0,0 +1,19 @@ +use crate::viewport::Viewport; + +pub struct Bottom {} + +impl Bottom { + pub fn new() -> Self { + Self {} + } + + pub fn update(&mut self, ctx: &egui::Context, viewport: &Viewport, viewport_rect: egui::Rect) { + egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| { + let transform = egui::emath::RectTransform::from_to(viewport.from_rect, viewport_rect); + let latest_pos = transform + .inverse() + .transform_pos(ctx.input(|i| i.pointer.latest_pos().unwrap_or_default())); + ui.label(format!("x: {} y: {}", latest_pos.x, latest_pos.y)); + }); + } +} diff --git a/src/bin/topola-egui/main.rs b/src/bin/topola-egui/main.rs index 3e1fb75..7afe8b9 100644 --- a/src/bin/topola-egui/main.rs +++ b/src/bin/topola-egui/main.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release mod app; +mod bottom; mod layers; mod overlay; mod painter; diff --git a/src/bin/topola-egui/viewport.rs b/src/bin/topola-egui/viewport.rs index 9008173..5909385 100644 --- a/src/bin/topola-egui/viewport.rs +++ b/src/bin/topola-egui/viewport.rs @@ -22,7 +22,7 @@ use crate::{ }; pub struct Viewport { - from_rect: egui::emath::Rect, + pub from_rect: egui::emath::Rect, } impl Viewport { @@ -40,7 +40,7 @@ impl Viewport { maybe_invoker: &Option>>>, maybe_overlay: &mut Option, maybe_layers: &Option, - ) { + ) -> egui::Rect { egui::CentralPanel::default().show(ctx, |ui| { egui::Frame::canvas(ui.style()).show(ui, |ui| { ui.ctx().request_repaint(); @@ -227,11 +227,11 @@ impl Viewport { egui::Color32::from_rgb(255, 255, 100), ); } - - //unreachable!(); } } + + viewport_rect }) - }); + }).inner.inner } }