forked from 1b-agent/opencadstudio-upstream
feat(viewport): optional touchpad pan for wheel-scrolling touchpads
Outside macOS a touchpad's two-finger drag arrives as wheel scrolls that nothing tells from a wheel. A new option (Options, off by default) makes every scroll pan and Ctrl+scroll — what a pinch sends there — zoom. Fixes #1560 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
17d2954098
commit
69057c55da
29 files changed
+83
-11
No files matched your search
@@ -559,6 +559,8 @@ pub(super) struct OpenCADStudio {
|
||||
polar_increment_deg: f32,
|
||||
/// Reverse the mouse-wheel zoom direction when true (ZOOMWHEEL = 1).
|
||||
zoom_wheel_reversed: bool,
|
||||
/// Scroll pans and Ctrl+scroll zooms (touchpads); see `scroll_intent`.
|
||||
touchpad_pan: bool,
|
||||
/// Mouse-wheel zoom sensitivity (ZOOMFACTOR), held inside
|
||||
/// `settings::ZOOM_FACTOR_MIN..=settings::ZOOM_FACTOR_MAX`. `SETVAR`
|
||||
/// only sets the range the system variable itself has; the Options
|
||||
@@ -2375,6 +2377,7 @@ pub enum Message {
|
||||
CommandLineFadeChanged(i32),
|
||||
/// Toggle reversing the mouse-wheel zoom direction (ZOOMWHEEL).
|
||||
ZoomWheelReversedChanged(bool),
|
||||
TouchpadPanChanged(bool),
|
||||
/// Change how far one wheel notch zooms, from the Options slider
|
||||
/// (ZOOMFACTOR).
|
||||
ZoomFactorChanged(i32),
|
||||
@@ -4157,6 +4160,7 @@ impl OpenCADStudio {
|
||||
polar_mode: false,
|
||||
polar_increment_deg: 45.0,
|
||||
zoom_wheel_reversed: false,
|
||||
touchpad_pan: false,
|
||||
zoom_factor: 60,
|
||||
zoom_factor_input: 60.to_string(),
|
||||
cursor_size: 5,
|
||||
|
||||
@@ -388,6 +388,9 @@ pub struct UserSettings {
|
||||
pub polar: bool,
|
||||
pub polar_increment_deg: f32,
|
||||
pub zoom_wheel_reversed: bool,
|
||||
/// Scrolling pans and Ctrl+scroll (a touchpad pinch) zooms, for a
|
||||
/// touchpad that reports two-finger drags as wheel scrolls.
|
||||
pub touchpad_pan: bool,
|
||||
pub zoom_factor: i32,
|
||||
/// CURSORSIZE: normalized crosshair reach; 5 retains the original 60 px arms.
|
||||
pub cursor_size: i32,
|
||||
@@ -807,6 +810,7 @@ impl Default for UserSettings {
|
||||
polar: false,
|
||||
polar_increment_deg: 45.0,
|
||||
zoom_wheel_reversed: false,
|
||||
touchpad_pan: false,
|
||||
zoom_factor: 60,
|
||||
cursor_size: 5,
|
||||
pick_box: 3,
|
||||
|
||||
@@ -662,6 +662,7 @@ impl OpenCADStudio {
|
||||
polar: self.polar_mode,
|
||||
polar_increment_deg: self.polar_increment_deg,
|
||||
zoom_wheel_reversed: self.zoom_wheel_reversed,
|
||||
touchpad_pan: self.touchpad_pan,
|
||||
zoom_factor: self.zoom_factor,
|
||||
cursor_size: self.cursor_size,
|
||||
pick_box: self.pick_box,
|
||||
@@ -762,6 +763,7 @@ impl OpenCADStudio {
|
||||
self.polar_mode = s.polar;
|
||||
self.polar_increment_deg = s.polar_increment_deg;
|
||||
self.zoom_wheel_reversed = s.zoom_wheel_reversed;
|
||||
self.touchpad_pan = s.touchpad_pan;
|
||||
self.zoom_factor = crate::app::settings::clamp_zoom_factor(s.zoom_factor);
|
||||
// Like the drafting-rotation field below, the Options field edits a
|
||||
// buffer rather than the value, so it is reseeded whenever the value
|
||||
|
||||
@@ -8383,6 +8383,12 @@ impl OpenCADStudio {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::TouchpadPanChanged(enabled) => {
|
||||
self.touchpad_pan = enabled;
|
||||
self.persist_settings_if_changed();
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::ZoomFactorChanged(factor) => {
|
||||
self.zoom_factor = crate::app::settings::clamp_zoom_factor(factor);
|
||||
// The field beside the slider reads the same value, so the
|
||||
|
||||
+33
-11
@@ -42,9 +42,6 @@ enum ScrollIntent {
|
||||
Zoom { notches: f32 },
|
||||
/// Trackpad movement to pan by, in screen pixels.
|
||||
///
|
||||
/// Built only where a pixel delta can only mean a trackpad, so it has no
|
||||
/// constructor on the other targets.
|
||||
#[cfg_attr(not(target_os = "macos"), allow(dead_code))]
|
||||
Pan { dx: f32, dy: f32 },
|
||||
}
|
||||
|
||||
@@ -55,11 +52,22 @@ const ZOOM_DIR_FLIP_PX: f32 = 2.0;
|
||||
|
||||
/// A wheel notch zooms; a trackpad's two fingers pan.
|
||||
///
|
||||
/// A wheel reports notches, a precise-scrolling device reports pixels, and that
|
||||
/// is the whole distinction — there is no modifier to check and no setting to
|
||||
/// read. The pixels only mean "trackpad" on macOS: the browser build reports
|
||||
/// every wheel notch as pixels too, so everywhere else they keep zooming.
|
||||
fn scroll_intent(delta: mouse::ScrollDelta) -> ScrollIntent {
|
||||
/// On macOS a wheel reports notches and a trackpad pixels, and that is the
|
||||
/// whole distinction. Elsewhere a touchpad's two-finger drag arrives as wheel
|
||||
/// notches (the browser build reports every wheel as pixels), so nothing tells
|
||||
/// it from a wheel: with `touchpad_pan` on, every scroll pans and Ctrl+scroll —
|
||||
/// what a pinch sends there — zooms.
|
||||
fn scroll_intent(delta: mouse::ScrollDelta, touchpad_pan: bool, ctrl: bool) -> ScrollIntent {
|
||||
/// Screen pixels one wheel line pans.
|
||||
const LINE_PX: f32 = 40.0;
|
||||
if touchpad_pan && !ctrl {
|
||||
return match delta {
|
||||
mouse::ScrollDelta::Pixels { x, y } => ScrollIntent::Pan { dx: x, dy: y },
|
||||
mouse::ScrollDelta::Lines { x, y } => {
|
||||
ScrollIntent::Pan { dx: x * LINE_PX, dy: y * LINE_PX }
|
||||
}
|
||||
};
|
||||
}
|
||||
match delta {
|
||||
// Both axes go straight through: the two-finger gesture moves the
|
||||
// drawing the same way the middle-button drag moves it. If a pan ever
|
||||
@@ -5673,7 +5681,7 @@ properties={:.1}ms picked={}",
|
||||
/// A wheel notch zooms; a trackpad's two fingers pan. Which one a delta
|
||||
/// means is `scroll_intent`'s call.
|
||||
pub(super) fn on_viewport_scroll(&mut self, delta: mouse::ScrollDelta) -> Task<Message> {
|
||||
match scroll_intent(delta) {
|
||||
match scroll_intent(delta, self.touchpad_pan, self.ctrl_down) {
|
||||
ScrollIntent::Zoom { notches } => {
|
||||
let mut s =
|
||||
notches * crate::app::settings::zoom_notch_steps(self.zoom_factor);
|
||||
@@ -6701,10 +6709,24 @@ mod scroll_intent_tests {
|
||||
use crate::scene::view::camera::Camera;
|
||||
use iced::mouse::ScrollDelta;
|
||||
|
||||
/// With the touchpad option, a scroll pans (wheel lines as pixels) and
|
||||
/// Ctrl+scroll — a pinch — still zooms.
|
||||
#[test]
|
||||
fn touchpad_pan_scrolls_pan_and_ctrl_zooms() {
|
||||
assert_eq!(
|
||||
scroll_intent(ScrollDelta::Lines { x: 0.5, y: -0.25 }, true, false),
|
||||
ScrollIntent::Pan { dx: 20.0, dy: -10.0 }
|
||||
);
|
||||
assert_eq!(
|
||||
scroll_intent(ScrollDelta::Lines { x: 0.0, y: 1.0 }, true, true),
|
||||
ScrollIntent::Zoom { notches: 1.0 }
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wheel_notches_zoom() {
|
||||
assert_eq!(
|
||||
scroll_intent(ScrollDelta::Lines { x: 0.0, y: 1.0 }),
|
||||
scroll_intent(ScrollDelta::Lines { x: 0.0, y: 1.0 }, false, false),
|
||||
ScrollIntent::Zoom { notches: 1.0 }
|
||||
);
|
||||
}
|
||||
@@ -6715,7 +6737,7 @@ mod scroll_intent_tests {
|
||||
#[test]
|
||||
fn two_finger_scroll_pans() {
|
||||
assert_eq!(
|
||||
scroll_intent(ScrollDelta::Pixels { x: 4.0, y: 6.0 }),
|
||||
scroll_intent(ScrollDelta::Pixels { x: 4.0, y: 6.0 }, false, false),
|
||||
ScrollIntent::Pan { dx: 4.0, dy: 6.0 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -316,6 +316,7 @@ impl OpenCADStudio {
|
||||
cliprompt_lines: self.cliprompt_lines,
|
||||
commandline_fade_ms: self.commandline_fade_ms,
|
||||
zoom_wheel_reversed: self.zoom_wheel_reversed,
|
||||
touchpad_pan: self.touchpad_pan,
|
||||
zoom_factor: self.zoom_factor,
|
||||
texteditmode: self.texteditmode,
|
||||
dimension_continue_mode: self.dimension_continue_mode,
|
||||
|
||||
@@ -4797,6 +4797,7 @@ pub(super) fn message_attribute(source: &str) -> Option<(&'static str, &'static
|
||||
"User Preferences" => Some(("common", "user-preferences")),
|
||||
"Zoom" => Some(("common", "zoom")),
|
||||
"Reverse mouse wheel zoom (ZOOMWHEEL)" => Some(("common", "reverse-mouse-wheel-zoom-zoomwheel")),
|
||||
"Touchpad: scroll pans, Ctrl+scroll or pinch zooms" => Some(("common", "touchpad-scroll-pans-ctrl-scroll-or-pinch-zooms")),
|
||||
"Zoom factor" => Some(("common", "zoom-factor")),
|
||||
"How far one wheel notch zooms (ZOOMFACTOR)." => Some(("common", "how-far-one-wheel-notch-zooms-zoomfactor")),
|
||||
"Text and Dimensions" => Some(("common", "text-and-dimensions")),
|
||||
|
||||
@@ -59,6 +59,8 @@ pub struct AppPrefs {
|
||||
pub commandline_fade_ms: i32,
|
||||
/// ZOOMWHEEL: reverse the mouse-wheel zoom direction.
|
||||
pub zoom_wheel_reversed: bool,
|
||||
/// Scroll pans and Ctrl+scroll zooms (touchpads).
|
||||
pub touchpad_pan: bool,
|
||||
/// ZOOMFACTOR. The slider sets the range the system variable has; the
|
||||
/// field beside it reaches `settings::ZOOM_FACTOR_MAX`.
|
||||
pub zoom_factor: i32,
|
||||
@@ -1254,6 +1256,15 @@ pub fn view_window<'a>(
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(iced::Center),
|
||||
Space::new().height(8),
|
||||
row![
|
||||
iced::widget::checkbox(prefs.touchpad_pan)
|
||||
.on_toggle(Message::TouchpadPanChanged)
|
||||
.size(15),
|
||||
text(crate::t!("Touchpad: scroll pans, Ctrl+scroll or pinch zooms")).size(12),
|
||||
]
|
||||
.spacing(8)
|
||||
.align_y(iced::Center),
|
||||
Space::new().height(12),
|
||||
row![
|
||||
text(crate::t!("Zoom factor")).size(12).width(150),
|
||||
|
||||
Reference in new issue
Block a user