mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Status bar: the zoom presets menu leaves out stops outside the zoom range
With Display Print Size on, 100% is not one screen point per document point, so a stop at either end of the list can fall outside the view's zoom range (WindowView::ZOOM_RANGE). Picking it set the nearest end of the range instead: at 96 PPI the 64000% entry showed 48000%. The menu now lists only the stops that view.setZoom sets exactly.
This commit is contained in:
1 parent
73b12022a8
commit
46e61230e2
1 file changed
+41
-1
@@ -12,6 +12,7 @@ use craft::ui::pickers::{Select, SelectLook};
|
||||
use craft::ui::runtime::env::Env;
|
||||
use craft::ui::style::TypeRole;
|
||||
use craft::ui::text::ZoomField;
|
||||
use vectorcraft_engine::WindowView;
|
||||
|
||||
/// Shows the status bar: zoom, rotation, artboard navigator, the info field with its Show menu, the readouts, Stop,
|
||||
/// the background-work progress and last the message, so a narrow bar elides the message before anything else.
|
||||
@@ -334,6 +335,38 @@ mod tests {
|
||||
assert!(zoom_presets(None, None).iter().all(|e| !e.is_checked()), "without a view no stop is checked");
|
||||
}
|
||||
|
||||
/// With Display Print Size on, 100% is more or less than one screen point per document point, so the stops at
|
||||
/// the ends of the list can fall outside the view's zoom range; the menu lists only the stops a pick sets exactly.
|
||||
#[test]
|
||||
fn the_zoom_presets_leave_out_stops_outside_the_zoom_range_at_print_size() {
|
||||
let percents = |print: Option<f64>| -> Vec<f64> {
|
||||
zoom_presets(None, print)
|
||||
.iter()
|
||||
.filter_map(|e| match e.value() {
|
||||
Some(ZoomPreset::Percent(pct)) => Some(*pct),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let stops: Vec<f64> = crate::state::zoom_stop_percents().collect();
|
||||
let n = stops.len();
|
||||
assert_eq!(percents(None).len(), n, "at 1:1 every stop is in range");
|
||||
let dense = crate::state::print_ppi(true, Some(96.0));
|
||||
assert_eq!(percents(dense).first(), Some(&stops[n - 2]), "64000% at 96 PPI is past the highest zoom, 25600% is not");
|
||||
assert_eq!(percents(dense).last(), Some(&stops[0]), "3.13% at 96 PPI is in range");
|
||||
let sparse = crate::state::print_ppi(true, Some(40.0));
|
||||
assert_eq!(percents(sparse).first(), Some(&stops[n - 1]), "64000% at 40 PPI is in range");
|
||||
assert_eq!(percents(sparse).last(), Some(&stops[2]), "3.13% and 4.17% at 40 PPI are below the lowest zoom, 6.25% is not");
|
||||
let (min, max) = WindowView::ZOOM_RANGE;
|
||||
for print in [None, dense, sparse] {
|
||||
for pct in percents(print) {
|
||||
let zoom = crate::state::zoom_from_display_percent(pct, print);
|
||||
let set = crate::state::zoom_display_percent(zoom.clamp(min, max), print);
|
||||
assert!((set - pct).abs() < 1e-6, "{pct}% at {print:?} sets {set}%");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_document_the_artboard_navigator_shows_a_dash() {
|
||||
let app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
@@ -369,11 +402,18 @@ enum ZoomPreset {
|
||||
}
|
||||
|
||||
/// The Zoom Presets menu: the zoom stops from the highest, the one at the `shown` percent checked, then Fit on Screen
|
||||
/// and Fit All.
|
||||
/// and Fit All. A stop whose zoom falls outside the view's zoom range ([`WindowView::ZOOM_RANGE`]) at the `print`
|
||||
/// setting is left out, since `view.setZoom` would set the nearest end of the range instead.
|
||||
fn zoom_presets(shown: Option<f64>, print: Option<f64>) -> Vec<Entry<ZoomPreset>> {
|
||||
let (min, max) = WindowView::ZOOM_RANGE;
|
||||
let reachable = |pct: &f64| {
|
||||
let zoom = crate::state::zoom_from_display_percent(*pct, print);
|
||||
zoom >= min * (1.0 - 1e-9) && zoom <= max * (1.0 + 1e-9)
|
||||
};
|
||||
let stops = crate::state::zoom_stop_percents();
|
||||
let mut entries: Vec<Entry<ZoomPreset>> = stops
|
||||
.rev()
|
||||
.filter(reachable)
|
||||
.map(|pct| {
|
||||
let label = crate::state::zoom_label(crate::state::zoom_from_display_percent(pct, print), print);
|
||||
Entry::new(ZoomPreset::Percent(pct), label).checked(shown.is_some_and(|s| (s - pct).abs() < 0.01))
|
||||
|
||||
Reference in new issue
Block a user