Skip to main content

Application

Struct Application 

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

重导出 App 核心模块(App、Context、Entity、EntityId 等) 对 RGPUI 应用的引用,通常在应用的 main 函数中构建。 除初始配置和启动阶段外,你不会频繁与此类型交互。

Implementations§

Source§

impl Application

表示尚未完全启动的应用。配置完成后, 使用 App::run 启动应用。

Source

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

使用调用方提供的平台实现构建应用。

Source

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

强制禁用无障碍(AccessKit)集成来构建应用。

在此模式下,无障碍 API(如 [div().role()][crate::StatefulInteractiveElement::role]) 会静默地不执行任何操作。

参见无障碍指南了解被禁用功能的概述。

Source

pub fn with_assets(self, asset_source: impl AssetSource) -> Self

设置应用的资源来源。

Source

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

设置应用的 HTTP 客户端。

Source

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

配置应用自动退出的时机。 默认使用 QuitMode::Default。

Source

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

启动应用。提供的回调将在应用完全启动后被调用。

Source

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

为自行驱动运行循环的嵌入方启动应用。

在普通平台上,Platform::run 会在应用生命周期内阻塞,应用状态由 Application::run 的栈帧保持存活。嵌入平台(即运行循环归属他方, 例如编译为 Wasm guest 的 RGPUI,或托管在外部原生应用中的 RGPUI 视图) 实现 Platform::run 时会调用启动回调后立即返回。本方法支持这种模式: 它返回一个 ApplicationHandle 来保持应用存活,并允许嵌入方在外部运行 循环交还控制权时重新进入应用。

Source

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

注册一个处理器,当平台指示应用打开一个或多个 URL 时被调用。

Source

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

当已运行的应用再次被启动时调用处理器。 在 macOS 上,双击应用图标或通过 Dock 启动应用时会触发此回调。

Source

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

当系统从休眠中唤醒时调用处理器。

Source

pub fn background_executor(&self) -> BackgroundExecutor

返回与此应用关联的 BackgroundExecutor 句柄,可用于在后台生成 future。

Source

pub fn foreground_executor(&self) -> ForegroundExecutor

返回与此应用关联的 ForegroundExecutor 句柄,可用于在前台生成 future。

Source

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

返回与此应用关联的 TextSystem 引用。

Source

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

返回应用 bundle 中指定名称的可执行文件的文件 URL

Auto Trait Implementations§

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<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> ErasedDestructor for T
where T: 'static,

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<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 = !

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