summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-11-18 21:47:56 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-11-18 21:47:56 +0100
commit73ad3eccad74754c1e74ff3025f4d4581f6178cb (patch)
tree0f0d3887795c917c889a590e204eb13cb94216ed
parent08636f9a7aeb082b7ed6c5bb56eebdbcb224fa2a (diff)
web: sync projection dropdown via the selectedIndex property
The dropdown mirrored the projection state through the 'selected' ATTRIBUTE on the options - but that only drives the DEFAULT selection. Once the browser's selectedIndex property has been established (first render, user interaction), patching the attribute no longer moves the visible choice: loading a panorama with a gipfel comment after a rectilinear one updated the model (peaks rendered correctly) while the dropdown kept showing the old mode. Attach a NodeRef to the <select> and set the selectedIndex property in an effect on every projection state change. The option attributes stay for the initial paint.
-rw-r--r--crates/gipfel/src/app.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/gipfel/src/app.rs b/crates/gipfel/src/app.rs
index fc9aa84..62b10c3 100644
--- a/crates/gipfel/src/app.rs
+++ b/crates/gipfel/src/app.rs
@@ -221,6 +221,21 @@ pub fn app() -> Html {
// 0 = rectilinear, 1 = cylindrical (panoramic); mirrors
// Panorama::projection_type, synced from the image comment on load
let projection = use_state(|| 0u32);
+ // The `selected` ATTRIBUTE on an <option> only drives the default
+ // selection; once the browser's selectedIndex PROPERTY has been
+ // established (first render, user interaction) patching the
+ // attribute no longer moves the visible choice. Mirror the state
+ // onto the property so a comment-driven projection switch on a
+ // later image load always shows up in the dropdown.
+ let proj_select_ref = use_node_ref();
+ {
+ let sel = proj_select_ref.clone();
+ use_effect_with(*projection, move |p| {
+ if let Some(sel) = sel.cast::<web_sys::HtmlSelectElement>() {
+ sel.set_selected_index(*p as i32);
+ }
+ });
+ }
let hover = use_state(|| Option::<String>::None);
let vp = use_state(UiParams::default);
let img_size = use_state(|| (0u32, 0u32));
@@ -1485,7 +1500,7 @@ pub fn app() -> Html {
<SliderItem label="Roll" display={format!("{:.1}°", vp.roll)}
value={vp.roll} min={-10.0} max={10.0} step={0.01} onchange={on_roll} />
<div class="section">{ "Projection" }</div>
- <select class="textinput" onchange={on_projection}>
+ <select class="textinput" onchange={on_projection} ref={proj_select_ref}>
<option value="0" selected={*projection == 0}>{ "Normal (rectilinear)" }</option>
<option value="1" selected={*projection == 1}>{ "Panorama (cylindrical)" }</option>
</select>