Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

#2253: Reset Interface Zoom replies with the zoom it set

irgendwasmitfelixaf3263cd9b53
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 2964378de..576f912da 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -687,10 +687,12 @@ impl FilmcraftApp {
/// View ▸ Reset Interface Zoom: the scale Settings ▸ Appearance ▸ UI Scale asks for (the
/// system's with Auto), undoing any session zoom (#2253).
- pub(crate) fn reset_ui_zoom(&mut self, ctx: &egui::Context) {
+ /// Returns the zoom factor set (egui reports it from the next pass on).
+ pub(crate) fn reset_ui_zoom(&mut self, ctx: &egui::Context) -> f32 {
let native = ctx.native_pixels_per_point().filter(|v| v.is_finite() && *v > 0.0).unwrap_or(1.0);
let zoom = self.session.prefs.appearance.ui_scale_factor().map_or(1.0, |scale| scale / native);
ctx.set_zoom_factor(zoom);
+ zoom
}
/// Make the UI follow the settings after they change (theme, tooltips, frame cache budget,
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs
index 45740f0e2..1d760d0c0 100644
--- a/crates/ui-egui/src/menus.rs
+++ b/crates/ui-egui/src/menus.rs
@@ -421,8 +421,8 @@ pub fn invoke(app: &mut FilmcraftApp, ctx: &egui::Context, id: &str, mut params:
// the whole interface back to Settings ▸ Appearance ▸ UI Scale, after Ctrl+Plus or a mouse
// mapped to page zoom scaled it (#2253)
"view.resetInterfaceZoom" => {
- app.reset_ui_zoom(ctx);
- return Ok(json!({"zoom": ctx.zoom_factor()}));
+ let zoom = app.reset_ui_zoom(ctx);
+ return Ok(json!({"zoom": zoom}));
}
"mode.import" => {
app.ui.mode = Mode::Import;
diff --git a/crates/ui-egui/tests/interface_zoom_ui.rs b/crates/ui-egui/tests/interface_zoom_ui.rs
index e3e6725cb..2908a0017 100644
--- a/crates/ui-egui/tests/interface_zoom_ui.rs
+++ b/crates/ui-egui/tests/interface_zoom_ui.rs
@@ -89,7 +89,8 @@ fn ctrl_plus_does_what_ctrl_equals_does_and_the_interface_zoom_can_be_reset() {
d.harness.ctx.set_zoom_factor(1.75);
d.frames(2);
assert_eq!(d.harness.ctx.zoom_factor(), 1.75);
- d.ok("ui.menu.invoke", json!({"id": "view.resetInterfaceZoom"}));
+ let r = d.ok("ui.menu.invoke", json!({"id": "view.resetInterfaceZoom"}));
+ assert_eq!(r["zoom"], json!(1.0), "the reply says the zoom it set: {r}");
d.frames(2);
assert_eq!(d.harness.ctx.zoom_factor(), 1.0);
}