pub struct Hooks { /* private fields */ }Expand description
General-purpose hooks system for TUI widget state management.
Stores persistent state, SDK watch handles, and animation registrations. Uses mark-and-sweep to automatically clean up state when widgets stop rendering (e.g., screen transitions).
Implementations§
Source§impl Hooks
impl Hooks
pub fn new() -> Self
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Reset access tracking before a render frame.
Sourcepub fn use_state<V: 'static>(
&mut self,
key: &str,
default: impl FnOnce() -> V,
) -> &mut V
pub fn use_state<V: 'static>( &mut self, key: &str, default: impl FnOnce() -> V, ) -> &mut V
Get or create persistent local state.
On first call for a given key, creates the state using default().
On subsequent calls, returns the existing state.
Must be called last — the returned &mut V borrows &mut self,
preventing other hook calls until the reference is dropped.
Sourcepub fn use_watch<P>(&mut self, prop: &PropertyHandle<P>) -> Option<P>where
P: SonosProperty + Clone + 'static,
pub fn use_watch<P>(&mut self, prop: &PropertyHandle<P>) -> Option<P>where
P: SonosProperty + Clone + 'static,
Subscribe to an SDK speaker property, returning the current value.
Each frame, creates a fresh WatchHandle via prop.watch() to get
an up-to-date snapshot. The old handle is replaced (dropped → grace
period starts → new handle re-acquires → grace period cancelled).
This is the SDK’s intended pattern: “Re-watch each frame to refresh
the snapshot.”
Falls back to prop.get() if watch() fails.
Sourcepub fn use_watch_group<P>(&mut self, prop: &GroupPropertyHandle<P>) -> Option<P>where
P: SonosProperty + Clone + 'static,
pub fn use_watch_group<P>(&mut self, prop: &GroupPropertyHandle<P>) -> Option<P>where
P: SonosProperty + Clone + 'static,
Subscribe to an SDK group property, returning the current value.
Same as use_watch but for group-scoped properties (e.g., group volume).
Sourcepub fn use_animation(&mut self, key: &str, active: bool)
pub fn use_animation(&mut self, key: &str, active: bool)
Register an animation tick request.
When active is true, the event loop’s global animation timer will
mark the app as dirty every ~250ms, triggering re-renders for smooth
progress bar animation.
Sourcepub fn has_active_animations(&self) -> bool
pub fn has_active_animations(&self) -> bool
Check if any widget has registered an active animation.
Called by the event loop between frames to decide whether to tick the animation timer.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Hooks
impl !RefUnwindSafe for Hooks
impl !Send for Hooks
impl !Sync for Hooks
impl Unpin for Hooks
impl UnsafeUnpin for Hooks
impl !UnwindSafe for Hooks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().