Skip to main content

Application

Struct Application 

Source
pub struct Application(/* private fields */);
Expand description

The entry point for a GPUI application. Configure it, then call Application::run.

Get one from gpui_platform::application(), which picks the platform for the current target. Configure it with the with_* and on_* builder methods, then call Application::run from main. The callback you pass to run receives the App once the platform has finished launching. That is where you open windows, bind keys and set globals.

The with_* methods take the application by value and return it, so you can chain them. Call them before Application::run.

run blocks until the app quits on native platforms, so anything after it in main runs only after the app exits. Once the app is running, you use App instead of Application.

§Examples

use gpui::{App, Window, WindowOptions, div, prelude::*};

struct HelloWorld;

impl Render for HelloWorld {
    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
        div().child("Hello, world!")
    }
}

fn main() {
    gpui_platform::application().run(|cx: &mut App| {
        cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| HelloWorld))
            .unwrap();
    });
}

See the start a project guide for a complete app. TestApp runs app code without a display, and is available with the test-support feature.

Implementations§

Source§

impl Application

Source

pub fn with_platform(platform: Rc<dyn Platform>) -> Self

Creates an application that uses a platform implementation you provide.

Most apps should use gpui_platform::application(), which chooses the platform for you. Use this when you want a custom or test platform. The app starts with an empty AssetRegistry, an HTTP client that fails every request, and QuitMode::Default.

§Panics

Panics if called from a thread other than the main thread.

Source

pub fn new_inaccessible(platform: Rc<dyn Platform>) -> Self

Builds an app with accessibility (AccessKit) integration forcibly disabled.

In this mode, accessibility APIs (e.g. div().role()) silently no-op.

See the accessibility guide for the features this disables.

Source

pub fn with_accessibility_forced(self) -> Self

Build every window’s accessibility tree every frame, even when no assistive technology is connected.

For automation and tree inspection: crate::Window::debug_a11y_tree_json otherwise reports nothing until a screen reader activates the platform adapter. Application::new_inaccessible still wins when both are set.

Source

pub fn with_assets(self, assets: impl Into<AssetRegistry>) -> Self

Sets the source of assets (images, fonts and SVGs) that the app loads by path.

The registry is returned by App::assets, and the SVG renderer is rebuilt to read from it. Set it before you open windows that load assets.

Source

pub fn with_restart_arguments(self, arguments: Vec<OsString>) -> Self

Sets the command-line arguments that App::restart passes to the new process.

Source

pub fn with_http_client(self, http_client: Arc<dyn HttpClient>) -> Self

Sets the HTTP client that App::http_client returns.

The default fails every request. Pass a real client to let the app fetch URLs, for example for remote images.

Source

pub fn with_quit_mode(self, mode: QuitMode) -> Self

Sets when the app quits on its own. See QuitMode for the choices.

Defaults to QuitMode::Default. You can also change it at runtime with App::set_quit_mode.

Source

pub fn with_windowing(self, request: WindowingRequest) -> Self

Starts the event loop and calls on_finish_launching once the app has launched.

The callback runs on the main thread with the App, and runs once. Open your first window there. On native platforms this method blocks until the app quits, so code after it runs only after the app exits. On the web it returns right away, and the app keeps running in the page.

See the Application example for a complete main. Sets the windowing mode the app starts in. See App::request_windowing.

Defaults to windowed. On Linux, the default environment is the process’s own, and the app starts headless if that names no allowed display server. On macOS, headless means the app starts without a Dock icon or menu bar (ActivationPolicy::Accessory). Has no effect on other platforms.

Source

pub fn run<F>(self, on_finish_launching: F)
where F: 'static + FnOnce(&mut App),

Start the application. The provided callback will be called once the app is fully launched.

On WebAssembly, this returns immediately and retains the app for the lifetime of the Wasm instance. Use Self::run_embedded to control its lifetime explicitly.

Source

pub fn run_embedded<F>(self, on_finish_launching: F) -> ApplicationHandle
where F: 'static + FnOnce(&mut App),

Start the application for an embedder that drives the run loop itself.

On ordinary platforms Platform::run blocks for the lifetime of the app, and the app state is kept alive by Application::run’s stack frame. Embedded platforms — where the run loop belongs to someone else, e.g. GPUI compiled into a Wasm guest, or a GPUI view hosted inside a foreign native application — implement Platform::run to invoke the launch callback and return immediately. This method supports that shape: it returns an ApplicationHandle that keeps the app alive and lets the embedder re-enter it whenever the external run loop yields control.

Source

pub fn on_open_urls<F>(&self, callback: F) -> &Self
where F: 'static + FnMut(Vec<String>),

Registers a handler for URLs that the user asks the app to open.

The handler receives the URLs as strings. Register a scheme with App::register_url_scheme so the platform routes links with that scheme to the app.

Source

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

Registers a handler for a second launch while the app is already running.

On macOS this happens when the user clicks the app icon in the Dock or in Finder. A common response is to open a window if none is visible. The handler receives the App.

Source

pub fn background_executor(&self) -> BackgroundExecutor

Returns the executor for Send futures. See BackgroundExecutor for platform behavior.

Source

pub fn foreground_executor(&self) -> ForegroundExecutor

Returns the executor for futures that run on the foreground thread.

Source

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

Returns a shared handle to the app’s TextSystem, which shapes and rasterizes text.

Source

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

Returns the path to a helper executable named name that ships with the app.

Use this to launch a companion binary, such as a CLI or a helper process. It returns an error if the platform cannot find the executable.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
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, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
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<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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
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, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
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> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
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