diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 16:32:12 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 16:32:12 +0100 |
| commit | aec36a8d6087266a2c9c7569314e2306f2dcf298 (patch) | |
| tree | 12287d4df8fc39808505530e5aba9cb655854831 | |
| parent | dbc12469028bb7d927fcd8bc1be3bcbc1bf63365 (diff) | |
web: mobile fixes — pinch zoom, dynamic viewport height, wider accept
- two-finger pinch on the viewport canvas: pointer table tracks all
active pointers; pinch emits zoom anchored at the finger midpoint
plus pan by the midpoint delta; a second finger cancels an in-flight
pan/marker drag, the remaining finger resumes panning, and pinch
gestures never fire a click
- 100dvh (with 100vh fallback) for the app shell: on mobile browsers
100vh includes the area behind the dynamic URL bar, which pushed
the compass strip below the visible fold
- file input accepts image/* so Android pickers offer all photos and
transcode exotic formats (HEIC) to decodable ones
| -rw-r--r-- | crates/wipfel/src/app.rs | 2 | ||||
| -rw-r--r-- | crates/wipfel/src/canvas_view.rs | 88 | ||||
| -rw-r--r-- | crates/wipfel/www/style.css | 4 | ||||
| -rw-r--r-- | dist/wipfel/style.css | 4 | ||||
| -rw-r--r-- | dist/wipfel/wipfel.js | 4 | ||||
| -rw-r--r-- | dist/wipfel/wipfel_bg.wasm | bin | 507713 -> 508958 bytes |
6 files changed, 92 insertions, 10 deletions
diff --git a/crates/wipfel/src/app.rs b/crates/wipfel/src/app.rs index d2a66cb..cc9f558 100644 --- a/crates/wipfel/src/app.rs +++ b/crates/wipfel/src/app.rs @@ -870,7 +870,7 @@ pub fn app() -> Html { <input type="file" ref={file_ref} - accept="image/jpeg,image/png" + accept="image/*" class="hidden-file" onchange={on_file_change} /> diff --git a/crates/wipfel/src/canvas_view.rs b/crates/wipfel/src/canvas_view.rs index 9ec2267..b962f17 100644 --- a/crates/wipfel/src/canvas_view.rs +++ b/crates/wipfel/src/canvas_view.rs @@ -96,6 +96,10 @@ struct DragState { last: (f64, f64), start: (f64, f64), moved: bool, + /// all active pointers (id, client position); >1 while pinching + pts: Vec<(i32, (f64, f64))>, + /// pinch geometry: (distance, center x, center y), canvas-relative + pinch: Option<(f64, f64, f64)>, } #[function_component(CanvasView)] @@ -105,6 +109,8 @@ pub fn canvas_view(props: &Props) -> Html { last: (0.0, 0.0), start: (0.0, 0.0), moved: false, + pts: Vec::new(), + pinch: None, }); // redraw on every view/bitmap/marker change and on resize ticks @@ -397,21 +403,71 @@ pub fn canvas_view(props: &Props) -> Html { } let pos = (e.client_x() as f64, e.client_y() as f64); let mut d = drag.borrow_mut(); - d.mode = Some(mode); - d.last = pos; - d.start = pos; - d.moved = false; + d.pts.push((e.pointer_id(), pos)); + if d.pts.len() >= 2 { + // second finger: switch to pinch, cancel any pan/marker + // drag so the view does not jump + d.mode = None; + d.pinch = None; + d.moved = true; + } else { + d.mode = Some(mode); + d.last = pos; + d.start = pos; + d.moved = false; + } }) }; let on_pointermove = { let drag = drag.clone(); let pan_cb = props.callbacks.pan.clone(); + let zoom_cb = props.callbacks.zoom.clone(); let marker_drag = props.callbacks.marker_drag.clone(); let hover = props.callbacks.hover.clone(); let to_img = to_img.clone(); + let canvas_ref = props.canvas_ref.clone(); let scale = props.view.scale; Callback::from(move |e: PointerEvent| { + // update the pointer table and handle two-finger pinch + let pinch_ev = { + let mut d = drag.borrow_mut(); + if let Some(p) = d.pts.iter_mut().find(|(id, _)| *id == e.pointer_id()) { + p.1 = (e.client_x() as f64, e.client_y() as f64); + } + if d.pts.len() >= 2 { + let (x1, y1) = d.pts[0].1; + let (x2, y2) = d.pts[1].1; + let rect = canvas_ref + .cast::<HtmlCanvasElement>() + .map(|c| c.get_bounding_client_rect()); + let (rl, rt) = match rect { + Some(r) => (r.left(), r.top()), + None => (0.0, 0.0), + }; + let dist = ((x2 - x1).powi(2) + (y2 - y1).powi(2)).sqrt(); + let cx = (x1 + x2) / 2.0 - rl; + let cy = (y1 + y2) / 2.0 - rt; + let ev = match d.pinch { + Some((od, ocx, ocy)) if od > 1.0 && dist > 1.0 => { + Some((dist / od, cx, cy, cx - ocx, cy - ocy)) + } + _ => None, + }; + d.pinch = Some((dist, cx, cy)); + d.moved = true; + Some(ev) + } else { + None + } + }; + if let Some(ev) = pinch_ev { + if let Some((factor, cx, cy, dx, dy)) = ev { + zoom_cb.emit((cx, cy, factor)); + pan_cb.emit((dx, dy)); + } + return; + } let mut d = drag.borrow_mut(); let mode = match &d.mode { Some(m) => m.clone(), @@ -451,11 +507,26 @@ pub fn canvas_view(props: &Props) -> Html { let drag_end = props.callbacks.drag_end.clone(); let to_img = to_img.clone(); Callback::from(move |e: PointerEvent| { - let mode = drag.borrow_mut().mode.take(); + let (mode, moved) = { + let mut d = drag.borrow_mut(); + d.pts.retain(|(id, _)| *id != e.pointer_id()); + if d.pts.len() < 2 { + d.pinch = None; + } + let mode = d.mode.take(); + let moved = d.moved; + if d.pts.len() == 1 { + // one finger left after pinch: resume panning from + // there, never treat it as a click + d.mode = Some(DragMode::Pan); + d.last = d.pts[0].1; + d.moved = true; + } + (mode, moved) + }; if let Some(c) = canvas_ref.cast::<HtmlCanvasElement>() { let _ = c.release_pointer_capture(e.pointer_id()); } - let moved = drag.borrow().moved; match mode { Some(DragMode::Pan) if !moved => { let (ix, iy) = to_img(e.client_x() as f64, e.client_y() as f64); @@ -470,7 +541,10 @@ pub fn canvas_view(props: &Props) -> Html { let on_pointercancel = { let drag = drag.clone(); Callback::from(move |_: PointerEvent| { - drag.borrow_mut().mode = None; + let mut d = drag.borrow_mut(); + d.mode = None; + d.pts.clear(); + d.pinch = None; }) }; diff --git a/crates/wipfel/www/style.css b/crates/wipfel/www/style.css index d706a8d..a0ffc4d 100644 --- a/crates/wipfel/www/style.css +++ b/crates/wipfel/www/style.css @@ -10,6 +10,10 @@ body { .app { display: flex; height: 100vh; + /* dynamic viewport height: on mobile browsers 100vh includes the + area behind the collapsing URL bar, pushing the compass below the + fold; dvh tracks the actually visible area */ + height: 100dvh; background: #101014; color: #e8e8ea; } diff --git a/dist/wipfel/style.css b/dist/wipfel/style.css index d706a8d..a0ffc4d 100644 --- a/dist/wipfel/style.css +++ b/dist/wipfel/style.css @@ -10,6 +10,10 @@ body { .app { display: flex; height: 100vh; + /* dynamic viewport height: on mobile browsers 100vh includes the + area behind the collapsing URL bar, pushing the compass below the + fold; dvh tracks the actually visible area */ + height: 100dvh; background: #101014; color: #e8e8ea; } diff --git a/dist/wipfel/wipfel.js b/dist/wipfel/wipfel.js index c813102..9119aea 100644 --- a/dist/wipfel/wipfel.js +++ b/dist/wipfel/wipfel.js @@ -594,7 +594,7 @@ function __wbg_get_imports() { return ret; }, __wbindgen_generic_0000000000000002: function(arg0, arg1) { - // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx: 75, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`. + // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Array<any>"), NamedExternref("ResizeObserver")], shim_idx: 74, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`. const ret = makeClosure(arg0, arg1, wasm_bindgen_f1f668f83a5f514b___convert__closures_____invoke___js_sys_351dd7d36d5f7033___Array__web_sys_d6718dd818f67bd6___features__gen_ResizeObserver__ResizeObserver______true_); return ret; }, @@ -604,7 +604,7 @@ function __wbg_get_imports() { return ret; }, __wbindgen_generic_0000000000000004: function(arg0, arg1) { - // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 77, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`. + // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 76, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`. const ret = makeClosure(arg0, arg1, wasm_bindgen_f1f668f83a5f514b___convert__closures_____invoke_______true_); return ret; }, diff --git a/dist/wipfel/wipfel_bg.wasm b/dist/wipfel/wipfel_bg.wasm Binary files differindex 32ce3bc..c89fbba 100644 --- a/dist/wipfel/wipfel_bg.wasm +++ b/dist/wipfel/wipfel_bg.wasm |
