From 8f72c212938743f616a0470cc221e00381e78b5a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 19:48:46 -0800 Subject: [PATCH] Show feedback when a zoom entry uses only a valid prefix --- crates/ui-egui/src/chrome/status_bar.rs | 12 ++++++-- crates/ui-egui/src/panels/navigator.rs | 37 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/chrome/status_bar.rs b/crates/ui-egui/src/chrome/status_bar.rs index aef6749bbc..0697d1cf8e 100644 --- a/crates/ui-egui/src/chrome/status_bar.rs +++ b/crates/ui-egui/src/chrome/status_bar.rs @@ -9,6 +9,7 @@ use craft::ui::form::Field; use craft::ui::layout_components::Row; use craft::ui::menu::Menu; use craft::ui::pickers::{Select, SelectLook}; +use craft::ui::runtime::env::Env; use craft::ui::style::TypeRole; use craft::ui::text::ZoomField; @@ -47,6 +48,7 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { let busy = busy_labels(app); let (mut zoom_to, mut rotate_to, mut go, mut show_pick, mut stop) = (None, None, None, None, false); + let mut invalid_zoom = None; // The readouts end the bar, the pointer's position and then the timings; a narrow bar leaves out the timings // first, then the position, before the message. let readouts = |ui: &mut Ui, _: &mut BodyCx<'_>| { @@ -73,8 +75,11 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { .side(SideLabel::new().kind(LabelKind::Hidden)) .show(ui, |ui, _| ZoomField::new(tl!("Zoom"), app.canvas_view(), document).scrub(true).show(ui)); // The field edits the canvas view, whose zoom is divided by UI Scaling; `view.setZoom` takes the view's zoom. - if let Some(view) = zoom.inner.and_then(|z| z.view.committed().copied()) { - zoom_to = Some(crate::state::zoom_display_percent(crate::state::View::zoom_of_canvas(&view, app.ui_scaling()), print)); + if let Some(zoom) = zoom.inner { + if let Some(view) = zoom.view.committed() { + zoom_to = Some(crate::state::zoom_display_percent(crate::state::View::zoom_of_canvas(view, app.ui_scaling()), print)); + } + invalid_zoom = zoom.invalid_zoom.map(|invalid| invalid.message(&Env::of(ui))); } Field::new(tl!("Rotation")).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| { // Entries are keyed by index: an angle is not a hashable value. @@ -156,6 +161,9 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) { { app.status(e); } + if let Some(message) = invalid_zoom { + app.status(message); + } } /// What the bar shows as work in progress: the running script, then background jobs, opens and places. The first diff --git a/crates/ui-egui/src/panels/navigator.rs b/crates/ui-egui/src/panels/navigator.rs index 31bb7ebd9f..c1f6bcc537 100644 --- a/crates/ui-egui/src/panels/navigator.rs +++ b/crates/ui-egui/src/panels/navigator.rs @@ -284,12 +284,49 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let scaling = app.ui_scaling(); app.run("view.setZoom", view_params(edited, region, print, scaling)).ok(); } + if let Some(invalid) = out.invalid_zoom { + app.status(invalid.message(&env)); + } } #[cfg(test)] mod tests { use super::*; + #[test] + fn navigator_reports_a_malformed_zoom_entry() { + assert_malformed_zoom_entry_reported(show); + } + + #[test] + fn status_bar_reports_a_malformed_zoom_entry() { + assert_malformed_zoom_entry_reported(crate::chrome::status_bar); + } + + fn assert_malformed_zoom_entry_reported(draw: fn(&mut VectorcraftApp, &mut Ui)) { + crate::i18n::set_current(crate::i18n::Lang::EN); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": false})).unwrap(); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.view_mut().unwrap().rect = Rect::from_min_size(pos2(0.0, 0.0), egui::vec2(460.0, 260.0)); + app.run("view.setZoom", json!({"zoom": 100})).unwrap(); + let mut panel = crate::tests::panel_harness::Panel::new(app, draw); + panel.app().ui.status.clear(); + panel.type_into("Zoom", "80..2"); + { + let app = panel.app(); + assert!((app.view().unwrap().zoom - 0.8).abs() < 1e-9, "applies the valid prefix"); + assert!(app.ui.status.contains("Closest value inserted"), "reports the partial entry: {:?}", app.ui.status); + } + panel.app().ui.status.clear(); + panel.type_into("Zoom", "200"); + { + let app = panel.app(); + assert!((app.view().unwrap().zoom - 2.0).abs() < 1e-9, "still accepts a valid entry"); + assert!(!app.ui.status.contains("Closest value inserted"), "does not warn for a valid entry"); + } + } + /// A centre edit of the shifted view reaches `view.setZoom` as the document point it shows, and /// an unedited view's centre is shifted by the region's corner. #[test]