Struct gpui2::AppContext

source ·
pub struct AppContext { /* private fields */ }

Implementations§

source§

impl AppContext

source

pub fn shutdown(&mut self)

Quit the application gracefully. Handlers registered with ModelContext::on_app_quit will be given 100ms to complete before exiting.

source

pub fn quit(&mut self)

source

pub fn app_metadata(&self) -> AppMetadata

source

pub fn refresh(&mut self)

Schedules all windows in the application to be redrawn. This can be called multiple times in an update cycle and still result in a single redraw.

source

pub fn observe<W, E>( &mut self, entity: &E, on_notify: impl FnMut(E, &mut AppContext) + 'static ) -> Subscriptionwhere W: 'static, E: Entity<W>,

source

pub fn observe_internal<W, E>( &mut self, entity: &E, on_notify: impl FnMut(E, &mut AppContext) -> bool + 'static ) -> Subscriptionwhere W: 'static, E: Entity<W>,

source

pub fn subscribe<T, E, Evt>( &mut self, entity: &E, on_event: impl FnMut(E, &Evt, &mut AppContext) + 'static ) -> Subscriptionwhere T: 'static + EventEmitter<Evt>, E: Entity<T>, Evt: 'static,

source

pub fn windows(&self) -> Vec<AnyWindowHandle>

source

pub fn open_window<V: 'static + Render>( &mut self, options: WindowOptions, build_root_view: impl FnOnce(&mut WindowContext<'_>) -> View<V> ) -> WindowHandle<V>

Opens a new window with the given option and the root view returned by the given function. The function is invoked with a WindowContext, which can be used to interact with window-specific functionality.

source

pub fn activate(&self, ignoring_other_apps: bool)

Instructs the platform to activate the application by bringing it to the foreground.

source

pub fn hide(&self)

source

pub fn hide_other_apps(&self)

source

pub fn unhide_other_apps(&self)

source

pub fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>

Returns the list of currently active displays.

source

pub fn write_to_clipboard(&self, item: ClipboardItem)

Writes data to the platform clipboard.

source

pub fn read_from_clipboard(&self) -> Option<ClipboardItem>

Reads data from the platform clipboard.

source

pub fn write_credentials( &self, url: &str, username: &str, password: &[u8] ) -> Result<()>

Writes credentials to the platform keychain.

source

pub fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>>

Reads credentials from the platform keychain.

source

pub fn delete_credentials(&self, url: &str) -> Result<()>

Deletes credentials from the platform keychain.

source

pub fn open_url(&self, url: &str)

Directs the platform’s default browser to open the given URL.

source

pub fn app_path(&self) -> Result<PathBuf>

source

pub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>

source

pub fn prompt_for_paths( &self, options: PathPromptOptions ) -> Receiver<Option<Vec<PathBuf>>>

source

pub fn prompt_for_new_path(&self, directory: &Path) -> Receiver<Option<PathBuf>>

source

pub fn reveal_path(&self, path: &Path)

source

pub fn should_auto_hide_scrollbars(&self) -> bool

source

pub fn to_async(&self) -> AsyncAppContext

Creates an AsyncAppContext, which can be cloned and has a static lifetime so it can be held across await points.

source

pub fn background_executor(&self) -> &BackgroundExecutor

Obtains a reference to the executor, which can be used to spawn futures.

source

pub fn foreground_executor(&self) -> &ForegroundExecutor

Obtains a reference to the executor, which can be used to spawn futures.

source

pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R> where Fut: Future<Output = R> + 'static, R: 'static,

Spawns the future returned by the given function on the thread pool. The closure will be invoked with AsyncAppContext, which allows the application state to be accessed across await points.

source

pub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static)

Schedules the given function to be run at the end of the current effect cycle, allowing entities that are currently on the stack to be returned to the app.

source

pub fn asset_source(&self) -> &Arc<dyn AssetSource>

Accessor for the application’s asset source, which is provided when constructing the App.

source

pub fn text_system(&self) -> &Arc<TextSystem>

Accessor for the text system.

source

pub fn text_style(&self) -> TextStyle

The current text style. Which is composed of all the style refinements provided to with_text_style.

source

pub fn has_global<G: 'static>(&self) -> bool

Check whether a global of the given type has been assigned.

source

pub fn global<G: 'static>(&self) -> &G

Access the global of the given type. Panics if a global for that type has not been assigned.

source

pub fn try_global<G: 'static>(&self) -> Option<&G>

Access the global of the given type if a value has been assigned.

source

pub fn global_mut<G: 'static>(&mut self) -> &mut G

