pub struct ViewContext<C: Component> { /* private fields */ }Expand description
Records view-time declarations for a component publication.
Context reads subscribe the component to the resolved provider. Callbacks queue messages rather than updating the component during view construction.
Implementations§
Source§impl<C: Component> ViewContext<C>
impl<C: Component> ViewContext<C>
Sourcepub fn on_color_scheme(
&mut self,
callback: impl IntoPayloadCallback<ColorScheme>,
)
pub fn on_color_scheme( &mut self, callback: impl IntoPayloadCallback<ColorScheme>, )
Declares a queued color-scheme observation for the owning window.
Sourcepub fn on_window_size(&mut self, callback: impl IntoPayloadCallback<WindowSize>)
pub fn on_window_size(&mut self, callback: impl IntoPayloadCallback<WindowSize>)
Declares a queued client-size observation for the owning window.
Sourcepub fn window_title(&mut self, title: impl Into<String>)
pub fn window_title(&mut self, title: impl Into<String>)
Declares the owning window’s title for this component publication.
Sourcepub fn window_visuals(&mut self, visuals: WindowVisuals)
pub fn window_visuals(&mut self, visuals: WindowVisuals)
Declares the owning window’s visual environment for this publication.
Sourcepub fn sender(&self) -> LocalSender<C::Message>
pub fn sender(&self) -> LocalSender<C::Message>
Returns a sender bound to this component instance.
Sourcepub fn callback<T>(
&self,
map: impl Fn(T) -> C::Message + 'static,
) -> Callback<T>
pub fn callback<T>( &self, map: impl Fn(T) -> C::Message + 'static, ) -> Callback<T>
Creates a callback that maps its argument to a queued component message.
Sourcepub fn forward(&self) -> Callback<C::Message>
pub fn forward(&self) -> Callback<C::Message>
Creates a callback that forwards its argument as a queued component message.
Sourcepub fn message(&self, message: C::Message) -> Callback<()>
pub fn message(&self, message: C::Message) -> Callback<()>
Creates a callback that queues a clone of message.
Sourcepub fn use_context<T: Clone + 'static>(&mut self, context: &Context<T>) -> T
pub fn use_context<T: Clone + 'static>(&mut self, context: &Context<T>) -> T
Reads the nearest provided value, or the context’s fallback when no provider exists.
Sourcepub fn use_effect<D>(
&mut self,
key: impl Into<EffectKey>,
dependency: D,
setup: impl FnOnce() -> Option<Box<dyn FnOnce()>> + 'static,
)where
D: PartialEq + 'static,
pub fn use_effect<D>(
&mut self,
key: impl Into<EffectKey>,
dependency: D,
setup: impl FnOnce() -> Option<Box<dyn FnOnce()>> + 'static,
)where
D: PartialEq + 'static,
Declares an effect identified by key and dependency.
The setup runs after a successful publication when the dependency is new or changed. Its cleanup runs before replacement, when the effect is omitted, or when the component is removed. Cleanup functions run in reverse order when the component is removed.