euv_ui/hook/debounced_value/fn.rs
1use super::*;
2
3/// Obtains the debounced value registered against the current hook context slot.
4///
5/// Behaves like `HookContext::use_hook`: the same `DebouncedValue` is
6/// returned on every render at the same hook index, so the in-flight
7/// throttle / pending slot survives across renders without losing state.
8///
9/// The factory uses the supplied `delay_ms` to seed the slot. To change
10/// the delay at runtime, call [`DebouncedValue::set`] with a `delay`
11/// value of your choice (the field is `pub(crate)`, but `set` plus
12/// `tick` is the supported public surface).
13///
14/// # Arguments
15///
16/// - `u32` - The quiet period in milliseconds. After this many
17/// milliseconds without a fresh `set`, any pending value is committed.
18///
19/// # Returns
20///
21/// - `DebouncedValue<T>` - The debounced value handle.
22/// Returns the factory result directly when no hook context is
23/// active (e.g. when called outside a render cycle).
24pub fn use_debounced_value<T>(delay_ms: u32) -> DebouncedValue<T>
25where
26 T: Clone + PartialEq + Debug + Default + 'static,
27{
28 HookContext::use_hook(|| DebouncedValue::<T>::new(delay_ms))
29}