mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 03:30:04 +00:00
Add macOS trackpad gesture support (#1007)
Adds trackpad gesture support to canvas interaction. Supports: - Pinch to zoom - Two-finger panning Feature is off by default. Also by default, the browser user-agent must include "Mac" (even if the feature has been enabled). ```ts // Enable mac trackpad gestures LiteGraph.macTrackpadGestures = true // Disable the default Mac user-agent check LiteGraph.macGesturesRequireMac = false ```
This commit is contained in:
@@ -2968,8 +2968,21 @@ export class LGraphCanvas {
|
||||
|
||||
let { scale } = this.ds
|
||||
|
||||
if (delta > 0) scale *= this.zoom_speed
|
||||
else if (delta < 0) scale *= 1 / this.zoom_speed
|
||||
if (
|
||||
LiteGraph.macTrackpadGestures &&
|
||||
(!LiteGraph.macGesturesRequireMac || navigator.userAgent.includes("Mac"))
|
||||
) {
|
||||
if (e.ctrlKey && !Number.isInteger(e.deltaY)) {
|
||||
scale *= 1 + e.deltaY * (1 - this.zoom_speed) * 0.18
|
||||
} else {
|
||||
this.ds.offset[0] -= e.deltaX * 1.18 * (1 / scale)
|
||||
this.ds.offset[1] -= e.deltaY * 1.18 * (1 / scale)
|
||||
}
|
||||
} else if (delta > 0) {
|
||||
scale *= this.zoom_speed
|
||||
} else if (delta < 0) {
|
||||
scale *= 1 / (this.zoom_speed)
|
||||
}
|
||||
|
||||
this.ds.changeScale(scale, [e.clientX, e.clientY])
|
||||
|
||||
|
||||
@@ -276,6 +276,22 @@ export class LiteGraphGlobal {
|
||||
*/
|
||||
onDeprecationWarning: ((message: string, source?: object) => void)[] = [console.warn]
|
||||
|
||||
/**
|
||||
* If `true`, mouse wheel events will be interpreted as trackpad gestures.
|
||||
* Tested on MacBook M4 Pro.
|
||||
* @default false
|
||||
* @see macGesturesRequireMac
|
||||
*/
|
||||
macTrackpadGestures: boolean = false
|
||||
|
||||
/**
|
||||
* If both this setting and {@link macTrackpadGestures} are `true`, trackpad gestures will
|
||||
* only be enabled when the browser user agent includes "Mac".
|
||||
* @default true
|
||||
* @see macTrackpadGestures
|
||||
*/
|
||||
macGesturesRequireMac: boolean = true
|
||||
|
||||
// TODO: Remove legacy accessors
|
||||
LGraph = LGraph
|
||||
LLink = LLink
|
||||
|
||||
@@ -158,6 +158,8 @@ LiteGraphGlobal {
|
||||
"do_add_triggers_slots": false,
|
||||
"highlight_selected_group": true,
|
||||
"isInsideRectangle": [Function],
|
||||
"macGesturesRequireMac": true,
|
||||
"macTrackpadGestures": false,
|
||||
"middle_click_slot_add_default_node": false,
|
||||
"node_box_coloured_by_mode": false,
|
||||
"node_box_coloured_when_on": false,
|
||||
|
||||
Reference in New Issue
Block a user