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>
pub fn update<R>( &mut self, update: impl FnOnce(&mut Window, &mut App) -> R, ) -> Result<R>
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>
pub fn update_root<R>( &mut self, update: impl FnOnce(AnyView, &mut Window, &mut App) -> R, ) -> Result<R>
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: Global, R>(
&mut self,
read: impl FnOnce(&G, &Window, &App) -> R,
) -> Result<R>
pub fn read_global<G: Global, R>( &mut self, read: impl FnOnce(&G, &Window, &App) -> R, ) -> Result<R>
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>where
G: Global,
pub fn update_global<G, R>(
&mut self,
update: impl FnOnce(&mut G, &mut Window, &mut App) -> R,
) -> Result<R>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 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) -> Result<R>
pub fn update<R>(&self, f: impl FnOnce(&mut App) -> R) -> Result<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,
) -> Result<Subscription>where
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,
) -> Result<Subscription>where
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>>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>>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: Global>(&self) -> Result<bool>
pub fn has_global<G: Global>(&self) -> Result<bool>
Determine whether global state of the specified type has been assigned.
Returns an error if the App has been dropped.
Sourcepub fn read_global<G: Global, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Result<R>
pub fn read_global<G: Global, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Result<R>
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.
Returns an error if the App has been dropped.
Sourcepub fn try_read_global<G: Global, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Option<R>
pub fn try_read_global<G: Global, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Option<R>
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
if no state of the specified type has been assigned.
Returns an error if no state of the specified type has been assigned the App has been dropped.
Sourcepub fn try_read_default_global<G: Global + Default, R>(
&self,
read: impl FnOnce(&G, &App) -> R,
) -> Result<R>
pub fn try_read_default_global<G: Global + Default, R>( &self, read: impl FnOnce(&G, &App) -> R, ) -> Result<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.
§Errors
If the app has ben dropped this returns an error.
Sourcepub fn update_global<G: Global, R>(
&self,
update: impl FnOnce(&mut G, &mut App) -> R,
) -> Result<R>
pub fn update_global<G: Global, R>( &self, update: impl FnOnce(&mut G, &mut App) -> R, ) -> Result<R>
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§type Result<T> = Result<T, Error>
type Result<T> = Result<T, Error>
Source§fn new<T>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Result<Entity<T>>where
T: 'static,
fn new<T>(
&mut self,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Result<Entity<T>>where
T: 'static,
Source§fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>>
fn reserve_entity<T: 'static>(&mut self) -> Result<Reservation<T>>
Source§fn insert_entity<T: 'static>(
&mut self,
reservation: Reservation<T>,
build_entity: impl FnOnce(&mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>
fn insert_entity<T: 'static>( &mut self, reservation: Reservation<T>, build_entity: impl FnOnce(&mut Context<'_, T>) -> T, ) -> Self::Result<Entity<T>>
reserve_entity.Source§fn update_entity<T: 'static, R>(
&mut self,
handle: &Entity<T>,
update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R,
) -> Result<R>
fn update_entity<T: 'static, R>( &mut self, handle: &Entity<T>, update: impl FnOnce(&mut T, &mut Context<'_, T>) -> R, ) -> Result<R>
Source§fn as_mut<'a, T>(&'a mut self, _: &Entity<T>) -> Self::Result<GpuiBorrow<'a, T>>where
T: 'static,
fn as_mut<'a, T>(&'a mut self, _: &Entity<T>) -> Self::Result<GpuiBorrow<'a, T>>where
T: 'static,
Source§fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
T: 'static,
fn read_entity<T, R>(
&self,
handle: &Entity<T>,
read: impl FnOnce(&T, &App) -> R,
) -> Self::Result<R>where
T: 'static,
Source§fn update_window<T, F>(
&mut self,
window: AnyWindowHandle,
update: F,
) -> Result<T>
fn update_window<T, F>( &mut self, window: AnyWindowHandle, update: F, ) -> Result<T>
Source§fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>where
T: 'static,
fn read_window<T, R>(
&self,
window: &WindowHandle<T>,
read: impl FnOnce(Entity<T>, &App) -> R,
) -> Result<R>where
T: 'static,
Source§impl Clone for AsyncWindowContext
impl Clone for AsyncWindowContext
Source§fn clone(&self) -> AsyncWindowContext
fn clone(&self) -> AsyncWindowContext
1.0.0 · 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: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>
fn new_window_entity<T: 'static>( &mut self, build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T, ) -> Self::Result<Entity<T>>
Window.Source§fn update_window_entity<T: 'static, R>(
&mut self,
view: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
) -> Self::Result<R>
fn update_window_entity<T: 'static, R>( &mut self, view: &Entity<T>, update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R, ) -> Self::Result<R>
Auto Trait Implementations§
impl Freeze for AsyncWindowContext
impl !RefUnwindSafe for AsyncWindowContext
impl !Send for AsyncWindowContext
impl !Sync for AsyncWindowContext
impl Unpin for AsyncWindowContext
impl !UnwindSafe for AsyncWindowContext
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> 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.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