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 end_frame(&mut self)
pub fn end_frame(&mut self)
Evict unaccessed state and drop unaccessed watch handles.
Handles for widgets that rendered this frame are retained, so a continuously-visible widget holds one subscription for its whole life.
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 its current value.
The subscription is acquired on first access and held until the widget
stops rendering (mark-and-sweep in Self::end_frame).
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 its current value.
Same as use_watch but for group-scoped properties (e.g., group volume).
Sourcepub fn use_watch_group_or_fetch<P>(
&mut self,
prop: &GroupPropertyHandle<P>,
) -> Option<P>
pub fn use_watch_group_or_fetch<P>( &mut self, prop: &GroupPropertyHandle<P>, ) -> Option<P>
Subscribe to a fetchable group property, fetching on first access if empty.
Like use_watch_group but performs a one-time fetch when the cache has
no value yet, so the UI doesn’t show a blank until the first UPnP event.
The fetch happens only on the frame that acquires the handle, since
later frames reuse it.
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 !RefUnwindSafe for Hooks
impl !Send for Hooks
impl !Sync for Hooks
impl !UnwindSafe for Hooks
impl Freeze for Hooks
impl Unpin for Hooks
impl UnsafeUnpin 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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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().