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 ///
19 /// Public because `ui/tests/counter/fn.rs` reads it
20 /// through `get_value()`.
21 #[new(skip)]
22 pub value: Signal<i32>,
23 /// Optional minimum bound. `None` means unbounded below.
24 ///
25 /// Public because `ui/tests/counter/fn.rs` reads it
26 /// through `get_min()`.
27 #[get(type(copy))]
28 pub min: Option<i32>,
29 /// Optional maximum bound. `None` means unbounded above.
30 ///
31 /// Public because `ui/tests/counter/fn.rs` reads it
32 /// through `get_max()`.
33 #[get(type(copy))]
34 pub max: Option<i32>,
35 /// Step size used by `increment` / `decrement`.
36 #[get(type(copy), pub(crate))]
37 #[get_mut(pub(crate))]
38 #[set(pub(crate))]
39 pub(crate) step: i32,
40}