Merge pull request #9672 from dotCooCoo/fix/zoom-malformed-entry-status

Show feedback when a zoom entry uses only a valid prefix
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-26 21:40:46 -08:00
commit b9e7caefda
2 files changed
+47 -2

No files matched your search

+10 -2
View File
@@ -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
+37
View File
@@ -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]