* Trackpad: zoom with two-finger scroll while holding a key, chosen in Preferences (#8322) Holding the zoom key turns a vertical two-finger scroll (or a wheel) into zoom at the pointer, with the wheel zoom's speed, direction and anchor, so a laptop user zooms without pinching. Preferences > Navigation > "Zoom with two-finger scroll while holding": Cmd on macOS and Ctrl elsewhere (default), Option/Alt, Ctrl, or Off. That key with the scroll did nothing before, so no default changes; Off keeps it that way. Shift keeps its orbit. * Trackpad zoom modifier: off by default (#8322) Scroll keeps its usual meaning until a key is chosen in Navigation. * Trackpad zoom modifier tests: Off is the default; tests that zoom choose Cmd (#8322) * Trackpad zoom modifier: zoom once alongside the Ctrl+wheel pinch from #8539 (#8322) A wheel the chosen key claims is no longer also read as a pinch, and a key that is not chosen keeps main's pinch handling unchanged.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"ar": {
|
||||
"prefs.trackpad_zoom_modifier": "التكبير بالتمرير بإصبعين أثناء الضغط على",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "اضغط على هذا المفتاح فقط للتكبير عند المؤشر بالتمرير العمودي. يحافظ الإيقاف على سلوك التمرير الحالي.",
|
||||
"prefs.trackpad_zoom_modifier.off": "إيقاف"
|
||||
},
|
||||
"de": {
|
||||
"prefs.trackpad_zoom_modifier": "Mit zwei Fingern zoomen bei gedrückter Taste",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Strg",
|
||||
"prefs.trackpad_zoom_modifier.help": "Nur diese Taste gedrückt halten, um durch vertikales Scrollen am Zeiger zu zoomen. Aus behält das bisherige Scrollverhalten bei.",
|
||||
"prefs.trackpad_zoom_modifier.off": "Aus"
|
||||
},
|
||||
"en": {
|
||||
"prefs.trackpad_zoom_modifier": "Zoom with two-finger scroll while holding",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "Hold only this key to zoom at the pointer with vertical scroll. Off keeps the existing scroll behaviour.",
|
||||
"prefs.trackpad_zoom_modifier.off": "Off"
|
||||
},
|
||||
"he": {
|
||||
"prefs.trackpad_zoom_modifier": "שינוי תקריב בגלילה בשתי אצבעות בזמן החזקת",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "יש להחזיק רק מקש זה כדי לשנות תקריב ליד המצביע בגלילה אנכית. כיבוי שומר על התנהגות הגלילה הקיימת.",
|
||||
"prefs.trackpad_zoom_modifier.off": "כבוי"
|
||||
},
|
||||
"ja": {
|
||||
"prefs.trackpad_zoom_modifier": "2本指スクロールでズームする修飾キー",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "このキーだけを押しながら縦にスクロールすると、ポインター位置を基準にズームします。オフでは従来のスクロール動作を維持します。",
|
||||
"prefs.trackpad_zoom_modifier.off": "オフ"
|
||||
},
|
||||
"ko": {
|
||||
"prefs.trackpad_zoom_modifier": "다음 키를 누른 채 두 손가락으로 스크롤하여 확대/축소",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "이 키만 누른 채 세로로 스크롤하면 포인터 위치를 기준으로 확대/축소합니다. 끄면 기존 스크롤 동작을 유지합니다.",
|
||||
"prefs.trackpad_zoom_modifier.off": "끄기"
|
||||
},
|
||||
"vi": {
|
||||
"prefs.trackpad_zoom_modifier": "Thu phóng bằng cuộn hai ngón tay khi giữ",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "Chỉ giữ phím này để thu phóng tại con trỏ bằng cuộn dọc. Tắt giữ nguyên hành vi cuộn hiện tại.",
|
||||
"prefs.trackpad_zoom_modifier.off": "Tắt"
|
||||
},
|
||||
"zh": {
|
||||
"prefs.trackpad_zoom_modifier": "按住以下按键时用双指滚动缩放",
|
||||
"prefs.trackpad_zoom_modifier.alt": "⌥ / Alt",
|
||||
"prefs.trackpad_zoom_modifier.cmd": "⌘",
|
||||
"prefs.trackpad_zoom_modifier.ctrl": "Ctrl",
|
||||
"prefs.trackpad_zoom_modifier.help": "仅按住此键并垂直滚动,即可以指针位置为中心缩放。关闭时保留现有滚动行为。",
|
||||
"prefs.trackpad_zoom_modifier.off": "关闭"
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,10 @@ pub(crate) struct RawWheel {
|
||||
zoom: f32,
|
||||
/// Trackpad point input, routed like the wheel (zooms when panning is off).
|
||||
point_zoom: f32,
|
||||
/// Vertical scroll with the chosen modifier alone (always zooms).
|
||||
modifier_zoom: f32,
|
||||
/// Modifier input was consumed, including horizontal-only or zero-sum scroll.
|
||||
modifier_scroll: bool,
|
||||
/// Bracketed two-finger scroll in points (pans when panning is on).
|
||||
pan: egui::Vec2,
|
||||
shift_pan: egui::Vec2,
|
||||
@@ -173,13 +177,24 @@ pub(crate) fn immediate_wheel(
|
||||
gesture: &mut bool,
|
||||
coast: &mut TrackpadCoast,
|
||||
shift_orbits: bool,
|
||||
zoom_modifier: Option<egui::Modifiers>,
|
||||
) -> RawWheel {
|
||||
let mut out = RawWheel { zoom: 0.0, point_zoom: 0.0, pan: egui::Vec2::ZERO, shift_pan: egui::Vec2::ZERO, mouse_pan: egui::Vec2::ZERO };
|
||||
let mut out = RawWheel {
|
||||
zoom: 0.0,
|
||||
point_zoom: 0.0,
|
||||
modifier_zoom: 0.0,
|
||||
modifier_scroll: false,
|
||||
pan: egui::Vec2::ZERO,
|
||||
shift_pan: egui::Vec2::ZERO,
|
||||
mouse_pan: egui::Vec2::ZERO,
|
||||
};
|
||||
for event in &input.events {
|
||||
let egui::Event::MouseWheel { unit, delta, modifiers, phase } = event else { continue };
|
||||
if modifiers.matches_any(options.zoom_modifier) {
|
||||
let modifier_zoom = claims_scroll(*modifiers, zoom_modifier);
|
||||
if !modifier_zoom && modifiers.matches_any(options.zoom_modifier) {
|
||||
continue;
|
||||
}
|
||||
out.modifier_scroll |= modifier_zoom;
|
||||
let point = matches!(unit, egui::MouseWheelUnit::Point);
|
||||
match phase {
|
||||
egui::TouchPhase::Start => {
|
||||
@@ -207,6 +222,13 @@ pub(crate) fn immediate_wheel(
|
||||
egui::MouseWheelUnit::Line => *delta * options.line_scroll_speed,
|
||||
egui::MouseWheelUnit::Page => *delta * page_height,
|
||||
};
|
||||
if !points.is_finite() {
|
||||
continue;
|
||||
}
|
||||
if modifier_zoom {
|
||||
out.modifier_zoom += points.y;
|
||||
continue;
|
||||
}
|
||||
let shift = modifiers.shift && !modifiers.ctrl && !modifiers.command && !modifiers.alt;
|
||||
if point && *gesture && !coast.moves(shift) && shift_orbits {
|
||||
continue;
|
||||
@@ -233,12 +255,18 @@ pub(crate) fn immediate_wheel(
|
||||
out
|
||||
}
|
||||
|
||||
/// Whether the chosen trackpad zoom modifier (Preferences › Navigation, #8322) claims a wheel
|
||||
/// event: that key held alone. egui aliases Ctrl/Command on Windows/Linux; macOS can hold both.
|
||||
pub(crate) fn claims_scroll(modifiers: egui::Modifiers, zoom_modifier: Option<egui::Modifiers>) -> bool {
|
||||
zoom_modifier.is_some_and(|chosen| modifiers.matches_exact(chosen) && !(modifiers.mac_cmd && modifiers.ctrl))
|
||||
}
|
||||
|
||||
/// Combined pinch-to-zoom factor for one frame (1 = no pinch input).
|
||||
///
|
||||
/// Some input paths deliver pinch as a zoom-modified wheel instead of `Event::Zoom`.
|
||||
/// Read the raw movement that [`immediate_wheel`] leaves to the zoom modifier, without
|
||||
/// replaying egui's smoothed zoom delta on later frames. Gesture boundaries carry no movement.
|
||||
pub(crate) fn pinch_factor(input: &egui::InputState, options: egui::InputOptions, page_height: f32) -> f32 {
|
||||
pub(crate) fn pinch_factor(input: &egui::InputState, options: egui::InputOptions, page_height: f32, zoom_modifier: Option<egui::Modifiers>) -> f32 {
|
||||
let mut factor = 1.0;
|
||||
for event in &input.events {
|
||||
match event {
|
||||
@@ -247,7 +275,10 @@ pub(crate) fn pinch_factor(input: &egui::InputState, options: egui::InputOptions
|
||||
factor *= f;
|
||||
}
|
||||
}
|
||||
egui::Event::MouseWheel { unit, delta, modifiers, phase: egui::TouchPhase::Move } if modifiers.matches_any(options.zoom_modifier) => {
|
||||
// A wheel the chosen zoom modifier already turns into zoom is not also a pinch.
|
||||
egui::Event::MouseWheel { unit, delta, modifiers, phase: egui::TouchPhase::Move }
|
||||
if modifiers.matches_any(options.zoom_modifier) && !claims_scroll(*modifiers, zoom_modifier) =>
|
||||
{
|
||||
let points = match unit {
|
||||
egui::MouseWheelUnit::Point => *delta,
|
||||
egui::MouseWheelUnit::Line => *delta * options.line_scroll_speed,
|
||||
@@ -515,8 +546,15 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
let options = ui.ctx().options(|o| o.input_options);
|
||||
let page_height = ui.ctx().viewport_rect().height();
|
||||
let trackpad_orbit = trackpad_pan && app.preferences.nav == "fusion";
|
||||
let zoom_modifier = app.preferences.trackpad_zoom_modifier.modifiers();
|
||||
let viewport = &mut app.viewport;
|
||||
let raw = ui.input(|i| immediate_wheel(i, options, page_height, &mut viewport.trackpad_gesture, &mut viewport.trackpad_coast, trackpad_orbit));
|
||||
let raw = ui.input(|i| {
|
||||
immediate_wheel(i, options, page_height, &mut viewport.trackpad_gesture, &mut viewport.trackpad_coast, trackpad_orbit, zoom_modifier)
|
||||
});
|
||||
if raw.modifier_scroll {
|
||||
// Apply modifier scroll once, without egui's scroll smoothing or its tail.
|
||||
app.viewport.wheel_zoom_raw_until_idle = true;
|
||||
}
|
||||
if trackpad_pan && (raw.pan != egui::Vec2::ZERO || raw.shift_pan != egui::Vec2::ZERO) {
|
||||
// Swallow egui's smoothing tail while the trackpad runs (a wheel-only
|
||||
// tail ends the moment trackpad input starts; mixed input is rare).
|
||||
@@ -535,9 +573,9 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
raw.zoom + if trackpad_pan { 0.0 } else { raw.point_zoom }
|
||||
} else {
|
||||
scroll
|
||||
};
|
||||
} + raw.modifier_zoom;
|
||||
// Pinch-to-zoom (trackpad): direct manipulation, never smoothed.
|
||||
let pinch = ui.input(|i| pinch_factor(i, options, page_height));
|
||||
let pinch = ui.input(|i| pinch_factor(i, options, page_height, zoom_modifier));
|
||||
let h = rect.height().max(1.0) as f64;
|
||||
if inside && pinch != 1.0 {
|
||||
app.viewport.orbit_free = None;
|
||||
@@ -555,7 +593,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
app.cam.zoom_at(f, anchor);
|
||||
}
|
||||
}
|
||||
if inside && scroll != 0.0 {
|
||||
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 anchor = zoom_anchor(app, rect, hover, caps.orbit);
|
||||
@@ -571,7 +609,7 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e
|
||||
}
|
||||
}
|
||||
// Two-finger scroll pans the model with the fingers.
|
||||
if inside && pan != egui::Vec2::ZERO {
|
||||
if inside && pan.is_finite() && pan != egui::Vec2::ZERO {
|
||||
app.viewport.orbit_free = None;
|
||||
if app.preferences.nav == crate::prefs::TOUCHPAD_NAV {
|
||||
camera_motion(app, rect, json!({"motion":"pan","delta":[pan.x,pan.y]}));
|
||||
@@ -1045,7 +1083,66 @@ mod tests {
|
||||
let events = raw.events.clone();
|
||||
let mut input = egui::InputState::default();
|
||||
input.events = raw.events;
|
||||
(super::immediate_wheel(&input, egui::InputOptions::default(), 600.0, gesture, &mut Default::default(), false), events)
|
||||
(
|
||||
super::immediate_wheel(
|
||||
&input,
|
||||
egui::InputOptions::default(),
|
||||
600.0,
|
||||
gesture,
|
||||
&mut Default::default(),
|
||||
false,
|
||||
Some(egui::Modifiers::COMMAND),
|
||||
),
|
||||
events,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modifier_zoom_routes_only_the_chosen_key_and_vertical_points() {
|
||||
use egui::{Modifiers as M, MouseWheelUnit as U, TouchPhase as P, vec2};
|
||||
let options = egui::InputOptions::default();
|
||||
for chosen in [Some(M::COMMAND), Some(M::ALT), Some(M::CTRL), None] {
|
||||
for held in [
|
||||
M::COMMAND,
|
||||
M::CTRL | M::COMMAND,
|
||||
M::MAC_CMD | M::COMMAND,
|
||||
M::CTRL,
|
||||
M::ALT,
|
||||
M::SHIFT,
|
||||
M::COMMAND | M::SHIFT,
|
||||
M::COMMAND | M::ALT,
|
||||
M::MAC_CMD | M::COMMAND | M::CTRL,
|
||||
M::ALT | M::SHIFT,
|
||||
] {
|
||||
for unit in [U::Point, U::Line, U::Page] {
|
||||
for bracket in [false, true] {
|
||||
let event = |phase| egui::Event::MouseWheel { unit, delta: vec2(8.0, 12.0), modifiers: held, phase };
|
||||
let mut input = egui::InputState::default();
|
||||
input.events = if bracket { vec![event(P::Start), event(P::Move), event(P::End)] } else { vec![event(P::Move)] };
|
||||
let raw = super::immediate_wheel(&input, options, 600.0, &mut false, &mut Default::default(), true, chosen);
|
||||
let expected = match chosen {
|
||||
Some(m) if m == M::COMMAND => [M::COMMAND, M::CTRL | M::COMMAND, M::MAC_CMD | M::COMMAND].contains(&held),
|
||||
Some(m) if m == M::CTRL => [M::CTRL, M::CTRL | M::COMMAND].contains(&held),
|
||||
Some(m) if m == M::ALT => held == M::ALT,
|
||||
_ => false,
|
||||
};
|
||||
let scale = match unit {
|
||||
U::Point => 1.0,
|
||||
U::Line => options.line_scroll_speed,
|
||||
U::Page => 600.0,
|
||||
};
|
||||
assert_eq!(raw.modifier_zoom, if expected { 12.0 * scale } else { 0.0 }, "chosen={chosen:?}, held={held:?}");
|
||||
if expected {
|
||||
assert_eq!(raw.pan, egui::Vec2::ZERO);
|
||||
assert_eq!(raw.mouse_pan, egui::Vec2::ZERO);
|
||||
assert_eq!(raw.zoom, 0.0);
|
||||
assert_eq!(raw.point_zoom, 0.0);
|
||||
assert_eq!(raw.shift_pan, egui::Vec2::ZERO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1111,7 +1208,7 @@ mod tests {
|
||||
assert_eq!(events.last(), Some(&egui::Event::Zoom(1.1)));
|
||||
let mut input = egui::InputState::default();
|
||||
input.events = events;
|
||||
assert!((super::pinch_factor(&input, egui::InputOptions::default(), 600.0) - 1.1).abs() < 1e-6);
|
||||
assert!((super::pinch_factor(&input, egui::InputOptions::default(), 600.0, None) - 1.1).abs() < 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1795,7 +1892,7 @@ mod tests {
|
||||
modifiers: egui::Modifiers::CTRL,
|
||||
phase,
|
||||
}];
|
||||
assert_eq!(super::pinch_factor(&input, egui::InputOptions::default(), 600.0), 1.0, "{phase:?} is a gesture boundary, not movement");
|
||||
assert_eq!(super::pinch_factor(&input, egui::InputOptions::default(), 600.0, None), 1.0, "{phase:?} is a gesture boundary, not movement");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1808,7 +1905,7 @@ mod tests {
|
||||
let factor = |events: Vec<Event>| {
|
||||
let mut input = egui::InputState::default();
|
||||
input.events = events;
|
||||
super::pinch_factor(&input, options, 600.0)
|
||||
super::pinch_factor(&input, options, 600.0, None)
|
||||
};
|
||||
let wheel = |unit, delta, modifiers| Event::MouseWheel { unit, delta, modifiers, phase: TouchPhase::Move };
|
||||
let close = |a: f32, b: f32| (a - b).abs() < 1e-4;
|
||||
|
||||
@@ -553,6 +553,40 @@ pub enum OrbitAround {
|
||||
Cursor,
|
||||
}
|
||||
|
||||
/// The sole modifier that turns vertical scroll into wheel-style zoom.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TrackpadZoomModifier {
|
||||
Cmd,
|
||||
Alt,
|
||||
Ctrl,
|
||||
/// The default: scroll keeps its usual meaning until a key is chosen.
|
||||
#[default]
|
||||
Off,
|
||||
}
|
||||
|
||||
impl TrackpadZoomModifier {
|
||||
pub const ALL: [Self; 4] = [Self::Cmd, Self::Alt, Self::Ctrl, Self::Off];
|
||||
|
||||
pub fn modifiers(self) -> Option<egui::Modifiers> {
|
||||
match self {
|
||||
Self::Cmd => Some(egui::Modifiers::COMMAND),
|
||||
Self::Alt => Some(egui::Modifiers::ALT),
|
||||
Self::Ctrl => Some(egui::Modifiers::CTRL),
|
||||
Self::Off => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn label_id(self, platform: crate::tool_modifiers::Platform) -> &'static str {
|
||||
match self {
|
||||
Self::Cmd if platform == crate::tool_modifiers::Platform::Mac => "prefs.trackpad_zoom_modifier.cmd",
|
||||
Self::Alt => "prefs.trackpad_zoom_modifier.alt",
|
||||
Self::Cmd | Self::Ctrl => "prefs.trackpad_zoom_modifier.ctrl",
|
||||
Self::Off => "prefs.trackpad_zoom_modifier.off",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the view goes when a sketch ends (Preferences: "When a sketch ends", #7038).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
@@ -1052,6 +1086,8 @@ preference_settings! {
|
||||
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.
|
||||
trackpad_pan: bool = true, PAGE_NAVIGATION;
|
||||
/// Hold this modifier alone to zoom with vertical wheel or two-finger scroll.
|
||||
trackpad_zoom_modifier: TrackpadZoomModifier = TrackpadZoomModifier::default(), PAGE_NAVIGATION;
|
||||
/// Horizontal trackpad and thumb-wheel scrolling pans the view the other way (#2007).
|
||||
pan_reverse_x: bool = false, PAGE_NAVIGATION => check("Reverse horizontal pan direction", "Horizontal two-finger scrolling and the thumb wheel pan the other way");
|
||||
/// Vertical trackpad scrolling pans the view the other way (#5240).
|
||||
@@ -3278,6 +3314,37 @@ pub(crate) fn reveal_preference(h: &mut crate::scenario::Harness, handle: &str)
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn trackpad_zoom_modifier_roundtrips_and_validates_control_values() {
|
||||
assert_eq!(Prefs::default().trackpad_zoom_modifier, TrackpadZoomModifier::Off);
|
||||
let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default());
|
||||
for (id, value) in [
|
||||
("cmd", TrackpadZoomModifier::Cmd),
|
||||
("alt", TrackpadZoomModifier::Alt),
|
||||
("ctrl", TrackpadZoomModifier::Ctrl),
|
||||
("off", TrackpadZoomModifier::Off),
|
||||
] {
|
||||
set(&mut app, &json!({"trackpad_zoom_modifier": id})).unwrap();
|
||||
assert_eq!(app.preferences.trackpad_zoom_modifier, value);
|
||||
let saved = serde_json::to_value(&app.preferences).unwrap();
|
||||
assert_eq!(saved["trackpad_zoom_modifier"], id);
|
||||
assert_eq!(lenient(&saved).trackpad_zoom_modifier, value);
|
||||
let mut restored = SolveApp::new(solidcraft_engine::Session::default(), Default::default());
|
||||
restored.load_prefs(&app.prefs());
|
||||
assert_eq!(restored.preferences.trackpad_zoom_modifier, value);
|
||||
}
|
||||
for invalid in [json!("super"), json!(""), json!(42), json!(null)] {
|
||||
assert!(set(&mut app, &json!({"trackpad_zoom_modifier": invalid})).is_err());
|
||||
assert_eq!(app.preferences.trackpad_zoom_modifier, TrackpadZoomModifier::Off);
|
||||
assert_eq!(lenient(&json!({"trackpad_zoom_modifier": invalid})).trackpad_zoom_modifier, TrackpadZoomModifier::Off);
|
||||
}
|
||||
app.load_prefs(&json!({"preferences": {"trackpad_zoom_modifier": "future"}}).to_string());
|
||||
assert_eq!(app.preferences.trackpad_zoom_modifier, TrackpadZoomModifier::Off);
|
||||
app.preferences.trackpad_zoom_modifier = TrackpadZoomModifier::Cmd;
|
||||
reset_preferences(&mut app.preferences, PAGE_NAVIGATION);
|
||||
assert_eq!(app.preferences.trackpad_zoom_modifier, TrackpadZoomModifier::Off);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn navigation_bar_preferences_round_trip_and_recover_hostile_fields() {
|
||||
use crate::navigation_bar::{Edge, Idle, Labels, NavigationBar, Position, Size};
|
||||
|
||||
@@ -138,6 +138,25 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
|
||||
setting::direct_interaction(app, ui);
|
||||
});
|
||||
});
|
||||
ui_kit::row(ui, app.tr("prefs.trackpad_zoom_modifier"), |ui| {
|
||||
let platform = crate::tool_modifiers::Platform::of(ui.ctx());
|
||||
let choice = &mut app.preferences.trackpad_zoom_modifier;
|
||||
ui_kit::dropdown_menu(ui, "pref_trackpad_zoom_modifier", crate::i18n::tr(choice.label_id(platform)), |ui| {
|
||||
for (index, value) in TrackpadZoomModifier::ALL.into_iter().enumerate() {
|
||||
if ui_kit::list_picker(
|
||||
ui,
|
||||
&format!("trackpad_zoom_modifier_{index}"),
|
||||
crate::i18n::tr(value.label_id(platform)),
|
||||
*choice == value,
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
*choice = value;
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_hover_text(crate::i18n::tr("prefs.trackpad_zoom_modifier.help"));
|
||||
});
|
||||
let cursor = ui_kit::checkbox(ui, crate::i18n::tr_label("Show tool at cursor"), &mut app.ui.tool_cursor);
|
||||
crate::scenario::publish_target("view:tool_cursor", cursor.rect);
|
||||
ui_kit::divider(ui, "navigation_view_controls");
|
||||
|
||||
@@ -9370,6 +9370,139 @@ mod tests {
|
||||
assert_eq!(h.app.cam, after);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trackpad_zoom_modifier_zooms_without_pan_or_tail() {
|
||||
use crate::prefs::TrackpadZoomModifier as Z;
|
||||
use egui::{Modifiers as M, MouseWheelUnit as U, TouchPhase as P};
|
||||
for preset in ["fusion", crate::prefs::TOUCHPAD_NAV] {
|
||||
for (chosen, held, zooms) in [
|
||||
(Z::Cmd, M::COMMAND, true),
|
||||
(Z::Off, M::COMMAND, false),
|
||||
(Z::Alt, M::ALT, true),
|
||||
(Z::Alt, M::COMMAND, false),
|
||||
(Z::Ctrl, M::CTRL, true),
|
||||
] {
|
||||
for bracket in [true, false] {
|
||||
for reverse in [false, true] {
|
||||
// Run the same input with the given choice; a key that is not chosen
|
||||
// must leave main's own handling (Cmd/Ctrl + wheel is a pinch, #8480) unchanged.
|
||||
let run = |choice| {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.preferences.nav = preset.into();
|
||||
h.app.preferences.trackpad_zoom_modifier = choice;
|
||||
h.app.preferences.zoom_reverse = reverse;
|
||||
h.app.preferences.zoom_to_cursor = false;
|
||||
h.call("ui.move", json!({"x":800,"y":500}));
|
||||
let before = h.app.cam;
|
||||
let event = |phase| egui::Event::MouseWheel { unit: U::Point, delta: vec2(60.0, 120.0), modifiers: held, phase };
|
||||
if bracket {
|
||||
h.app.synthetic.push(event(P::Start));
|
||||
h.frame();
|
||||
}
|
||||
h.app.synthetic.push(event(P::Move));
|
||||
h.frame();
|
||||
if bracket {
|
||||
h.app.synthetic.push(event(P::End));
|
||||
h.frame();
|
||||
}
|
||||
(h, before)
|
||||
};
|
||||
let (mut h, before) = run(chosen);
|
||||
if zooms {
|
||||
let expected = before.half_height() * (-0.18 * crate::prefs::zoom_sign(&h.app)).exp();
|
||||
assert!((h.app.cam.half_height() - expected).abs() < 1e-6, "{preset}, {chosen:?}, {held:?}");
|
||||
assert_eq!(h.app.cam.target, before.target);
|
||||
assert_eq!(h.app.cam.back(), before.back());
|
||||
} else {
|
||||
assert_eq!(h.app.cam, run(Z::Off).0.app.cam, "{preset}, {chosen:?}, {held:?}: unchosen keys keep the default handling");
|
||||
}
|
||||
let after = h.app.cam;
|
||||
h.frames(30);
|
||||
assert_eq!(h.app.cam, after, "modifier scroll must not drift");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trackpad_zoom_modifier_ignores_horizontal_only_scroll() {
|
||||
for chosen in [crate::prefs::TrackpadZoomModifier::Cmd, crate::prefs::TrackpadZoomModifier::Alt] {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.preferences.trackpad_zoom_modifier = chosen;
|
||||
h.call("ui.move", json!({"x":800,"y":500}));
|
||||
let before = h.app.cam;
|
||||
for phase in [egui::TouchPhase::Start, egui::TouchPhase::Move, egui::TouchPhase::End] {
|
||||
h.app.synthetic.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: vec2(120.0, 0.0),
|
||||
modifiers: chosen.modifiers().unwrap(),
|
||||
phase,
|
||||
});
|
||||
h.frame();
|
||||
}
|
||||
h.frames(30);
|
||||
assert_eq!(h.app.cam, before, "{chosen:?}: horizontal scroll must be ignored");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trackpad_zoom_modifier_matches_wheel_speed_and_pointer_anchor() {
|
||||
for preset in ["fusion", crate::prefs::TOUCHPAD_NAV] {
|
||||
for unit in [egui::MouseWheelUnit::Point, egui::MouseWheelUnit::Line] {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.preferences.nav = preset.into();
|
||||
h.app.preferences.smooth_wheel_zoom = false;
|
||||
h.app.preferences.trackpad_zoom_modifier = crate::prefs::TrackpadZoomModifier::Cmd;
|
||||
h.call("engine.execute", json!({"command":"solid.box","params":{"length":40,"width":30,"height":20}}));
|
||||
h.call("ui.camera", json!({"fit":true}));
|
||||
h.call("ui.move", json!({"x":800,"y":500}));
|
||||
let before = h.app.cam;
|
||||
let event = |modifiers| egui::Event::MouseWheel {
|
||||
unit,
|
||||
delta: vec2(0.0, if unit == egui::MouseWheelUnit::Point { 120.0 } else { 3.0 }),
|
||||
modifiers,
|
||||
phase: egui::TouchPhase::Move,
|
||||
};
|
||||
h.app.synthetic.push(event(egui::Modifiers::NONE));
|
||||
h.frame();
|
||||
let wheel = h.app.cam;
|
||||
h.frames(30);
|
||||
h.app.cam = before;
|
||||
h.step(&json!({"shot":"trackpad-zoom-modifier-before"})).unwrap();
|
||||
h.app.synthetic.push(event(egui::Modifiers::COMMAND));
|
||||
h.frame();
|
||||
assert_eq!(h.app.cam, wheel, "{preset}, {unit:?}: same speed and cursor anchor as wheel");
|
||||
assert_ne!(h.app.cam.target, before.target, "off-centre zoom must preserve its pointer anchor");
|
||||
h.step(&json!({"shot":"trackpad-zoom-modifier-after"})).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trackpad_zoom_modifier_rejects_nonfinite_scroll() {
|
||||
for preset in ["fusion", crate::prefs::TOUCHPAD_NAV] {
|
||||
for invalid in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY] {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.preferences.nav = preset.into();
|
||||
h.call("ui.move", json!({"x":800,"y":500}));
|
||||
let before = h.app.cam;
|
||||
for phase in [egui::TouchPhase::Start, egui::TouchPhase::Move, egui::TouchPhase::End] {
|
||||
h.app.synthetic.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: vec2(0.0, invalid),
|
||||
modifiers: egui::Modifiers::COMMAND,
|
||||
phase,
|
||||
});
|
||||
h.frame();
|
||||
}
|
||||
h.frames(10);
|
||||
assert!(h.app.cam.is_valid());
|
||||
assert_eq!(h.app.cam, before);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trackpad_two_finger_scroll_pans_without_zooming() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
off: scroll zooms like the wheel); mouse wheels zoom and the thumb wheel pans sideways.
|
||||
On Linux, pinch needs the native Wayland window system
|
||||
(see [Troubleshooting](troubleshooting.md)).
|
||||
To zoom with vertical two-finger scroll while holding a key, choose the key in Navigation › Zoom with two-finger scroll while holding (Cmd on macOS or Ctrl on Windows/Linux, Alt, or Control). It is off until you choose one.
|
||||
With the **Fusion** preset and two-finger pan enabled, hold **Shift** while scrolling with
|
||||
two fingers to orbit freely instead of panning. No click is needed. Releasing Shift returns
|
||||
to panning, even during the same gesture. Shift does not snap this gesture to standard views;
|
||||
|
||||
@@ -394,6 +394,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own
|
||||
- `timeline_origin_bodies` (default false: the History on the left or under the browser starts with the active component's Bodies folder and the Origin, the browser's rows with their eyes, folds and menus; the bottom History is unchanged)
|
||||
- `toast_place` (`corner` (default: notices and offers stack in one column in the view's bottom-right corner, each 340 points wide, buttons right-aligned with the main action right-most, #7893), `centre` (at the bottom centre above the view toolbar, each as wide as its text, as before))
|
||||
- `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms)
|
||||
- `trackpad_zoom_modifier` (`off` default, `cmd`, `alt`, or `ctrl`: hold this key alone for vertical scroll to zoom)
|
||||
- `ui_font` (an installed font family or a font file for the interface; empty for the built-in font)
|
||||
- `ui_scale`
|
||||
- `up_axis` (`z`, `y`)
|
||||
|
||||
Reference in New Issue
Block a user