Skip to main content

AppContext

Trait AppContext 

Source
pub trait AppContext {
    // Required methods
    fn central(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder));
    fn set_theme(&mut self, theme: &UiTheme);
    fn set_fonts(&mut self, pack: &FontPack);
    fn screen_size(&self) -> [f32; 2];
    fn request_repaint(&mut self);

    // Provided methods
    fn pixels_per_point(&self) -> f32 { ... }
    fn request_close(&mut self) { ... }
}
Expand description

Top-level app context — one per frame.

Required Methods§

Source

fn central(&mut self, f: &mut dyn FnMut(&mut dyn UiBuilder))

Open the central drawing region. The closure receives a &mut dyn UiBuilder and lays out the frame’s content.

Equivalent to “the whole window minus any panels installed at the backend level”. For tools without OS-level panels (the hub) this is the only call needed per frame.

Source

fn set_theme(&mut self, theme: &UiTheme)

Apply a UiTheme to the underlying backend’s visual configuration. Idempotent — call again to swap palettes at runtime.

Source

fn set_fonts(&mut self, pack: &FontPack)

Install the fonts described by pack. Called once at startup (or whenever fonts change).

Source

fn screen_size(&self) -> [f32; 2]

Logical screen size in pixels — [width, height].

Source

fn request_repaint(&mut self)

Ask the backend for another paint pass on the next available frame, even if no input event would normally trigger one. Use when an off-thread async task completes and the visible UI must update.

Provided Methods§

Source

fn pixels_per_point(&self) -> f32

Pixels-per-point ratio (DPI scale). 1.0 on standard displays, 2.0 on Retina, etc.

Source

fn request_close(&mut self)

Request the application window to close. The shutdown happens at the end of the current frame (or whenever the backend gets to it).

Implementors§