summaryrefslogtreecommitdiff
path: root/crates/wipfel/src/widgets.rs
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-27 13:55:35 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-27 13:55:35 +0100
commitf6883fa1d586a040bf228ab886b95ca64457fa34 (patch)
tree9e071b64c4f1a6ac46a7b4033e0c9a4b284742bb /crates/wipfel/src/widgets.rs
parent0b85e7989eacb26d3496cdb98ed3221868a4013f (diff)
Rename web front end to wipfel
'gipfel web' is taken by an existing related project. The browser app is now wipfel — web based gipfel photogrammetry for mountain images: crate gipfel-web -> wipfel, updated titles, docs, plan and dev script. The shared engine crate stays gipfel-core.
Diffstat (limited to 'crates/wipfel/src/widgets.rs')
-rw-r--r--crates/wipfel/src/widgets.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/crates/wipfel/src/widgets.rs b/crates/wipfel/src/widgets.rs
new file mode 100644
index 0000000..1d22bac
--- /dev/null
+++ b/crates/wipfel/src/widgets.rs
@@ -0,0 +1,77 @@
+//! Small form controls: full-width slider with value readout above
+//! (mirrors the desktop `slider_item` layout) and a numeric input row.
+
+use web_sys::{HtmlInputElement, InputEvent};
+use yew::prelude::*;
+
+#[derive(Properties, PartialEq)]
+pub struct SliderProps {
+ pub label: AttrValue,
+ /// formatted value shown right of the label
+ pub display: AttrValue,
+ pub value: f64,
+ pub min: f64,
+ pub max: f64,
+ pub step: f64,
+ pub onchange: Callback<f64>,
+}
+
+#[function_component(SliderItem)]
+pub fn slider_item(p: &SliderProps) -> Html {
+ // live update while dragging (oninput), not only on release
+ let oninput = {
+ let onchange = p.onchange.clone();
+ Callback::from(move |e: InputEvent| {
+ let input: HtmlInputElement = e.target_unchecked_into();
+ if let Ok(v) = input.value().parse::<f64>() {
+ onchange.emit(v);
+ }
+ })
+ };
+ html! {
+ <div class="slider">
+ <div class="sliderhead">
+ <span>{ p.label.as_ref().to_string() }</span>
+ <span class="val">{ p.display.as_ref().to_string() }</span>
+ </div>
+ <input
+ type="range"
+ min={p.min.to_string()}
+ max={p.max.to_string()}
+ step={p.step.to_string()}
+ value={p.value.to_string()}
+ {oninput}
+ />
+ </div>
+ }
+}
+
+#[derive(Properties, PartialEq)]
+pub struct NumProps {
+ pub label: AttrValue,
+ pub value: f64,
+ pub step: f64,
+ #[prop_or(2)]
+ pub decimals: usize,
+ pub onchange: Callback<f64>,
+}
+
+#[function_component(NumItem)]
+pub fn num_item(p: &NumProps) -> Html {
+ let onchange = {
+ let onchange = p.onchange.clone();
+ Callback::from(move |e: Event| {
+ let input: HtmlInputElement = e.target_unchecked_into();
+ if let Ok(v) = input.value().parse::<f64>() {
+ onchange.emit(v);
+ }
+ })
+ };
+ let display = format!("{:.*}", p.decimals, p.value);
+ html! {
+ <label class="numrow">
+ <span>{ p.label.as_ref().to_string() }</span>
+ <input type="number" step={p.step.to_string()} value={display} {onchange} />
+ </label>
+ }
+}