mirror of https://codeberg.org/topola/topola.git
egui: add bottom bar displaying cursor position
Useful for writing tests.
This commit is contained in:
parent
13c8237da6
commit
d56d6046a4
|
|
@ -40,7 +40,10 @@ use topola::{
|
||||||
specctra::{design::SpecctraDesign, mesadata::SpecctraMesadata},
|
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)]
|
#[derive(Debug, Default)]
|
||||||
pub struct SharedData {
|
pub struct SharedData {
|
||||||
|
|
@ -74,6 +77,9 @@ pub struct App {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
top: Top,
|
top: Top,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
bottom: Bottom,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
layers: Option<Layers>,
|
layers: Option<Layers>,
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +93,7 @@ impl Default for App {
|
||||||
text_channel: channel(),
|
text_channel: channel(),
|
||||||
viewport: Viewport::new(),
|
viewport: Viewport::new(),
|
||||||
top: Top::new(),
|
top: Top::new(),
|
||||||
|
bottom: Bottom::new(),
|
||||||
layers: None,
|
layers: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +205,7 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.viewport.update(
|
let viewport_rect = self.viewport.update(
|
||||||
ctx,
|
ctx,
|
||||||
&self.top,
|
&self.top,
|
||||||
self.shared_data.clone(),
|
self.shared_data.clone(),
|
||||||
|
|
@ -207,6 +214,8 @@ impl eframe::App for App {
|
||||||
&self.layers,
|
&self.layers,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
self.bottom.update(ctx, &self.viewport, viewport_rect);
|
||||||
|
|
||||||
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod bottom;
|
||||||
mod layers;
|
mod layers;
|
||||||
mod overlay;
|
mod overlay;
|
||||||
mod painter;
|
mod painter;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Viewport {
|
pub struct Viewport {
|
||||||
from_rect: egui::emath::Rect,
|
pub from_rect: egui::emath::Rect,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Viewport {
|
impl Viewport {
|
||||||
|
|
@ -40,7 +40,7 @@ impl Viewport {
|
||||||
maybe_invoker: &Option<Arc<Mutex<Invoker<SpecctraMesadata>>>>,
|
maybe_invoker: &Option<Arc<Mutex<Invoker<SpecctraMesadata>>>>,
|
||||||
maybe_overlay: &mut Option<Overlay>,
|
maybe_overlay: &mut Option<Overlay>,
|
||||||
maybe_layers: &Option<Layers>,
|
maybe_layers: &Option<Layers>,
|
||||||
) {
|
) -> egui::Rect {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
egui::Frame::canvas(ui.style()).show(ui, |ui| {
|
egui::Frame::canvas(ui.style()).show(ui, |ui| {
|
||||||
ui.ctx().request_repaint();
|
ui.ctx().request_repaint();
|
||||||
|
|
@ -227,11 +227,11 @@ impl Viewport {
|
||||||
egui::Color32::from_rgb(255, 255, 100),
|
egui::Color32::from_rgb(255, 255, 100),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//unreachable!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewport_rect
|
||||||
})
|
})
|
||||||
});
|
}).inner.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue