* claim: #4176 * Preferences: mouse-wheel zoom speed (#4176) A 0.25x to 4x multiplier for each wheel zoom step, applied in navigation::handle so every canvas uses it. The 3D mouse keeps its own speed. Values outside the range are refused when set and reset to 1x when loaded. * Control protocol: wheel_zoom_speed in the sorted ui.prefs list (#4176) * Wheel zoom speed: its label in the complete catalogs (#4176)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"en": {
|
||||
"ui.wheel_zoom_speed": "Mouse wheel zoom speed"
|
||||
},
|
||||
"ar": {
|
||||
"ui.wheel_zoom_speed": "سرعة التكبير بعجلة الفأرة"
|
||||
},
|
||||
"de": {
|
||||
"ui.wheel_zoom_speed": "Zoomgeschwindigkeit des Mausrads"
|
||||
},
|
||||
"he": {
|
||||
"ui.wheel_zoom_speed": "מהירות זום בגלגלת העכבר"
|
||||
},
|
||||
"ja": {
|
||||
"ui.wheel_zoom_speed": "マウスホイールのズーム速度"
|
||||
},
|
||||
"vi": {
|
||||
"ui.wheel_zoom_speed": "Tốc độ thu phóng bằng con lăn chuột"
|
||||
},
|
||||
"zh": {
|
||||
"ui.wheel_zoom_speed": "鼠标滚轮缩放速度"
|
||||
}
|
||||
}
|
||||
@@ -595,7 +595,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
}
|
||||
if inside && scroll.is_finite() && scroll != 0.0 {
|
||||
app.viewport.orbit_free = None;
|
||||
let f = (-scroll as f64 * 0.0015 * crate::prefs::zoom_sign(app)).exp();
|
||||
let f = (-scroll as f64 * 0.0015 * f64::from(app.preferences.wheel_zoom_speed) * crate::prefs::zoom_sign(app)).exp();
|
||||
let anchor = zoom_anchor(app, rect, hover, caps.orbit);
|
||||
if app.preferences.nav == crate::prefs::TOUCHPAD_NAV {
|
||||
let mut params = json!({"motion":"zoom", "factor":f.clamp(0.05,20.0)});
|
||||
@@ -1703,6 +1703,86 @@ mod tests {
|
||||
assert!(offenders.is_empty(), "camera input outside navigation::handle; call it instead:\n{}", offenders.join("\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wheel_zoom_speed_scales_each_step_on_every_canvas() {
|
||||
use egui::{Event, Modifiers, MouseWheelUnit, TouchPhase, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
for caps in [super::NavCaps::MODEL, super::NavCaps::RENDER, super::NavCaps { orbit: false, pick: false }] {
|
||||
for speed in [None, Some(0.25), Some(1.0), Some(4.0)] {
|
||||
for reverse in [false, true] {
|
||||
let mut app = crate::SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
|
||||
crate::prefs::set(&mut app, &json!({"smooth_wheel_zoom":false, "zoom_to_cursor":false, "zoom_reverse":reverse})).unwrap();
|
||||
if let Some(speed) = speed {
|
||||
crate::prefs::set(&mut app, &json!({"wheel_zoom_speed":speed})).unwrap();
|
||||
}
|
||||
let ctx = crate::fonts::test_context();
|
||||
let mut frame = |events| {
|
||||
let raw = egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(800.0, 600.0))),
|
||||
focused: true,
|
||||
events,
|
||||
..Default::default()
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
let rect = ui.max_rect();
|
||||
let resp = ui.interact(rect, ui.id().with("wheel-speed"), egui::Sense::click_and_drag());
|
||||
super::handle(&mut app, ui, rect, &resp, caps);
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
};
|
||||
frame(vec![Event::PointerMoved(pos2(200.0, 300.0))]);
|
||||
frame(vec![Event::MouseWheel {
|
||||
unit: MouseWheelUnit::Point,
|
||||
delta: vec2(0.0, 40.0),
|
||||
modifiers: Modifiers::NONE,
|
||||
phase: TouchPhase::Move,
|
||||
}]);
|
||||
let expected = (-40.0_f64 * 0.0015 * speed.unwrap_or(1.0) * if reverse { -1.0 } else { 1.0 }).exp();
|
||||
let default_distance = super::Camera::default().distance;
|
||||
assert!((app.cam.distance / default_distance - expected).abs() < 1e-6, "{caps:?}, {speed:?}, reverse={reverse}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wheel_zoom_speed_persists_defaults_and_rejects_invalid_values() {
|
||||
use serde_json::json;
|
||||
let mut app = crate::SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
|
||||
let old = crate::prefs::lenient(&json!({"zoom_reverse":true}));
|
||||
assert_eq!(serde_json::to_value(old).unwrap()["wheel_zoom_speed"], 1.0);
|
||||
crate::prefs::control(&mut app, &json!({"open":"Navigation", "wheel_zoom_speed":2.5, "button":"apply"})).unwrap();
|
||||
let saved = serde_json::to_value(&app.preferences).unwrap();
|
||||
assert_eq!(serde_json::to_value(crate::prefs::lenient(&saved)).unwrap()["wheel_zoom_speed"], 2.5);
|
||||
for invalid in [0.0, 0.24, 4.01, 1e30] {
|
||||
assert!(crate::prefs::set(&mut app, &json!({"wheel_zoom_speed":invalid})).is_err());
|
||||
let loaded = crate::prefs::lenient(&json!({"wheel_zoom_speed":invalid, "zoom_reverse":true}));
|
||||
assert_eq!(serde_json::to_value(&loaded).unwrap()["wheel_zoom_speed"], 1.0);
|
||||
assert!(loaded.zoom_reverse);
|
||||
}
|
||||
crate::prefs::control(&mut app, &json!({"button":"defaults"})).unwrap();
|
||||
assert_eq!(serde_json::to_value(&app.preferences).unwrap()["wheel_zoom_speed"], 1.0);
|
||||
crate::prefs::control(&mut app, &json!({"button":"cancel"})).unwrap();
|
||||
assert_eq!(serde_json::to_value(&app.preferences).unwrap()["wheel_zoom_speed"], 2.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wheel_zoom_speed_does_not_change_3d_mouse_zoom() {
|
||||
use crate::space_mouse::{DeviceMotion, Motion};
|
||||
let mut distances = Vec::new();
|
||||
for speed in [0.25, 1.0, 4.0] {
|
||||
let mut app = crate::SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());
|
||||
crate::prefs::set(&mut app, &serde_json::json!({"wheel_zoom_speed":speed})).unwrap();
|
||||
let before = app.cam.distance;
|
||||
app.viewport.device_motion = Some(DeviceMotion { motion: Motion { translation: [0.0, 1.0, 0.0], rotation: [0.0; 3] }, seconds: 0.05 });
|
||||
super::device(&mut app, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0)), super::NavCaps::MODEL);
|
||||
assert!(app.cam.distance < before);
|
||||
distances.push(app.cam.distance);
|
||||
}
|
||||
assert!(distances.windows(2).all(|pair| pair[0] == pair[1]));
|
||||
}
|
||||
|
||||
/// A flat page (orbit off) pans and zooms with the same bindings and never turns the view.
|
||||
#[test]
|
||||
fn flat_pages_pan_and_zoom_with_the_same_bindings_but_never_orbit() {
|
||||
|
||||
@@ -1082,6 +1082,8 @@ preference_settings! {
|
||||
browser_bodies_folders: BodiesFolders = BodiesFolders::Several, PAGE_INTERFACE;
|
||||
/// The wheel zooms toward the point under the cursor (else toward the view's centre).
|
||||
zoom_to_cursor: bool = true, PAGE_NAVIGATION => check("Zoom to the cursor", "The wheel zooms toward the point under the cursor (off: toward the view's centre)");
|
||||
/// Speed multiplier for wheel zoom, independent of the 3D mouse.
|
||||
wheel_zoom_speed: f32 = 1.0, PAGE_NAVIGATION, accept(0.25..=4.0) => slider("ui.wheel_zoom_speed", 0.25..=4.0, 0.05, |v| format!("{v:.2}×"), "prefs:wheel_zoom_speed");
|
||||
/// Spread discrete wheel input across frames (off: apply each event immediately).
|
||||
smooth_wheel_zoom: bool = true, PAGE_NAVIGATION => check("Smooth wheel zoom", "Turn off to apply each wheel event immediately, without a smoothing tail");
|
||||
/// Two-finger trackpad scroll pans (off: it zooms like the wheel); pinch always zooms.
|
||||
@@ -3081,6 +3083,9 @@ pub fn migrate(mut p: Prefs) -> Prefs {
|
||||
if !p.joint_rotation_fine.is_finite() || !(0.001..=180.0).contains(&p.joint_rotation_fine) {
|
||||
p.joint_rotation_fine = 0.1;
|
||||
}
|
||||
if !accepted::wheel_zoom_speed(&p) {
|
||||
p.wheel_zoom_speed = Prefs::default().wheel_zoom_speed;
|
||||
}
|
||||
if p.orbit_cursor {
|
||||
p.orbit_around = OrbitAround::Cursor;
|
||||
p.orbit_cursor = false;
|
||||
@@ -3191,7 +3196,11 @@ pub fn set(app: &mut SolveApp, p: &serde_json::Value) -> Result<serde_json::Valu
|
||||
{
|
||||
return Err("`stand_up_unknown` must be ask, note or off".into());
|
||||
}
|
||||
let new: Prefs = migrate(serde_json::from_value(cur).map_err(|e| e.to_string())?);
|
||||
let new: Prefs = serde_json::from_value(cur).map_err(|e| e.to_string())?;
|
||||
if !accepted::wheel_zoom_speed(&new) {
|
||||
return Err("`wheel_zoom_speed` must be 0.25…4".into());
|
||||
}
|
||||
let new = migrate(new);
|
||||
if !UNITS.contains(&new.default_units.as_str()) {
|
||||
return Err(format!("units must be one of {}", UNITS.join(", ")));
|
||||
}
|
||||
|
||||
@@ -161,6 +161,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
crate::scenario::publish_target("view:tool_cursor", cursor.rect);
|
||||
ui_kit::divider(ui, "navigation_view_controls");
|
||||
ui_kit::settings_form(ui, 150.0, |ui| {
|
||||
setting::wheel_zoom_speed(app, ui);
|
||||
ui_kit::row(ui, app.tr_label("View navigator"), |ui| {
|
||||
let mut selected = usize::from(app.preferences.navigator_style == NavigatorStyle::Cube);
|
||||
if ui_kit::segmented(
|
||||
|
||||
@@ -403,6 +403,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
|
||||
- `up_axis` (`z`, `y`)
|
||||
- `view_confirm_corner` (default false: while a dialog or a sketch is open, a check and a cross at the view's top right, handles `view:confirm:ok` and `view:confirm:cancel`, do what the dialog's OK and Cancel do, or Finish Sketch and Cancel Sketch; the axis view or cube moves down below them, #6709)
|
||||
- `viewport_theme` (`theme` (default: the theme's own), `light`, `dark`: the 3D view in the Light or Dark theme's colours whatever the window uses, #4146)
|
||||
- `wheel_zoom_speed` (0.25 to 4, default 1: how far each wheel step zooms; the 3D mouse keeps its own speed)
|
||||
- `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it)
|
||||
- `zoom_reverse`
|
||||
- `zoom_to_cursor`
|
||||
|
||||
Reference in New Issue
Block a user