pub struct AsyncWindowContext { /* private fields */ }Expand description
A cloneable, owned handle to the application context, composed with the window associated with the current task.
Implementations§
Source§impl AsyncWindowContext
impl AsyncWindowContext
Sourcepub fn window_handle(&self) -> AnyWindowHandle
pub fn window_handle(&self) -> AnyWindowHandle
Get the handle of the window this context is associated with.
Sourcepub fn update<R>(
&mut self,
update: impl FnOnce(&mut Window, &mut App) -> R,
) -> Result<R, Error>
pub fn update<R>( &mut self, update: impl FnOnce(&mut Window, &mut App) -> R, ) -> Result<R, Error>
A convenience method for App::update_window.
Sourcepub fn update_root<R>(
&mut self,
update: impl FnOnce(AnyView, &mut Window, &mut App) -> R,
) -> Result<R, Error>
pub fn update_root<R>( &mut self, update: impl FnOnce(AnyView, &mut Window, &mut App) -> R, ) -> Result<R, Error>
A convenience method for App::update_window.
Sourcepub fn on_next_frame(&mut self, f: impl FnOnce(&mut Window, &mut App) + 'static)
pub fn on_next_frame(&mut self, f: impl FnOnce(&mut Window, &mut App) + 'static)
A convenience method for Window::on_next_frame.
Sourcepub fn read_global<G, R>(
&mut self,
read: impl FnOnce(&G, &Window, &App) -> R,
) -> Result<R, Error>where
G: Global,
pub fn read_global<G, R>(
&mut self,
read: impl FnOnce(&G, &Window, &App) -> R,
) -> Result<R, Error>where
G: Global,
A convenience method for App::global.
Sourcepub fn update_global<G, R>(
&mut self,
update: impl FnOnce(&mut G, &mut Window, &mut App) -> R,
) -> Result<R, Error>where
G: Global,
pub fn update_global<G, R>(
&mut self,
update: impl FnOnce(&mut G, &mut Window, &mut App) -> R,
) -> Result<R, Error>where
G: Global,
A convenience method for App::update_global.
for updating the global state of the specified type.
Sourcepub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncWindowContext) -> R + 'static,
R: 'static,
pub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncWindowContext) -> R + 'static,
R: 'static,
Schedule a future to be executed on the main thread. This is used for collecting the results of background tasks and updating the UI.
Sourcepub fn prompt<T>(
&mut self,
level: PromptLevel,
message: &str,
detail: Option<&str>,
answers: &[T],
) -> Receiver<usize> ⓘ
pub fn prompt<T>( &mut self, level: PromptLevel, message: &str, detail: Option<&str>, answers: &[T], ) -> Receiver<usize> ⓘ
Present a platform dialog. The provided message will be presented, along with buttons for each answer. When a button is clicked, the returned Receiver will receive the index of the clicked button.
Methods from Deref<Target = AsyncApp>§
Sourcepub fn background_executor(&self) -> &BackgroundExecutor
pub fn background_executor(&self) -> &BackgroundExecutor
Get an executor which can be used to spawn futures in the background.
Sourcepub fn is_test(&self) -> bool
pub fn is_test(&self) -> bool
Whether this app runs on the deterministic test scheduler. See
BackgroundExecutor::is_test.
Sourcepub fn foreground_executor(&self) -> &ForegroundExecutor
pub fn foreground_executor(&self) -> &ForegroundExecutor
Get an executor which can be used to spawn futures in the foreground.
Sourcepub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> R
pub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> R
Invoke the given function in the context of the app, then flush any effects produced during its invocation.
Sourcepub fn subscribe<T, Event>(
&mut self,
entity: &Entity<T>,
on_event: impl FnMut(Entity<T>, &Event, &mut App) + 'static,
) -> Subscriptionwhere
T: 'static + EventEmitter<Event>,
Event: 'static,
pub fn subscribe<T, Event>(
&mut self,
entity: &Entity<T>,
on_event: impl FnMut(Entity<T>, &Event, &mut App) + 'static,
) -> Subscriptionwhere
T: 'static + EventEmitter<Event>,
Event: 'static,
Arrange for the given callback to be invoked whenever the given entity emits an event of a given type. The callback is provided a handle to the emitting entity and a reference to the emitted event.
Sourcepub fn open_window<V>(
&self,
options: WindowOptions,
build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity<V>,
) -> Result<WindowHandle<V>, Error>where
V: 'static + Render,
pub fn open_window<V>(
&self,
options: WindowOptions,
build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity<V>,
) -> Result<WindowHandle<V>, Error>where
V: 'static + Render,
Open a window with the given options based on the root view returned by the given function.
Sourcepub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static,
R: 'static,
pub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R> ⓘwhere
AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static,
R: 'static,
Schedule a future to be polled in the foreground.
Sourcepub fn has_global<G>(&self) -> boolwhere
G: Global,
pub fn has_global<G>(&self) -> boolwhere
G: Global,
Determine whether global state of the specified type has been assigned.
Sourcepub fn read_global<G, R>(&self, read: impl FnOnce(&G, &App) -> R) -> Rwhere
G: Global,
pub fn read_global<G, R>(&self, read: impl FnOnce(&G, &App) -> R) -> Rwhere
G: Global,
Reads the global state of the specified type, passing it to the given callback.
Panics if no global state of the specified type has been assigned.
Sourcepub fn try_read_global<G, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Option<R>where
G: Global,
pub fn try_read_global<G, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Option<R>where
G: Global,
Reads the global state of the specified type, passing it to the given callback.
Similar to AsyncApp::read_global, but returns an error instead of panicking
Sourcepub fn read_default_global<G, R>(&self, read: impl FnOnce(&G, &App) -> R) -> R
pub fn read_default_global<G, R>(&self, read: impl FnOnce(&G, &App) -> R) -> R
Reads the global state of the specified type, passing it to the given callback. A default value is assigned if a global of this type has not yet been assigned.
Sourcepub fn update_global<G, R>(
&self,
update: impl FnOnce(&mut G, &mut App) -> R,
) -> Rwhere
G: Global,
pub fn update_global<G, R>(
&self,
update: impl FnOnce(&mut G, &mut App) -> R,
) -> Rwhere
G: Global,
A convenience method for App::update_global
for updating the global state of the specified type.
Trait Implementations§
Source§impl AppContext for AsyncWindowContext
impl AppContext for AsyncWindowContext
Source§fn new<T>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>where
T: 'static,
fn new<T>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>where
T: 'static,
Source§fn reserve_entity<T>(&mut self) -> Reservation<T>where
T: 'static,
fn reserve_entity<T>(&mut self) -> Reservation<T>where
T: 'static,
Source§fn insert_entity<T>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>where
T: 'static,
fn insert_entity<T>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Entity<T>where
T: 'static,
reserve_entity.Source§fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Rwhere
T: 'static,
fn update_entity<T, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Rwhere
T: 'static,
Source§fn as_mut<'a, T>(&'a mut self, _: &Entity<T>) -> GpuiBorrow<'a, T>where
T: 'static,
fn as_mut<'a, T>(&'a mut self, _: &Entity<T>) -> GpuiBorrow<'a, T>where
T: 'static,
Source§fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Rwhere
T: 'static,
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Rwhere
T: 'static,
Source§fn update_window<T, F>(
&mut self,
window: AnyWindowHandle,
update: F,
) -> Result<T, Error>
fn update_window<T, F>( &mut self, window: AnyWindowHandle, update: F, ) -> Result<T, Error>
Source§fn with_window<R>(
&mut self,
entity_id: EntityId,
f: impl FnOnce(&mut Window, &mut App) -> R,
) -> Option<R>
fn with_window<R>( &mut self, entity_id: EntityId, f: impl FnOnce(&mut Window, &mut App) -> R, ) -> Option<R>
f against the entity’s current window — the most recently
rendered window that referenced the entity. Returns None if the
entity has no current window or that window is unavailable. See
App::with_window for the underlying lookup.Source§fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R, Error>where
T: 'static,
fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R, Error>where
T: 'static,
Source§impl Clone for AsyncWindowContext
impl Clone for AsyncWindowContext
Source§fn clone(&self) -> AsyncWindowContext
fn clone(&self) -> AsyncWindowContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Deref for AsyncWindowContext
impl Deref for AsyncWindowContext
Source§impl DerefMut for AsyncWindowContext
impl DerefMut for AsyncWindowContext
Source§impl VisualContext for AsyncWindowContext
impl VisualContext for AsyncWindowContext
Source§fn window_handle(&self) -> AnyWindowHandle
fn window_handle(&self) -> AnyWindowHandle
Source§fn new_window_entity<T>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Result<Entity<T>, Error>where
T: 'static,
fn new_window_entity<T>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Result<Entity<T>, Error>where
T: 'static,
Window.Source§fn update_window_entity<T, R>(
&mut self,
view: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
) -> Result<R, Error>where
T: 'static,
fn update_window_entity<T, R>(
&mut self,
view: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
) -> Result<R, Error>where
T: 'static,
Auto Trait Implementations§
impl !RefUnwindSafe for AsyncWindowContext
impl !Send for AsyncWindowContext
impl !Sync for AsyncWindowContext
impl !UnwindSafe for AsyncWindowContext
impl Forget for AsyncWindowContext
impl Freeze for AsyncWindowContextwhere
*const RcInner<AppCell> is !null: Freeze,
*const ArcInner<dyn Scheduler> is !null: Freeze,
PhantomData<ArcInner<dyn Scheduler>>: Freeze,
*const ArcInner<dyn PlatformDispatcher> is !null: Freeze,
PhantomData<ArcInner<dyn PlatformDispatcher>>: Freeze,
*const ArcInner<dyn Fn(Runnable<RunnableMeta>) + Send + Sync> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(Runnable<RunnableMeta>) + Send + Sync>>: Freeze,
PhantomData<Rc<()>>: Freeze,
NonZero<u32>: Freeze,
*const (): Freeze,
&'static str: Freeze,
impl Move for AsyncWindowContext
impl Unpin for AsyncWindowContext
impl UnsafeUnpin for AsyncWindowContextwhere
*const RcInner<AppCell> is !null: UnsafeUnpin,
*const ArcInner<dyn Scheduler> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Scheduler>>: UnsafeUnpin,
*const ArcInner<dyn PlatformDispatcher> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn PlatformDispatcher>>: UnsafeUnpin,
*const ArcInner<dyn Fn(Runnable<RunnableMeta>) + Send + Sync> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(Runnable<RunnableMeta>) + Send + Sync>>: UnsafeUnpin,
PhantomData<Rc<()>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
&'static str: UnsafeUnpin,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
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 more