pub struct Counter { /* private fields */ }Expand description
A bounded reactive counter.
Constructed via Counter::new(min, max, step)
(Lombok New); the counter starts at i32::default()
(0). Use Counter::set (or one of the mutator
methods) to set the initial value. The current value
is exposed as a Signal<i32> accessed through
get_value(). Mutators (increment, decrement,
set, reset) write through that signal, so any
render closure that reads counter.get_value().get()
re-renders when the value changes.
Implementations§
Source§impl Counter
Inherent implementation of Counter.
impl Counter
Inherent implementation of Counter.
Sourcepub fn increment(&self)
pub fn increment(&self)
Adds step to the value, clamping into [min, max]
afterwards. If the counter is already at max, the
value is left at max.
Sourcepub fn decrement(&self)
pub fn decrement(&self)
Subtracts step from the value, clamping into
[min, max] afterwards. If the counter is already
at min, the value is left at min.
Sourcepub fn set(&self, next: i32)
pub fn set(&self, next: i32)
Replaces the value with next, clamping into
[min, max] if bounds are set.
§Arguments
i32- A 32-bit signed integer (i32).
Sourcepub fn set_unchecked(&self, next: i32)
pub fn set_unchecked(&self, next: i32)
Replaces the value with next without clamping.
Bypasses both the min and max bounds. Use
when you genuinely want to push the counter outside
its configured range (e.g., to “reset to a
deliberately out-of-range sentinel” or to recover
from an invalid configuration).
§Arguments
i32- A 32-bit signed integer (i32).
Sourcepub fn is_at_max(&self) -> bool
pub fn is_at_max(&self) -> bool
Returns true when the value is at the configured
max (or always false if unbounded above).
§Returns
bool-truewhen the value is at the configured maximum.