From 6fa2ffc8964b31c4e85393527599b5da97b53c9a Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 27 Oct 2026 14:18:00 +0100 Subject: web: optional labels for unmarked visible peaks Display > 'Show peak labels' toggle (off by default): every visible peak gets its name drawn next to its guide dot, like the desktop version. Labels join one combined collision-avoidance layout pass with the marker labels (same layout_label_y), so marker labels keep priority and nothing overlaps. Unmarked labels are tinted pale green; hidden peaks and already-marked peaks get no duplicate label. Candidates now carry name + marked flag (DotView), markers carry the hill index (MarkerView::hill) for the dedup. --- crates/wipfel/src/app.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'crates/wipfel/src/app.rs') diff --git a/crates/wipfel/src/app.rs b/crates/wipfel/src/app.rs index 879ed91..2b205fa 100644 --- a/crates/wipfel/src/app.rs +++ b/crates/wipfel/src/app.rs @@ -15,7 +15,7 @@ use web_sys::{DragEvent, Event, HtmlCanvasElement, HtmlInputElement, InputEvent, use yew::prelude::*; use crate::bridge; -use crate::canvas_view::{CanvasView, MarkerView, ViewCallbacks, ViewState}; +use crate::canvas_view::{CanvasView, DotView, MarkerView, ViewCallbacks, ViewState}; use crate::compass::{Compass, CompassData}; use crate::markers::{self, Marker}; use crate::widgets::{NumItem, SliderItem}; @@ -162,6 +162,7 @@ pub fn app() -> Html { let img_size = use_state(|| (0u32, 0u32)); let find_peak = use_state(|| Option::::None); let show_hidden = use_state(|| false); + let peak_labels = use_state(|| false); // set once the user pans or zooms by hand; auto-fit is then suppressed // until the next image load let user_moved = use_mut_ref(|| false); @@ -493,6 +494,13 @@ pub fn app() -> Html { show_hidden.set(input.checked()); }) }; + let on_peak_labels = { + let peak_labels = peak_labels.clone(); + Callback::from(move |e: Event| { + let input: HtmlInputElement = e.target_unchecked_into(); + peak_labels.set(input.checked()); + }) + }; // compass strip: shares the image transform, drag changes azimuth let compass_data = { @@ -700,23 +708,25 @@ pub fn app() -> Html { markers .iter() .map(|m| MarkerView { + hill: m.hill, x: m.x, y: m.y, name: p.hills[m.hill].name.clone(), }) .collect() }; - let candidates: Vec<(f64, f64, bool)> = { + let candidates: Vec = { let p = pan.borrow(); + let marked: Vec = markers.iter().map(|m| m.hill).collect(); p.visible .iter() .filter(|&&i| *show_hidden || p.hills[i].flags & FLAG_HIDDEN == 0) - .map(|&i| { - ( - p.hills[i].x, - p.hills[i].y, - p.hills[i].flags & FLAG_HIDDEN != 0, - ) + .map(|&i| DotView { + x: p.hills[i].x, + y: p.hills[i].y, + hidden: p.hills[i].flags & FLAG_HIDDEN != 0, + marked: marked.contains(&i), + name: p.hills[i].name.clone(), }) .collect() }; @@ -768,6 +778,10 @@ pub fn app() -> Html { { "Show hidden peaks" } + Html { tick={*tick} markers={marker_views} candidates={candidates} + peak_labels={*peak_labels} label_font={vp.label_font} /> { findpeak_popup.clone() } -- cgit v1.2.3