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
impl Application
Sourcepub fn with_platform(platform: Rc<dyn Platform>) -> Self
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.
Sourcepub fn new_inaccessible(platform: Rc<dyn Platform>) -> Self
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.
Sourcepub fn with_accessibility_forced(self) -> Self
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.
Sourcepub fn with_assets(self, assets: impl Into<AssetRegistry>) -> Self
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.
Sourcepub fn with_restart_arguments(self, arguments: Vec<OsString>) -> Self
pub fn with_restart_arguments(self, arguments: Vec<OsString>) -> Self
Sets the command-line arguments that App::restart passes to the new process.
Sourcepub fn with_http_client(self, http_client: Arc<dyn HttpClient>) -> Self
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.
Sourcepub fn with_quit_mode(self, mode: QuitMode) -> Self
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.
Sourcepub fn with_windowing(self, request: WindowingRequest) -> Self
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.
Sourcepub fn run<F>(self, on_finish_launching: F)
pub fn run<F>(self, on_finish_launching: F)
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.
Sourcepub fn run_embedded<F>(self, on_finish_launching: F) -> ApplicationHandle
pub fn run_embedded<F>(self, on_finish_launching: F) -> ApplicationHandle
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.
Sourcepub fn on_open_urls<F>(&self, callback: F) -> &Self
pub fn on_open_urls<F>(&self, callback: F) -> &Self
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.
Sourcepub fn on_reopen<F>(&self, callback: F) -> &Self
pub fn on_reopen<F>(&self, callback: F) -> &Self
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.
Sourcepub fn background_executor(&self) -> BackgroundExecutor
pub fn background_executor(&self) -> BackgroundExecutor
Returns the executor for Send futures. See BackgroundExecutor for platform behavior.
Sourcepub fn foreground_executor(&self) -> ForegroundExecutor
pub fn foreground_executor(&self) -> ForegroundExecutor
Returns the executor for futures that run on the foreground thread.
Sourcepub fn text_system(&self) -> Arc<TextSystem> ⓘ
pub fn text_system(&self) -> Arc<TextSystem> ⓘ
Returns a shared handle to the app’s TextSystem, which shapes and rasterizes text.
Sourcepub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>
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§
impl !RefUnwindSafe for Application
impl !Send for Application
impl !Sync for Application
impl !UnwindSafe for Application
impl Freeze for Application
impl Unpin for Application
impl UnsafeUnpin for Application
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
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) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more