pub trait VisualContext: AppContext {
type Result<T>;
// Required methods
fn window_handle(&self) -> AnyWindowHandle;
fn update_window_entity<T: 'static, R>(
&mut self,
entity: &Entity<T>,
update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R,
) -> Self::Result<R>;
fn new_window_entity<T: 'static>(
&mut self,
build_entity: impl FnOnce(&mut Window, &mut Context<'_, T>) -> T,
) -> Self::Result<Entity<T>>;
fn replace_root_view<V>(
&mut self,
build_view: impl FnOnce(&mut Window, &mut Context<'_, V>) -> V,
) -> Self::Result<Entity<V>>
where V: 'static + Render;
fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
where V: Focusable;
}Expand description
Operations that need a window.
Contexts that have a window implement this, including AsyncWindowContext.
Import it along with AppContext from gpui::prelude.
Required Associated Types§
Sourcetype Result<T>
type Result<T>
The return type of window operations.
AsyncWindowContext uses Result, because the window may have closed by the
time the call runs.
Required Methods§
Sourcefn window_handle(&self) -> AnyWindowHandle
fn window_handle(&self) -> AnyWindowHandle
Returns the handle of the window this context works in.
Sourcefn update_window_entity<T: 'static, R>(
&mut self,
entity: &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, entity: &Entity<T>, update: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) -> R, ) -> Self::Result<R>
Runs update with the entity, its window and a Context for the entity, and
returns the result, wrapped in VisualContext::Result.
Sourcefn 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>>
Creates an entity with access to the window.
build_entity receives the window and a Context for the new entity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".