Skip to content

Commit 1eacff1

Browse files
committed
feat: add pinch-to-zoom gesture support
Use Slint's ScaleRotateGestureHandler for native trackpad/touch pinch-to-zoom. Zooms toward the gesture center point. Enabled by default via pinch-zoom-enabled property. Reuses the existing apply-zoom-with-adjustment function — no Rust changes needed.
1 parent 5878d31 commit 1eacff1

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

node-editor.slint

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export component NodeEditor inherits FocusScope {
117117
// === Zoom constraints ===
118118
in property <float> min-zoom: 0.1;
119119
in property <float> max-zoom: 3.0;
120+
/// Enable pinch-to-zoom gesture (trackpad/touch)
121+
in property <bool> pinch-zoom-enabled: true;
120122

121123
// === LOD (Level of Detail) configuration ===
122124
/// Zoom threshold above which nodes render full detail (all widgets)
@@ -539,6 +541,32 @@ export component NodeEditor inherits FocusScope {
539541
viewbox-height: max(self.height / 1px, 1);
540542
}
541543

544+
// Pinch-to-zoom gesture handler (trackpad/touch)
545+
// Placed before TouchArea so it captures gesture events first.
546+
// While active, it grabs input and prevents pan/selection.
547+
pinch-gesture := ScaleRotateGestureHandler {
548+
enabled: root.pinch-zoom-enabled;
549+
550+
property <float> zoom-at-start: 1.0;
551+
property <float> graph-center-x: 0;
552+
property <float> graph-center-y: 0;
553+
554+
started => {
555+
zoom-at-start = root.zoom;
556+
graph-center-x = (self.center.x - root.pan-x) / root.zoom / 1px;
557+
graph-center-y = (self.center.y - root.pan-y) / root.zoom / 1px;
558+
}
559+
560+
updated => {
561+
root.apply-zoom-with-adjustment(
562+
clamp(zoom-at-start * self.scale, root.min-zoom, root.max-zoom),
563+
self.center.x,
564+
self.center.y,
565+
graph-center-x,
566+
graph-center-y);
567+
}
568+
}
569+
542570
// Background TouchArea - handles pan, zoom, box selection, link clicks
543571
background-ta := TouchArea {
544572
width: 100%;

0 commit comments

Comments
 (0)