Skip to main content

Launcher

Struct Launcher 

Source
pub struct Launcher { /* private fields */ }
Expand description

The windowed runner’s builder, made by app.

Every method takes and returns the launcher; Launcher::run opens the window and runs the event loop, Launcher::open opens it and hands the loop back as a PumpRunner.

Implementations§

Source§

impl Launcher

Source

pub fn chrome(self, chrome: Chrome) -> Self

Who draws the window chrome; see Chrome. The OS by default.

Source

pub fn text_aa(self, aa: TextAa) -> Self

Glyph antialiasing; see TextAa.

Source

pub fn frame_latency(self, frames: u32) -> Self

How many frames may be queued ahead of the one on screen, for every window. Two by default (kui_wgpu::DEFAULT_FRAME_LATENCY), which keeps every vsync fed at light load; one on Windows, where one already does. On macOS 14+ frames are paced to the display, so the second queued frame costs no latency; on Linux and under a pumped runner it reaches the screen one vsync later. KUI_FRAME_LATENCY overrides the value and KUI_FRAME_PACING=0 turns the pacing off. Values below one are one.

Source

pub fn diagnostics(self, on: bool) -> Self

Whether the core looks for silent misconfigurations and the runner prints them to stderr (see diag). On in debug builds and off in release unless set, so a shipped app stays quiet.

Source

pub fn devtools(self, on: bool) -> Self

Opens the app with the devtools panel docked beside it: the event stream, the runtime’s facts and the node tree. KUI_DEVTOOLS=1 in the environment asks the same of an app that never called this. Sugar for setup_core(|c| c.set_devtools(on)).

Source

pub fn devtools_key(self, key: Accel) -> Self

Respells the chord that moves the keyboard into the devtools panel and back, and brings a hidden panel back, from its default Ctrl+Shift+I: Accel::parse("f12"), "mod+shift+d", any spelling a menu item takes. The panel’s other chords stay Ctrl+Shift+<letter>, and Ctrl+Shift+I is the app’s again. Sugar for setup_core(|c| c.set_devtools_key(key)).

Source

