Skip to main content

ViewContext

Struct ViewContext 

Source
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>

Source

pub fn on_color_scheme( &mut self, callback: impl IntoPayloadCallback<ColorScheme>, )

Declares a queued color-scheme observation for the owning window.

Source

pub fn on_window_size(&mut self, callback: impl IntoPayloadCallback<WindowSize>)

Declares a queued client-size observation for the owning window.

Source

pub fn window_title(&mut self, title: impl Into<String>)

Declares the owning window’s title for this component publication.

Source

pub fn window_visuals(&mut self, visuals: WindowVisuals)

Declares the owning window’s visual environment for this publication.

Source

pub fn sender(&self) -> LocalSender<C::Message>

Returns a sender bound to this component instance.

Source

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.

Source

pub fn forward(&self) -> Callback<C::Message>

Creates a callback that forwards its argument as a queued component message.

Source

pub fn message(&self, message: C::Message) -> Callback<()>
where C::Message: Clone,

Creates a callback that queues a clone of message.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for ViewContext<C>

§

impl<C> !Send for ViewContext<C>

§

impl<C> !Sync for ViewContext<C>

§

impl<C> !UnwindSafe for ViewContext<C>

§

impl<C> Freeze for ViewContext<C>

§

impl<C> Unpin for ViewContext<C>

§

impl<C> UnsafeUnpin for ViewContext<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.