diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 11:48:04 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 11:48:04 +0100 |
| commit | 9e1d138a29aafc52d2da68b66f7d6ea00081134f (patch) | |
| tree | d1a11cc2c192b2418560a61b9bb42fca035d2e4b /crates | |
| parent | 21487476293a77518e81c91ecdc0fbd4c4b74a25 (diff) | |
web: visible guide dots with hover peak identification
- guide dots: dark outline ring + bright core, readable on any photo
- hover over a dot shows 'NAME · height m' in the sidebar (same info
the desktop hover status line gives)
- pointermove doubles as hover report when not dragging
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/gipfel-web/src/app.rs | 23 | ||||
| -rw-r--r-- | crates/gipfel-web/src/canvas_view.rs | 45 | ||||
| -rw-r--r-- | crates/gipfel-web/www/style.css | 5 |
3 files changed, 65 insertions, 8 deletions
diff --git a/crates/gipfel-web/src/app.rs b/crates/gipfel-web/src/app.rs index 8512d6a..f152dcc 100644 --- a/crates/gipfel-web/src/app.rs +++ b/crates/gipfel-web/src/app.rs @@ -38,6 +38,7 @@ pub fn app() -> Html { let pan = use_mut_ref(Panorama::new); let markers = use_state(Vec::<Marker>::new); let fit_distortion = use_state(|| false); + let hover = use_state(|| Option::<String>::None); // force a redraw when the window is resized so the canvas backing // store tracks its CSS size (listener lives as long as the app) @@ -309,6 +310,23 @@ pub fn app() -> Html { } }) }, + hover: { + let pan = pan.clone(); + let view = view.clone(); + let hover = hover.clone(); + Callback::from(move |(ix, iy): (f64, f64)| { + let p = pan.borrow(); + let name = markers::nearest_hill(&p, ix, iy, 20.0 / view.scale).map(|i| { + let h = &p.hills[i]; + format!("{} · {:.0} m", h.name, h.height) + }); + hover.set(name); + }) + }, + hover_end: { + let hover = hover.clone(); + Callback::from(move |_: ()| hover.set(None)) + }, }; // overlay data for the canvas @@ -356,9 +374,12 @@ pub fn app() -> Html { if !fit_info.is_empty() { <p class="fitinfo">{ (*fit_info).clone() }</p> } + if let Some(h) = hover.as_ref() { + <p class="hover">{ h.clone() }</p> + } } <p class="hint"> - { "Click a green dot to mark that peak · drag markers to adjust · right-click a marker to remove." } + { "Hover a green dot to see the peak · click to mark it · drag to adjust · right-click to remove." } </p> <p class="hint dim"> { "The view is fitted automatically once 4+ markers are placed." } diff --git a/crates/gipfel-web/src/canvas_view.rs b/crates/gipfel-web/src/canvas_view.rs index 4282bc0..d870029 100644 --- a/crates/gipfel-web/src/canvas_view.rs +++ b/crates/gipfel-web/src/canvas_view.rs @@ -36,6 +36,10 @@ pub struct ViewCallbacks { pub drag_end: Callback<()>, /// right-click: (x, y) center-relative image coords pub context: Callback<(f64, f64)>, + /// pointer moved over the image (not dragging): (x, y) center-relative + pub hover: Callback<(f64, f64)>, + /// pointer left the canvas + pub hover_end: Callback<()>, } #[derive(Properties, PartialEq)] @@ -123,15 +127,29 @@ pub fn canvas_view(props: &Props) -> Html { let sx = |x: f64| (x + hw) * view.scale + view.ox; let sy = |y: f64| (y + hh) * view.scale + view.oy; - // guide dots for all visible peaks + // guide dots for all visible peaks: dark outline ring + + // bright core so they stay visible on any photo content #[allow(deprecated)] - ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(120, 220, 160, 0.8)")); + ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(0, 0, 0, 0.85)")); for (cx, cy) in candidates { let (px, py) = (sx(*cx), sy(*cy)); - if px < -4.0 || py < -4.0 || px > cw + 4.0 || py > ch + 4.0 { + if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 { continue; } - ctx.fill_rect(px - 1.5, py - 1.5, 3.0, 3.0); + ctx.begin_path(); + ctx.arc(px, py, 4.5, 0.0, std::f64::consts::TAU); + ctx.fill(); + } + #[allow(deprecated)] + ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgb(110, 231, 183)")); + for (cx, cy) in candidates { + let (px, py) = (sx(*cx), sy(*cy)); + if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 { + continue; + } + ctx.begin_path(); + ctx.arc(px, py, 2.5, 0.0, std::f64::consts::TAU); + ctx.fill(); } // markers: red cross + name @@ -226,14 +244,21 @@ pub fn canvas_view(props: &Props) -> Html { let on_pointermove = { let drag = drag.clone(); - let pan = props.callbacks.pan.clone(); + let pan_cb = props.callbacks.pan.clone(); let marker_drag = props.callbacks.marker_drag.clone(); + let hover = props.callbacks.hover.clone(); + let to_img = to_img.clone(); let scale = props.view.scale; Callback::from(move |e: PointerEvent| { let mut d = drag.borrow_mut(); let mode = match &d.mode { Some(m) => m.clone(), - None => return, + None => { + // free hover: report position for peak identification + let (ix, iy) = to_img(e.client_x() as f64, e.client_y() as f64); + hover.emit((ix, iy)); + return; + } }; let pos = (e.client_x() as f64, e.client_y() as f64); let dx = pos.0 - d.last.0; @@ -246,12 +271,17 @@ pub fn canvas_view(props: &Props) -> Html { return; } match mode { - DragMode::Pan => pan.emit((dx, dy)), + DragMode::Pan => pan_cb.emit((dx, dy)), DragMode::Marker(i) => marker_drag.emit((i, dx / scale, dy / scale)), } }) }; + let on_pointerleave = { + let hover_end = props.callbacks.hover_end.clone(); + Callback::from(move |_: PointerEvent| hover_end.emit(())) + }; + let on_pointerup = { let drag = drag.clone(); let canvas_ref = props.canvas_ref.clone(); @@ -320,6 +350,7 @@ pub fn canvas_view(props: &Props) -> Html { onpointermove={on_pointermove} onpointerup={on_pointerup} onpointercancel={on_pointercancel} + onpointerleave={on_pointerleave} oncontextmenu={on_contextmenu} onwheel={on_wheel} /> diff --git a/crates/gipfel-web/www/style.css b/crates/gipfel-web/www/style.css index 187b476..1e632f2 100644 --- a/crates/gipfel-web/www/style.css +++ b/crates/gipfel-web/www/style.css @@ -67,6 +67,11 @@ body { color: #9fd09f; font-variant-numeric: tabular-nums; } +.hover { + font-size: 14px; + font-weight: 600; + color: #ffffff; +} .dim { opacity: 0.6; } |