pub fn setup_core(self, f: impl FnOnce(&mut Core) + 'static) -> Self

Runs f on the main window’s Core before its first frame: the place for what a core is told rather than declared in a view, such as a pinned theme, set_native_menus or the devtools. Every call adds one; they run in order.

Source

pub fn core(self, core: Core) -> Self

Opens the main window on core rather than on one the launcher makes. Everything registered on it beforehand (fonts, images, sounds, tokens, a pinned theme, menus) reaches the window, and its session becomes the app’s, so a second window joins it and handles minted by an earlier headless frame keep drawing. The launcher’s own settings still apply on top, in order: Launcher::diagnostics, then KUI_DEVTOOLS, then every Launcher::setup_core. For a host that drew headless first, or built the core through a binding.

Source

pub fn deferred_events(self) -> Self

Declares that the app answers an event after on_event returns, which only a host driving the loop itself can do (Launcher::open, PumpRunner): on_event keeps the event, the pump returns, the host runs its handler and submits the next view.

With it set, an input whose events reached the app does not ask for a frame itself; the host asks with PumpRunner::request_redraw once its handler has run, so a button’s release and what the release did land in one frame instead of two. Nothing else changes: a transition, a caret blink, a Waker wake or the OS’s own repaint still paint when they ask, and an input that reached nobody still asks for its own frame.

Source

pub fn system(self, pinned: SystemEnv) -> Self

Pins part of env.system for this app’s windows. Every field of pinned that is not “cannot tell” is what the views read, over whatever the OS says, for as long as the app runs; the fields left at their default keep following the OS, and a change to one of those still arrives as the system event.

kui_native::app("mine").system(SystemEnv { motion: MotionPref::Reduced, ..Default::default() });

Use it to see the window a user who asked for less motion, or a dark appearance, would get. It is on the launcher rather than an environment variable so that a shipped app’s motion is decided in its own code; a headless core takes the same reading through core.env.system.

Source

pub fn icon(self, rgba: Vec<u8>, width: u32, height: u32) -> Self

The icon every window of the app is created with: rgba is width by height pixels, four bytes each, row by row from the top left, alpha not premultiplied. Windows shows it in the title bar, Alt-Tab and the taskbar, X11 in the window manager’s; macOS and Wayland take the app’s icon from the bundle or the .desktop file and ignore this. Pass something a taskbar can shrink cleanly, 64 to 256 px. Panics when the pixels are not that size; Launcher::try_icon returns the reason instead.

kui_native::app("mine").icon(rgba, 64, 64);

On Windows, Launcher::icon_resource names the icon linked into the executable and wins over these pixels.

Source

pub fn try_icon( self, rgba: Vec<u8>, width: u32, height: u32, ) -> Result<Self, String>

Launcher::icon for pixels that came from outside the program, refused with the reason rather than a panic. The launcher is consumed either way.

Source

pub fn icon_resource(self, id: u16) -> Self

The executable’s icon resource id as every window’s icon, on Windows: the .ico a 1 ICON "app.ico" line in the program’s .rc links in, from which the title bar and the taskbar each load the frame drawn for their size. A resource the executable does not have is reported once on stderr, and Launcher::icon’s pixels are used if there are any. Nothing on other platforms, so an app passes both and each OS takes its own.

Source

pub fn custom_titlebar(self) -> Self

Shorthand for .chrome(Chrome::Custom).

Source

pub fn borderless(self) -> Self

Shorthand for .chrome(Chrome::Borderless).

Source

pub fn size(self, w: f64, h: f64) -> Self

Initial inner size, logical px (KUI_WINDOW=WxH still overrides). Clamped into the min_size/max_size bounds, as the OS would.

Source

pub fn min_size(self, w: f64, h: f64) -> Self

Smallest inner size the user may resize the window to, logical px. The OS enforces it; the initial size is clamped up into it.

Source

pub fn max_size(self, w: f64, h: f64) -> Self

Largest inner size the user may resize the window to, logical px. A bound below the matching min_size loses to it, as on the OS side.

Source

pub fn extension(self, ext: impl Extension + 'static) -> Self

Loads ext under its own name as its namespace. The slots it fills are declared as ui.slot("<name>/<slot>"). Panics when the name is already another extension’s namespace; two of one name need Launcher::extension_as.

Source

pub fn extension_as( self, namespace: impl Into<String>, ext: impl Extension + 'static, ) -> Self

Loads ext under namespace, so the same extension loaded twice is two namespaces with two sets of slots and params. Panics on a namespace already taken, an empty one, or an extension whose slot names contain /.

Source

pub fn try_extension_as( self, namespace: impl Into<String>, ext: impl Extension + 'static, ) -> Result<Self, String>

Launcher::extension_as for a caller that reports the refusal rather than panicking, such as a plugin named from outside the program. The launcher is consumed either way.

Source

pub fn with_extensions(self, extensions: Extensions) -> Self

Takes an Extensions list already loaded, replacing any extension calls before it. For a host that built the list elsewhere, as the C binding does.

Source

pub fn extensions(self, exts: Vec<Box<dyn Extension>>) -> Self

Launcher::extension for each, in order.

Source

pub fn run<A: App>(self, app: A) -> Result<(), Box<dyn Error>>

Opens the main window and runs the event loop until the main window closes. Returns Ok then, or the error when the window or its renderer could not be made. One event loop per process: a process that has used Launcher::open opens again rather than calling run.

Source

pub fn open<A: App>(self, app: A) -> Result<PumpRunner<A>, Box<dyn Error>>

Opens the window but keeps the event loop in the caller’s hands: the returned PumpRunner processes OS events only when PumpRunner::pump is called, so a foreign loop (libuv, a game loop, a test harness) can interleave with winit on the main thread. winit allows one event loop per process, but any number of runners in turn: a runner whose main window has closed parks the loop, and the next open on the thread takes it back.

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<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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

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