mirror of https://codeberg.org/topola/topola.git
egui/Viewport: merge zoom_to_fit part into paint, merge into update method
This commit is contained in:
parent
1420995492
commit
e66fbe292b
|
|
@ -35,22 +35,6 @@ impl Viewport {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
|
||||||
ctx: &egui::Context,
|
|
||||||
top: &MenuBar,
|
|
||||||
mut maybe_workspace: Option<&mut Workspace>,
|
|
||||||
) -> egui::Rect {
|
|
||||||
let viewport_rect = self.paint(ctx, top, maybe_workspace.as_deref_mut());
|
|
||||||
|
|
||||||
if self.scheduled_zoom_to_fit {
|
|
||||||
let mut maybe_invoker = maybe_workspace.as_mut().map(|w| &mut w.invoker);
|
|
||||||
self.zoom_to_fit(maybe_invoker.as_deref_mut(), &viewport_rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
viewport_rect
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn paint(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &egui::Context,
|
ctx: &egui::Context,
|
||||||
top: &MenuBar,
|
top: &MenuBar,
|
||||||
|
|
@ -247,20 +231,8 @@ impl Viewport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
viewport_rect
|
|
||||||
})
|
|
||||||
}).inner.inner
|
|
||||||
}
|
|
||||||
|
|
||||||
fn zoom_to_fit(
|
|
||||||
&mut self,
|
|
||||||
maybe_invoker: Option<&mut Invoker<SpecctraMesadata>>,
|
|
||||||
viewport_rect: &egui::Rect,
|
|
||||||
) {
|
|
||||||
if self.scheduled_zoom_to_fit {
|
if self.scheduled_zoom_to_fit {
|
||||||
if let Some(invoker) = maybe_invoker {
|
|
||||||
let root_bbox = invoker
|
let root_bbox = invoker
|
||||||
.autorouter()
|
.autorouter()
|
||||||
.board()
|
.board()
|
||||||
|
|
@ -273,13 +245,13 @@ impl Viewport {
|
||||||
let root_bbox_width = root_bbox.upper()[0] - root_bbox.lower()[0];
|
let root_bbox_width = root_bbox.upper()[0] - root_bbox.lower()[0];
|
||||||
let root_bbox_height = root_bbox.upper()[1] - root_bbox.lower()[1];
|
let root_bbox_height = root_bbox.upper()[1] - root_bbox.lower()[1];
|
||||||
|
|
||||||
if root_bbox_width / root_bbox_height
|
self.transform.scaling = 0.8 * if root_bbox_width / root_bbox_height
|
||||||
>= (viewport_rect.width() as f64) / (viewport_rect.height() as f64)
|
>= (viewport_rect.width() as f64) / (viewport_rect.height() as f64)
|
||||||
{
|
{
|
||||||
self.transform.scaling = 0.8 * viewport_rect.width() / root_bbox_width as f32;
|
viewport_rect.width() / root_bbox_width as f32
|
||||||
} else {
|
} else {
|
||||||
self.transform.scaling = 0.8 * viewport_rect.height() / root_bbox_height as f32;
|
viewport_rect.height() / root_bbox_height as f32
|
||||||
}
|
};
|
||||||
|
|
||||||
self.transform.translation = egui::Vec2::new(
|
self.transform.translation = egui::Vec2::new(
|
||||||
viewport_rect.center()[0] as f32,
|
viewport_rect.center()[0] as f32,
|
||||||
|
|
@ -288,8 +260,12 @@ impl Viewport {
|
||||||
* egui::Pos2::new(root_bbox.center()[0] as f32, -root_bbox.center()[1] as f32))
|
* egui::Pos2::new(root_bbox.center()[0] as f32, -root_bbox.center()[1] as f32))
|
||||||
.to_vec2();
|
.to_vec2();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.scheduled_zoom_to_fit = false;
|
self.scheduled_zoom_to_fit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewport_rect
|
||||||
|
})
|
||||||
|
}).inner.inner
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue