euv_ui/hook/counter/struct.rs
1use super::*;
2
3/// A bounded reactive counter.
4///
5/// Constructed via `Counter::new(min, max, step)`
6/// (Lombok `New`); the counter starts at `i32::default()`
7/// (`0`). Use [`Counter::set`] (or one of the mutator
8/// methods) to set the initial value. The current value
9/// is exposed as a `Signal<i32>` accessed through
10/// `get_value()`. Mutators (`increment`, `decrement`,
11/// `set`, `reset`) write through that signal, so any
12/// render closure that reads `counter.get_value().get()`
13/// re-renders when the value changes.
14#[derive(Clone, Data, Debug, Default, New)]
15pub struct Counter {
16 /// The current value signal. Defaults to
17 /// `Signal::create(0)` because of `#[new(skip)]`.
18 #[new(skip)]
19 pub(crate) value: Signal<i32>,
20 /// Optional minimum bound. `None` means unbounded below.
21 pub(crate) min: Option<i32>,
22 /// Optional maximum bound. `None` means unbounded above.
23 pub(crate) max: Option<i32>,
24 /// Step size used by `increment` / `decrement`.
25 pub(crate) step: i32,
26}