Context

Struct Context 

Source
pub struct Context<'a, T> { /* private fields */ }
Expand description

The app context, with specialized behavior for the given entity.

Implementations§

Source§

impl<'a, T: 'static> Context<'a, T>

Source

pub fn entity_id(&self) -> EntityId

The entity id of the entity backing this context.

Source

pub fn entity(&self) -> Entity<T>

Returns a handle to the entity belonging to this context.

Source

pub fn weak_entity(&self) -> WeakEntity<T>

Returns a weak handle to the entity belonging to this context.

Source

pub fn observe<W>( &mut self, entity: &Entity<W>, on_notify: impl FnMut(&mut T, Entity<W>, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: 'static, W: 'static,

Arranges for the given function to be called whenever Context::notify is called with the given entity.

Source

pub fn observe_self( &mut self, on_event: impl FnMut(&mut T, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: 'static,

Observe changes to ourselves

Source

pub fn subscribe<T2, Evt>( &mut self, entity: &Entity<T2>, on_event: impl FnMut(&mut T, Entity<T2>, &Evt, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: 'static, T2: 'static + EventEmitter<Evt>, Evt: 'static,

Subscribe to an event type from another entity

Source

pub fn subscribe_self<Evt>( &mut self, on_event: impl FnMut(&mut T, &Evt, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: 'static + EventEmitter<Evt>, Evt: 'static,

Subscribe to an event type from ourself

Source

pub fn on_release( &self, on_release: impl FnOnce(&mut T, &mut App) + 'static, ) -> Subscription
where T: 'static,

Register a callback to be invoked when GPUI releases this entity.

Source

pub fn observe_release<T2>( &self, entity: &Entity<T2>, on_release: impl FnOnce(&mut T, &mut T2, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: Any, T2: 'static,

Register a callback to be run on the release of another entity

Source

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

Register a callback to for updates to the given global

Source

pub fn on_app_restart( &self, on_restart: impl FnMut(&mut T, &mut App) + 'static, ) -> Subscription
where T: 'static,

Register a callback to be invoked when the application is about to restart.

Source

pub fn on_app_quit<Fut>( &self, on_quit: impl FnMut(&mut T, &mut Context<'_, T>) -> Fut + 'static, ) -> Subscription
where Fut: 'static + Future<Output = ()>, T: 'static,

Arrange for the given function to be invoked whenever the application is quit. The future returned from this callback will be polled for up to crate::SHUTDOWN_TIMEOUT until the app fully quits.

Source

pub fn notify(&mut self)

Tell GPUI that this entity has changed and observers of it should be notified.

Source

pub fn spawn<AsyncFn, R>(&self, f: AsyncFn) -> Task<R>
where T: 'static, AsyncFn: AsyncFnOnce(WeakEntity<T>, &mut AsyncApp) -> R + 'static, R: 'static,

Spawn the future returned by the given function. The function is provided a weak handle to the entity owned by this context and a context that can be held across await points. The returned task must be held or detached.

Source

pub fn listener<E: ?Sized>( &self, f: impl Fn(&mut T, &E, &mut Window, &mut Context<'_, T>) + 'static, ) -> impl Fn(&E, &mut Window, &mut App) + 'static

Convenience method for accessing view state in an event callback.

Many GPUI callbacks take the form of Fn(&E, &mut Window, &mut App), but it’s often useful to be able to access view state in these callbacks. This method provides a convenient way to do so.

Source

pub fn processor<E, R>( &self, f: impl Fn(&mut T, E, &mut Window, &mut Context<'_, T>) -> R + 'static, ) -> impl Fn(E, &mut Window, &mut App) -> R + 'static

Convenience method for producing view state in a closure. See listener for more details.

Source

pub fn on_drop( &self, f: impl FnOnce(&mut T, &mut Context<'_, T>) + 'static, ) -> Deferred<impl FnOnce()>

Run something using this entity and cx, when the returned struct is dropped

Source

pub fn focus_view<W: Focusable>( &mut self, view: &Entity<W>, window: &mut Window, )

Focus the given view in the given window. View type is required to implement Focusable.

Source

pub fn on_next_frame( &self, window: &mut Window, f: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) + 'static, )
where T: 'static,

Sets a given callback to be run on the next frame.

Source

pub fn defer_in( &mut self, window: &Window, f: impl FnOnce(&mut T, &mut Window, &mut Context<'_, T>) + '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 observe_in<V2>( &mut self, observed: &Entity<V2>, window: &mut Window, on_notify: impl FnMut(&mut T, Entity<V2>, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription
where V2: 'static, T: 'static,

Observe another entity for changes to its state, as tracked by Context::notify.

Source

pub fn subscribe_in<Emitter, Evt>( &mut self, emitter: &Entity<Emitter>, window: &Window, on_event: impl FnMut(&mut T, &Entity<Emitter>, &Evt, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription
where Emitter: EventEmitter<Evt>, Evt: 'static,

Subscribe to events emitted by another entity. The entity to which you’re subscribing must implement the EventEmitter trait. The callback will be invoked with a reference to the current view, a handle to the emitting Entity, the event, a mutable reference to the Window, and the context for the entity.

Source

pub fn on_release_in( &mut self, window: &Window, on_release: impl FnOnce(&mut T, &mut Window, &mut App) + 'static, ) -> Subscription

Register a callback to be invoked when the view is released.

The callback receives a handle to the view’s window. This handle may be invalid, if the window was closed before the view was released.

Source

pub fn observe_release_in<T2>( &self, observed: &Entity<T2>, window: &Window, on_release: impl FnMut(&mut T, &mut T2, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription
where T: 'static, T2: 'static,

Register a callback to be invoked when the given Entity is released.

Source

pub fn observe_window_bounds( &self, window: &mut Window, callback: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a callback to be invoked when the window is resized.

Source

pub fn observe_window_activation( &self, window: &mut Window, callback: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a callback to be invoked when the window is activated or deactivated.

Source

pub fn observe_window_appearance( &self, window: &mut Window, callback: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Registers a callback to be invoked when the window appearance changes.

Source

pub fn observe_keystrokes( &mut self, f: impl FnMut(&mut T, &KeystrokeEvent, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a callback to be invoked when a keystroke is received by the application in any window. Note that this fires after all other action and event mechanisms have resolved and that this API will not be invoked if the event’s propagation is stopped.

Source

pub fn observe_pending_input( &self, window: &mut Window, callback: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a callback to be invoked when the window’s pending input changes.

Source

pub fn on_focus( &mut self, handle: &FocusHandle, window: &mut Window, listener: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle receives focus. Returns a subscription and persists until the subscription is dropped.

Source

pub fn on_focus_in( &mut self, handle: &FocusHandle, window: &mut Window, listener: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle or one of its descendants receives focus. This does not fire if the given focus handle - or one of its descendants - was previously focused. Returns a subscription and persists until the subscription is dropped.

Source

pub fn on_blur( &mut self, handle: &FocusHandle, window: &mut Window, listener: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle loses focus. Returns a subscription and persists until the subscription is dropped.

Source

pub fn on_focus_lost( &mut self, window: &mut Window, listener: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a listener to be called when nothing in the window has focus. This typically happens when the node that was focused is removed from the tree, and this callback lets you chose a default place to restore the users focus. Returns a subscription and persists until the subscription is dropped.

Source

pub fn on_focus_out( &mut self, handle: &FocusHandle, window: &mut Window, listener: impl FnMut(&mut T, FocusOutEvent, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a listener to be called when the given focus handle or one of its descendants loses focus. Returns a subscription and persists until the subscription is dropped.

Source

pub fn spawn_in<AsyncFn, R>(&self, window: &Window, f: AsyncFn) -> Task<R>
where R: 'static, AsyncFn: AsyncFnOnce(WeakEntity<T>, &mut AsyncWindowContext) -> R + 'static,

Schedule a future to be run asynchronously. The given callback is invoked with a WeakEntity<V> to avoid leaking the entity for a long-running process. It’s also given an AsyncWindowContext, which can be used to access the state of the entity across await points. The returned future will be polled on the main thread.

Source

pub fn spawn_in_with_priority<AsyncFn, R>( &self, priority: Priority, window: &Window, f: AsyncFn, ) -> Task<R>
where R: 'static, AsyncFn: AsyncFnOnce(WeakEntity<T>, &mut AsyncWindowContext) -> R + 'static,

Schedule a future to be run asynchronously with the given priority. The given callback is invoked with a WeakEntity<V> to avoid leaking the entity for a long-running process. It’s also given an AsyncWindowContext, which can be used to access the state of the entity across await points. The returned future will be polled on the main thread.

Source

pub fn observe_global_in<G: Global>( &mut self, window: &Window, f: impl FnMut(&mut T, &mut Window, &mut Context<'_, T>) + 'static, ) -> Subscription

Register a callback to be invoked when the given global state changes.

Source

pub fn on_action( &mut self, action_type: TypeId, window: &mut Window, listener: impl Fn(&mut T, &dyn Any, DispatchPhase, &mut Window, &mut Context<'_, T>) + 'static, )

Register a callback to be invoked when the given Action type is dispatched to the window.

Source

pub fn focus_self(&mut self, window: &mut Window)
where T: Focusable,

Move focus to the current view, assuming it implements Focusable.

Source§

impl<T> Context<'_, T>

Source

pub fn emit<Evt>(&mut self, event: Evt)
where T: EventEmitter<Evt>, Evt: 'static,

Emit an event of the specified type, which can be handled by other entities that have subscribed via subscribe methods on their respective contexts.

Methods from Deref<Target = App>§

Source

pub fn shutdown(&mut self)

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

Source

pub fn keyboard_layout(&self) -> &dyn PlatformKeyboardLayout

Get the id of the current keyboard layout

Source

pub fn keyboard_mapper(&self) -> &Rc<dyn PlatformKeyboardMapper>

Get the current keyboard mapper.

Source

pub fn on_keyboard_layout_change<F>(&self, callback: F) -> Subscription
where F: 'static + FnMut(&mut App),

Invokes a handler when the current keyboard layout changes

Source

pub fn quit(&self)

Gracefully quit the application via the platform’s standard routine.

Source

pub fn refresh_windows(&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>( &mut self, entity: &Entity<W>, on_notify: impl FnMut(Entity<W>, &mut App) + 'static, ) -> Subscription
where W: 'static,

Arrange a callback to be invoked when the given entity calls notify on its respective context.

Source

pub fn subscribe<T, Event>( &mut self, entity: &Entity<T>, on_event: impl FnMut(Entity<T>, &Event, &mut App) + 'static, ) -> 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.

Source

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

Returns handles to all open windows in the application. Each handle could be downcast to a handle typed for the root view of that window. To find all windows of a given type, you could filter on

Source

pub fn window_stack(&self) -> Option<Vec<AnyWindowHandle>>

Returns the window handles ordered by their appearance on screen, front to back.

The first window in the returned list is the active/topmost window of the application.

This method returns None if the platform doesn’t implement the method yet.

Source

pub fn active_window(&self) -> Option<AnyWindowHandle>

Returns a handle to the window that is currently focused at the platform level, if one exists.

Source

pub fn open_window<V: 'static + Render>( &mut self, options: WindowOptions, build_root_view: impl FnOnce(&mut Window, &mut App) -> Entity<V>, ) -> Result<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 Window, 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)

Hide the application at the platform level.

Source

pub fn hide_other_apps(&self)

Hide other applications at the platform level.

Source

pub fn unhide_other_apps(&self)

Unhide other applications at the platform level.

Source

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

Returns the list of currently active displays.

Source

pub fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>>

Returns the primary display that will be used for new windows.

Source

pub fn is_screen_capture_supported(&self) -> bool

Returns whether screen_capture_sources may work.

Source

pub fn screen_capture_sources( &self, ) -> Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>>>

Returns a list of available screen capture sources.

Source

pub fn find_display(&self, id: DisplayId) -> Option<Rc<dyn PlatformDisplay>>

Returns the display with the given ID, if one exists.

Source

pub fn window_appearance(&self) -> WindowAppearance

Returns the appearance of the application’s windows.

Source

pub fn write_to_primary(&self, item: ClipboardItem)

Writes data to the primary selection buffer. Only available on Linux.

Source

pub fn write_to_clipboard(&self, item: ClipboardItem)

Writes data to the platform clipboard.

Source

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

Reads data from the primary selection buffer. Only available on Linux.

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], ) -> Task<Result<()>>

Writes credentials to the platform keychain.

Source

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

Reads credentials from the platform keychain.

Source

pub fn delete_credentials(&self, url: &str) -> Task<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 register_url_scheme(&self, scheme: &str) -> Task<Result<()>>

Registers the given URL scheme (e.g. zed for zed:// urls) to be opened by the current app.

On some platforms (e.g. macOS) you may be able to register URL schemes as part of app distribution, but this method exists to let you register schemes at runtime.

Source

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

Returns the full pathname of the current app bundle.

Returns an error if the app is not being run from a bundle.

Source

pub fn compositor_name(&self) -> &'static str

On Linux, returns the name of the compositor in use.

Returns an empty string on other platforms.

Source

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

Returns the file URL of the executable with the specified name in the application bundle

Source

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

Displays a platform modal for selecting paths.

When one or more paths are selected, they’ll be relayed asynchronously via the returned oneshot channel. If cancelled, a None will be relayed instead. May return an error on Linux if the file picker couldn’t be opened.

Source

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

Displays a platform modal for selecting a new path where a file can be saved.

The provided directory will be used to set the initial location. When a path is selected, it is relayed asynchronously via the returned oneshot channel. If cancelled, a None will be relayed instead. May return an error on Linux if the file picker couldn’t be opened.

Source

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

Reveals the specified path at the platform level, such as in Finder on macOS.

Source

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

Opens the specified path with the system’s default application.

Source

pub fn should_auto_hide_scrollbars(&self) -> bool

Returns whether the user has configured scrollbars to auto-hide at the platform level.

Source

pub fn restart(&mut self)

Restarts the application.

Source

pub fn set_restart_path(&mut self, path: PathBuf)

Sets the path to use when restarting the application.

Source

pub fn http_client(&self) -> Arc<dyn HttpClient>

Returns the HTTP client for the application.

Source

pub fn set_http_client(&mut self, new_client: Arc<dyn HttpClient>)

Sets the HTTP client for the application.

Source

pub fn set_quit_mode(&mut self, mode: QuitMode)

Configures when the application should automatically quit. By default, QuitMode::Default is used.

Source

pub fn svg_renderer(&self) -> SvgRenderer

Returns the SVG renderer used by the application.

Source

pub fn to_async(&self) -> AsyncApp

Creates an AsyncApp, 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<AsyncFn, R>(&self, f: AsyncFn) -> Task<R>
where AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static, R: 'static,

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

Source

pub fn spawn_with_priority<AsyncFn, R>( &self, priority: Priority, f: AsyncFn, ) -> Task<R>
where AsyncFn: AsyncFnOnce(&mut AsyncApp) -> R + 'static, R: 'static,

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

Source

pub fn defer(&mut self, f: impl FnOnce(&mut App) + '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 has_global<G: Global>(&self) -> bool

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

Source

pub fn global<G: Global>(&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: Global>(&self) -> Option<&G>

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

Source

pub fn global_mut<G: Global>(&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: Global + 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: Global>(&mut self, global: G)

Sets the value of the global of the given type.

Source

pub fn remove_global<G: Global>(&mut self) -> G

Remove the global of the given type from the app context. Does not notify global observers.

Source

pub fn observe_global<G: Global>( &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<T: 'static>( &self, on_new: impl 'static + Fn(&mut T, Option<&mut Window>, &mut Context<'_, T>), ) -> Subscription

Arrange for the given function to be invoked whenever a view of the specified type is created. The function will be passed a mutable reference to the view along with an appropriate context.

Source

pub fn observe_release<T>( &self, handle: &Entity<T>, on_release: impl FnOnce(&mut T, &mut App) + 'static, ) -> Subscription
where T: 'static,

Observe the release of a entity. The callback is invoked after the entity has no more strong references but before it has been dropped.

Source

pub fn observe_release_in<T>( &self, handle: &Entity<T>, window: &Window, on_release: impl FnOnce(&mut T, &mut Window, &mut App) + 'static, ) -> Subscription
where T: 'static,

Observe the release of a entity. The callback is invoked after the entity has no more strong references but before it has been dropped.

Source

pub fn observe_keystrokes( &mut self, f: impl FnMut(&KeystrokeEvent, &mut Window, &mut App) + 'static, ) -> Subscription

Register a callback to be invoked when a keystroke is received by the application in any window. Note that this fires after all other action and event mechanisms have resolved and that this API will not be invoked if the event’s propagation is stopped.

Source

pub fn intercept_keystrokes( &mut self, f: impl FnMut(&KeystrokeEvent, &mut Window, &mut App) + 'static, ) -> Subscription

Register a callback to be invoked when a keystroke is received by the application in any window. Note that this fires before all other action and event mechanisms have resolved unlike App::observe_keystrokes which fires after. This means that cx.stop_propagation calls within interceptors will prevent action dispatch

Source

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

Register key bindings.

Source

pub fn clear_key_bindings(&mut self)

Clear all key bindings in the app.

Source

pub fn key_bindings(&self) -> Rc<RefCell<Keymap>>

Get all key bindings in the app.

Source

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

Register a global handler for actions invoked via the keyboard. These handlers are run at the end of the bubble phase for actions, and so will only be invoked if there are no other handlers or if they called cx.propagate().

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 Self::propagate. It’s also possible to cancel a call to Self::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 Self::stop_propagation. It’s also possible to cancel a call to Self::stop_propagation by calling this method before effects are flushed.

Source

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

Build an action from some arbitrary data, typically a keymap entry.

Source

pub fn all_action_names(&self) -> &[&'static str]

Get all action names that have been registered. Note that registration only allows for actions to be built dynamically, and is unrelated to binding actions in the element tree.

Source

pub fn all_bindings_for_input(&self, input: &[Keystroke]) -> Vec<KeyBinding>

Returns key bindings that invoke the given action on the currently focused element, without checking context. Bindings are returned in the order they were added. For display, the last binding should take precedence.

Source

pub fn action_schemas( &self, generator: &mut SchemaGenerator, ) -> Vec<(&'static str, Option<Schema>)>

Get all non-internal actions that have been registered, along with their schemas.

Source

pub fn deprecated_actions_to_preferred_actions( &self, ) -> &HashMap<&'static str, &'static str>

Get a map from a deprecated action name to the canonical name.

Source

pub fn action_deprecation_messages( &self, ) -> &HashMap<&'static str, &'static str>

Get a map from an action name to the deprecation messages.

Source

pub fn action_documentation(&self) -> &HashMap<&'static str, &'static str>

Get a map from an action name to the documentation.

Source

pub fn on_app_quit<Fut>( &self, on_quit: impl FnMut(&mut App) -> Fut + 'static, ) -> Subscription
where Fut: 'static + Future<Output = ()>,

Register a callback to be invoked when the application is about to quit. It is not possible to cancel the quit event at this point.

Source

pub fn on_app_restart( &self, on_restart: impl 'static + FnMut(&mut App), ) -> Subscription

Register a callback to be invoked when the application is about to restart.

These callbacks are called before any on_app_quit callbacks.

Source

pub fn on_window_closed( &self, on_closed: impl FnMut(&mut App) + 'static, ) -> Subscription

Register a callback to be invoked when a window is closed The window is no longer accessible at the point this callback is invoked.

Source

pub fn is_action_available(&mut self, action: &dyn Action) -> bool

Checks if the given action is bound in the current context, as defined by the app’s current focus, the bindings in the element tree, and any global action listeners.

Source

pub fn set_menus(&self, menus: Vec<Menu>)

Sets the menu bar for this application. This will replace any existing menu bar.

Source

pub fn get_menus(&self) -> Option<Vec<OwnedMenu>>

Gets the menu bar for this application.

Source

pub fn set_dock_menu(&self, menus: Vec<MenuItem>)

Sets the right click menu for the app icon in the dock

Source

pub fn perform_dock_menu_action(&self, action: usize)

Performs the action associated with the given dock menu item, only used on Windows for now.

Source

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

Adds given path to the bottom of the list of recent paths for the application. The list is usually shown on the application icon’s context menu in the dock, and allows to open the recent files via that context menu. If the path is already in the list, it will be moved to the bottom of the list.

Source

pub fn update_jump_list( &self, menus: Vec<MenuItem>, entries: Vec<SmallVec<[PathBuf; 2]>>, ) -> Vec<SmallVec<[PathBuf; 2]>>

Updates the jump list with the updated list of recent paths for the application, only used on Windows for now. Note that this also sets the dock menu on Windows.

Source

pub fn dispatch_action(&mut self, action: &dyn Action)

Dispatch an action to the currently active window or global action handler See crate::Action for more information on how actions work

Source

pub fn has_active_drag(&self) -> bool

Is there currently something being dragged?

Source

pub fn active_drag_cursor_style(&self) -> Option<CursorStyle>

Gets the cursor style of the currently active drag operation.

Source

pub fn stop_active_drag(&mut self, window: &mut Window) -> bool

Stops active drag and clears any related effects.

Source

pub fn set_active_drag_cursor_style( &mut self, cursor_style: CursorStyle, window: &mut Window, ) -> bool

Sets the cursor style for the currently active drag operation.

Source

pub fn set_prompt_builder( &mut self, renderer: impl Fn(PromptLevel, &str, Option<&str>, &[PromptButton], PromptHandle, &mut Window, &mut App) -> RenderablePromptHandle + 'static, )

Set the prompt renderer for GPUI. This will replace the default or platform specific prompts with this custom implementation.

Source

pub fn reset_prompt_builder(&mut self)

Reset the prompt builder to the default implementation.

Source

pub fn remove_asset<A: Asset>(&mut self, source: &A::Source)

Remove an asset from GPUI’s cache

Source

pub fn fetch_asset<A: Asset>( &mut self, source: &A::Source, ) -> (Shared<Task<A::Output>>, bool)

Asynchronously load an asset, if the asset hasn’t finished loading this will return None.

Note that the multiple calls to this method will only result in one Asset::load call at a time, and the results of this call will be cached

Source

pub fn focus_handle(&self) -> FocusHandle

Obtain a new FocusHandle, which allows you to track and manipulate the keyboard focus for elements rendered within this window.

Source

pub fn notify(&mut self, entity_id: EntityId)

Tell GPUI that an entity has changed and observers of it should be notified.

Source

pub fn get_name(&self) -> Option<&'static str>

Returns the name for this App.

Source

pub fn can_select_mixed_files_and_dirs(&self) -> bool

Returns true if the platform file picker supports selecting a mix of files and directories.

Source

pub fn drop_image( &mut self, image: Arc<RenderImage>, current_window: Option<&mut Window>, )

Removes an image from the sprite atlas on all windows.

If the current window is being updated, it will be removed from App.windows, you can use current_window to specify the current window. This is a no-op if the image is not in the sprite atlas.

Source

pub fn set_inspector_renderer(&mut self, f: InspectorRenderer)

Sets the renderer for the inspector.

Source

pub fn register_inspector_element<T: 'static, R: IntoElement>( &mut self, f: impl 'static + Fn(InspectorElementId, &T, &mut Window, &mut App) -> R, )

Registers a renderer specific to an inspector state.

Source

pub fn init_colors(&mut self)

Initializes gpui’s default colors for the application.

These colors can be accessed through cx.default_colors().

Trait Implementations§

Source§

impl<T> AppContext for Context<'_, T>

Source§

type Result<U> = U

The result type for this context, used for async contexts that can’t hold a direct reference to the application context.
Source§

fn new<U: 'static>( &mut self, build_entity: impl FnOnce(&mut Context<'_, U>) -> U, ) -> Entity<U>

Create a new entity in the app context.
Source§

fn reserve_entity<U: 'static>(&mut self) -> Reservation<U>

Reserve a slot for a entity to be inserted later. The returned Reservation allows you to obtain the EntityId for the future entity.
Source§

fn insert_entity<U: 'static>( &mut self, reservation: Reservation<U>, build_entity: impl FnOnce(&mut Context<'_, U>) -> U, ) -> Self::Result<Entity<U>>

Insert a new entity in the app context based on a Reservation previously obtained from reserve_entity.
Source§

fn update_entity<U: 'static, R>( &mut self, handle: &Entity<U>, update: impl FnOnce(&mut U, &mut Context<'_, U>) -> R, ) -> R

Update a entity in the app context.
Source§

fn as_mut<'a, E>( &'a mut self, handle: &Entity<E>, ) -> Self::Result<GpuiBorrow<'a, E>>
where E: 'static,

Update a entity in the app context.
Source§

fn read_entity<U, R>( &self, handle: &Entity<U>, read: impl FnOnce(&U, &App) -> R, ) -> Self::Result<R>
where U: 'static,

Read a entity from the app context.
Source§

fn update_window<R, F>( &mut self, window: AnyWindowHandle, update: F, ) -> Result<R>
where F: FnOnce(AnyView, &mut Window, &mut App) -> R,

Update a window for the given handle.
Source§

fn read_window<U, R>( &self, window: &WindowHandle<U>, read: impl FnOnce(Entity<U>, &App) -> R, ) -> Result<R>
where U: 'static,

Read a window off of the application context.
Source§

fn background_spawn<R>( &self, future: impl Future<Output = R> + Send + 'static, ) -> Task<R>
where R: Send + 'static,

Spawn a future on a background thread
Source§

fn read_global<G, R>( &self, callback: impl FnOnce(&G, &App) -> R, ) -> Self::Result<R>
where G: Global,

Read a global from this app context
Source§

impl<T> Borrow<App> for Context<'_, T>

Source§

fn borrow(&self) -> &App

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<App> for Context<'_, T>

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<'a, T> Deref for Context<'a, T>

Source§

type Target = App

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T> DerefMut for Context<'a, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Context<'a, T>

§

impl<'a, T> !RefUnwindSafe for Context<'a, T>

§

impl<'a, T> !Send for Context<'a, T>

§

impl<'a, T> !Sync for Context<'a, T>

§

impl<'a, T> Unpin for Context<'a, T>

§

impl<'a, T> !UnwindSafe for Context<'a, T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<C> BorrowAppContext for C
where C: BorrowMut<App>,

Source§

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

Set a global value on the context.
Source§

fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut C) -> R) -> R
where G: Global,

Updates the global state of the given type.
Source§

fn update_default_global<G, R>( &mut self, f: impl FnOnce(&mut G, &mut C) -> R, ) -> R
where G: Global + Default,

Updates the global state of the given type, creating a default if it didn’t exist before.
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> 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, U> Into<U> for T
where 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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

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

Source§

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