summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-27 14:18:00 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-27 14:18:00 +0100
commit6fa2ffc8964b31c4e85393527599b5da97b53c9a (patch)
tree80df09a5a704cd0a8539730338794c4d6dfba283
parente838bb23f8251c7b2d5b0ebfca820f38680cc022 (diff)
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.
-rw-r--r--crates/wipfel/src/app.rs31
-rw-r--r--crates/wipfel/src/canvas_view.rs124
2 files changed, 117 insertions, 38 deletions
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::<FindPeak>::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<DotView> = {
let p = pan.borrow();
+ let marked: Vec<usize> = 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 {
<input type="checkbox" checked={*show_hidden} onchange={on_show_hidden} />
{ "Show hidden peaks" }
</label>
+ <label class="row">
+ <input type="checkbox" checked={*peak_labels} onchange={on_peak_labels} />
+ { "Show peak labels" }
+ </label>
<SliderItem label="Visibility" display={format!("{:.0} %", (vp.vis - 0.01) / 0.09 * 100.0)}
value={vp.vis} min={0.01} max={0.1} step={0.001} onchange={on_vis} />
<SliderItem label="Label size" display={format!("{:.0} px", vp.label_font)}
@@ -798,6 +812,7 @@ pub fn app() -> Html {
tick={*tick}
markers={marker_views}
candidates={candidates}
+ peak_labels={*peak_labels}
label_font={vp.label_font}
/>
{ findpeak_popup.clone() }
diff --git a/crates/wipfel/src/canvas_view.rs b/crates/wipfel/src/canvas_view.rs
index 9d4338e..808ba1a 100644
--- a/crates/wipfel/src/canvas_view.rs
+++ b/crates/wipfel/src/canvas_view.rs
@@ -18,11 +18,24 @@ pub struct ViewState {
/// A marker in center-relative image coordinates.
#[derive(Clone, Debug, PartialEq)]
pub struct MarkerView {
+ pub hill: usize,
pub x: f64,
pub y: f64,
pub name: String,
}
+/// A visible (unmarked or marked) peak drawn as a guide dot.
+#[derive(Clone, Debug, PartialEq)]
+pub struct DotView {
+ pub x: f64,
+ pub y: f64,
+ /// hidden by nearer terrain (drawn grey)
+ pub hidden: bool,
+ /// already carries a user marker (no duplicate label)
+ pub marked: bool,
+ pub name: String,
+}
+
#[derive(Clone, PartialEq)]
pub struct ViewCallbacks {
pub pan: Callback<(f64, f64)>,
@@ -51,9 +64,10 @@ pub struct Props {
/// bumped on window resize to force a redraw
pub tick: u32,
pub markers: Vec<MarkerView>,
- /// projected positions of all visible hills (guide dots) with their
- /// hidden-by-occlusion flag
- pub candidates: Vec<(f64, f64, bool)>,
+ /// guide dots for all visible hills
+ pub candidates: Vec<DotView>,
+ /// draw name labels for unmarked visible peaks too
+ pub peak_labels: bool,
/// marker label font size, screen px
pub label_font: f32,
}
@@ -89,9 +103,18 @@ pub fn canvas_view(props: &Props) -> Html {
let markers = props.markers.clone();
let candidates = props.candidates.clone();
let label_font = props.label_font;
+ let peak_labels = props.peak_labels;
use_effect_with(
- (bitmap, view, props.tick, markers.clone(), candidates.clone(), label_font),
- move |(bitmap, view, _tick, markers, candidates, label_font)| {
+ (
+ bitmap,
+ view,
+ props.tick,
+ markers.clone(),
+ candidates.clone(),
+ label_font,
+ peak_labels,
+ ),
+ move |(bitmap, view, _tick, markers, candidates, label_font, peak_labels)| {
let Some(canvas) = canvas_ref.cast::<HtmlCanvasElement>() else {
return;
};
@@ -136,8 +159,8 @@ pub fn canvas_view(props: &Props) -> Html {
// peaks hidden by nearer terrain are drawn grey
#[allow(deprecated)]
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(0, 0, 0, 0.85)"));
- for (cx, cy, _hidden) in candidates {
- let (px, py) = (sx(*cx), sy(*cy));
+ for d in candidates.iter() {
+ let (px, py) = (sx(d.x), sy(d.y));
if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 {
continue;
}
@@ -145,12 +168,12 @@ pub fn canvas_view(props: &Props) -> Html {
let _ = ctx.arc(px, py, 4.5, 0.0, std::f64::consts::TAU);
ctx.fill();
}
- for (cx, cy, hidden) in candidates {
- let (px, py) = (sx(*cx), sy(*cy));
+ for d in candidates.iter() {
+ let (px, py) = (sx(d.x), sy(d.y));
if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 {
continue;
}
- let color = if *hidden { "rgb(150, 150, 150)" } else { "rgb(110, 231, 183)" };
+ let color = if d.hidden { "rgb(150, 150, 150)" } else { "rgb(110, 231, 183)" };
#[allow(deprecated)]
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color));
ctx.begin_path();
@@ -158,39 +181,75 @@ pub fn canvas_view(props: &Props) -> Html {
ctx.fill();
}
- // markers: yellow leader lines, red crosses, collision-free
- // labels (port of the desktop viewport drawing)
- if !markers.is_empty() {
+ // labels: markers always; unmarked visible peaks when
+ // peak_labels is on. One combined collision-avoiding
+ // layout pass sorted by screen x (port of the desktop
+ // viewport drawing).
+ if !markers.is_empty() || *peak_labels {
let label_font = *label_font;
let line_h = label_font * 1.3 + 2.0;
ctx.set_font(&format!("{label_font:.0}px system-ui, sans-serif"));
+
+ struct Item {
+ x: f64,
+ y: f64,
+ name: String,
+ marker: bool,
+ }
+ let mut items: Vec<Item> = markers
+ .iter()
+ .map(|m| Item {
+ x: m.x,
+ y: m.y,
+ name: m.name.clone(),
+ marker: true,
+ })
+ .collect();
+ if *peak_labels {
+ for d in candidates.iter() {
+ if d.hidden || d.marked || d.name.is_empty() {
+ continue;
+ }
+ items.push(Item {
+ x: d.x,
+ y: d.y,
+ name: d.name.clone(),
+ marker: false,
+ });
+ }
+ }
+
// layout runs in screen space, sorted by x
- let mut order: Vec<usize> = (0..markers.len())
+ let mut order: Vec<usize> = (0..items.len())
.filter(|&i| {
- markers[i].x.abs() * 2.0 <= bitmap.width() as f64
- && markers[i].y.abs() * 2.0 <= bitmap.height() as f64
+ items[i].x.abs() * 2.0 <= bitmap.width() as f64
+ && items[i].y.abs() * 2.0 <= bitmap.height() as f64
})
.collect();
- order.sort_by(|&a, &b| sx(markers[a].x).total_cmp(&sx(markers[b].x)));
- let xs: Vec<f32> = order.iter().map(|&i| sx(markers[i].x) as f32).collect();
- let ys: Vec<f32> = order.iter().map(|&i| sy(markers[i].y) as f32).collect();
+ order.sort_by(|&a, &b| sx(items[a].x).total_cmp(&sx(items[b].x)));
+ let xs: Vec<f32> = order.iter().map(|&i| sx(items[i].x) as f32).collect();
+ let ys: Vec<f32> = order.iter().map(|&i| sy(items[i].y) as f32).collect();
let widths: Vec<f32> = order
.iter()
.map(|&i| {
- ctx.measure_text(&markers[i].name)
+ ctx.measure_text(&items[i].name)
.map(|m| m.width() as f32)
- .unwrap_or_else(|_| markers[i].name.len() as f32 * 7.0)
+ .unwrap_or_else(|_| items[i].name.len() as f32 * 7.0)
})
.collect();
let in_img = vec![true; order.len()];
let entries = layout_label_y(&xs, &ys, &widths, &in_img, line_h);
- // leaders (yellow): cross, vertical, horizontal
+ // leaders (yellow): cross, vertical, horizontal —
+ // drawn for markers only
#[allow(deprecated)]
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str("rgb(255, 230, 51)"));
ctx.set_line_width(1.0);
for (k, &i) in order.iter().enumerate() {
- let (px, py) = (sx(markers[i].x), sy(markers[i].y));
+ if !items[i].marker {
+ continue;
+ }
+ let (px, py) = (sx(items[i].x), sy(items[i].y));
let (lx, ly) = entries[k];
let label_line = py + ly as f64 - line_h as f64;
ctx.begin_path();
@@ -207,7 +266,10 @@ pub fn canvas_view(props: &Props) -> Html {
ctx.set_stroke_style(&wasm_bindgen::JsValue::from_str("rgb(255, 64, 64)"));
ctx.set_line_width(1.5);
for &i in &order {
- let (px, py) = (sx(markers[i].x), sy(markers[i].y));
+ if !items[i].marker {
+ continue;
+ }
+ let (px, py) = (sx(items[i].x), sy(items[i].y));
ctx.begin_path();
ctx.move_to(px - 5.0, py);
ctx.line_to(px + 5.0, py);
@@ -215,22 +277,24 @@ pub fn canvas_view(props: &Props) -> Html {
ctx.line_to(px, py + 5.0);
ctx.stroke();
}
- // labels: white on dark shadow, right-aligned at leader end
+ // labels: white on dark shadow, right-aligned at the
+ // leader end (markers) or just right of the dot
for (k, &i) in order.iter().enumerate() {
- if markers[i].name.is_empty() {
+ if items[i].name.is_empty() {
continue;
}
- let (px, py) = (sx(markers[i].x), sy(markers[i].y));
+ let (px, py) = (sx(items[i].x), sy(items[i].y));
let (lx, ly) = entries[k];
let label_line = py + ly as f64 - line_h as f64;
let tx = px + lx as f64 - widths[k] as f64;
let ty = label_line - 3.0;
#[allow(deprecated)]
ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(0, 0, 0, 0.85)"));
- ctx.fill_text(&markers[i].name, tx + 1.0, ty + 1.0).ok();
+ ctx.fill_text(&items[i].name, tx + 1.0, ty + 1.0).ok();
+ let color = if items[i].marker { "white" } else { "rgb(196, 240, 214)" };
#[allow(deprecated)]
- ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("white"));
- ctx.fill_text(&markers[i].name, tx, ty).ok();
+ ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color));
+ ctx.fill_text(&items[i].name, tx, ty).ok();
}
}
},