Skip to main content

VisualContext

Trait VisualContext 

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

Source

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§

Source

fn window_handle(&self) -> AnyWindowHandle

Returns the handle of the window this context works in.

Source

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.

Source

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.

Source

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,

Replaces the root view of the window with the view that build_view creates, and returns a handle to the new view.

Source

fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
where V: Focusable,

Moves keyboard focus to entity, using its Focusable::focus_handle.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§