Access the global of the given type mutably. Panics if a global for that type has not been assigned.

source

pub fn default_global<G: 'static + Default>(&mut self) -> &mut G

Access the global of the given type mutably. A default value is assigned if a global of this type has not yet been assigned.

source

pub fn set_global<G: Any>(&mut self, global: G)

Set the value of the global of the given type.

source

pub fn update_global<G: 'static, R>( &mut self, f: impl FnOnce(&mut G, &mut Self) -> R ) -> R

Update the global of the given type with a closure. Unlike global_mut, this method provides your closure with mutable access to the AppContext and the global simultaneously.

source

pub fn observe_global<G: 'static>( &mut self, f: impl FnMut(&mut Self) + 'static ) -> Subscription

Register a callback to be invoked when a global of the given type is updated.

source

pub fn observe_new_views<V: 'static>( &mut self, on_new: impl 'static + Fn(&mut V, &mut ViewContext<'_, V>) ) -> Subscription

source

pub fn observe_release<E, T>( &mut self, handle: &E, on_release: impl FnOnce(&mut T, &mut AppContext) + 'static ) -> Subscriptionwhere E: Entity<T>, T: 'static,

source

pub fn bind_keys(&mut self, bindings: impl IntoIterator<Item = KeyBinding>)

Register key bindings.

source

pub fn on_action<A: Action>( &mut self, listener: impl Fn(&A, &mut Self) + 'static )

Register a global listener for actions invoked via the keyboard.

source

pub fn stop_propagation(&mut self)

Event handlers propagate events by default. Call this method to stop dispatching to event handlers with a lower z-index (mouse) or higher in the tree (keyboard). This is the opposite of [propagate]. It’s also possible to cancel a call to [propagate] by calling this method before effects are flushed.

source

pub fn propagate(&mut self)

Action handlers stop propagation by default during the bubble phase of action dispatch dispatching to action handlers higher in the element tree. This is the opposite of [stop_propagation]. It’s also possible to cancel a call to [stop_propagate] by calling this method before effects are flushed.

source

pub fn build_action( &self, name: &str, data: Option<Value> ) -> Result<Box<dyn Action>>

source

pub fn all_action_names(&self) -> &[SharedString]

Trait Implementations§

source§

impl<T> Borrow<AppContext> for ModelContext<'_, T>

source§

fn borrow(&self) -> &AppContext

Immutably borrows from an owned value. Read more
source§

impl<V> Borrow<AppContext> for ViewContext<'_, V>

source§

fn borrow(&self) -> &AppContext

Immutably borrows from an owned value. Read more
source§

impl<'a> Borrow<AppContext> for WindowContext<'a>

source§

fn borrow(&self) -> &AppContext

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<AppContext> for ModelContext<'_, T>

source§

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

Mutably borrows from an owned value. Read more
source§

impl<V> BorrowMut<AppContext> for ViewContext<'_, V>

source§

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

Mutably borrows from an owned value. Read more
source§

impl<'a> BorrowMut<AppContext> for WindowContext<'a>

source§

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

Mutably borrows from an owned value. Read more
source§

impl Context for AppContext

source§

fn build_model<T: 'static>( &mut self, build_model: impl FnOnce(&mut ModelContext<'_, T>) -> T ) -> Model<T>

Build an entity that is owned by the application. The given function will be invoked with a ModelContext and must return an object representing the entity. A Model will be returned which can be used to access the entity in a context.

source§

fn update_model<T: 'static, R>( &mut self, model: &Model<T>, update: impl FnOnce(&mut T, &mut ModelContext<'_, T>) -> R ) -> R

Update the entity referenced by the given model. The function is passed a mutable reference to the entity along with a ModelContext for the entity.

§

type Result<T> = T

source§

fn update_window<T, F>( &mut self, handle: AnyWindowHandle, update: F ) -> Result<T>where F: FnOnce(AnyView, &mut WindowContext<'_>) -> T,

source§

fn read_model<T, R>( &self, handle: &Model<T>, read: impl FnOnce(&T, &AppContext) -> R ) -> Self::Result<R>where T: 'static,

source§

fn read_window<T, R>( &self, window: &WindowHandle<T>, read: impl FnOnce(View<T>, &AppContext) -> R ) -> Result<R>where T: 'static,

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<C> BorrowAppContext for Cwhere C: BorrowMut<AppContext>,

source§

fn with_text_style<F, R>( &mut self, style: Option<TextStyleRefinement>, f: F ) -> Rwhere F: FnOnce(&mut C) -> R,

source§

fn set_global<G>(&mut self, global: G)where G: 'static,

source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more