mirror of https://codeberg.org/topola/topola.git
feat(topola-egui): Make stroke width independent of scale factor
This commit is contained in:
parent
b1ab710adb
commit
74b9004ed9
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use egui::Pos2;
|
||||
|
||||
use crate::{menu_bar::MenuBar, workspace::Workspace};
|
||||
use crate::{viewport::Viewport, workspace::Workspace};
|
||||
|
||||
pub struct Displayer {}
|
||||
|
||||
|
|
@ -18,9 +18,10 @@ impl Displayer {
|
|||
ctx: &egui::Context,
|
||||
ui: &egui::Ui,
|
||||
//menu_bar: &MenuBar,
|
||||
viewport: &Viewport,
|
||||
workspace: &Workspace,
|
||||
) {
|
||||
self.display_layout(ctx, ui, /*menu_bar,*/ workspace);
|
||||
self.display_layout(ctx, ui, /*menu_bar,*/ viewport, workspace);
|
||||
}
|
||||
|
||||
pub fn display_layout(
|
||||
|
|
@ -28,6 +29,7 @@ impl Displayer {
|
|||
ctx: &egui::Context,
|
||||
ui: &egui::Ui,
|
||||
//menu_bar: &MenuBar,
|
||||
viewport: &Viewport,
|
||||
workspace: &Workspace,
|
||||
) {
|
||||
ui.painter().line(
|
||||
|
|
@ -41,7 +43,7 @@ impl Displayer {
|
|||
y: p[1] as f32,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
egui::Stroke::new(500.0, egui::Color32::WHITE),
|
||||
egui::Stroke::new(20.0 / viewport.scale_factor(), egui::Color32::WHITE),
|
||||
);
|
||||
ui.painter().line(
|
||||
vec![
|
||||
|
|
|
|||
|
|
@ -5,29 +5,42 @@
|
|||
use crate::{displayer::Displayer, workspace::Workspace};
|
||||
|
||||
pub struct Viewport {
|
||||
pub view_rect: egui::Rect,
|
||||
pub scene_rect: egui::Rect,
|
||||
pub ref_scene_rect: egui::Rect,
|
||||
}
|
||||
|
||||
impl Viewport {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
view_rect: egui::Rect::from_min_max(
|
||||
egui::pos2(-10000.0, 10000.0),
|
||||
egui::pos2(-10000.0, 10000.0),
|
||||
scene_rect: egui::Rect::from_min_max(
|
||||
egui::pos2(-10000.0, -10000.0),
|
||||
egui::pos2(10000.0, 10000.0),
|
||||
),
|
||||
ref_scene_rect: egui::Rect::from_min_max(
|
||||
egui::pos2(-10000.0, -10000.0),
|
||||
egui::pos2(10000.0, 10000.0),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, ctx: &egui::Context, workspace: Option<&mut Workspace>) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
let mut scene_rect = self.scene_rect.clone();
|
||||
|
||||
egui::Scene::new()
|
||||
.zoom_range(0.0001..=10000.0)
|
||||
.show(ui, &mut self.view_rect, |ui| {
|
||||
.show(ui, &mut scene_rect, |ui| {
|
||||
if let Some(workspace) = workspace {
|
||||
let mut displayer = Displayer::new();
|
||||
displayer.update(ctx, ui, workspace)
|
||||
displayer.update(ctx, ui, &self, workspace);
|
||||
}
|
||||
});
|
||||
|
||||
self.scene_rect = scene_rect;
|
||||
});
|
||||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f32 {
|
||||
self.ref_scene_rect.width() / self.scene_rect.width()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue