Trait eframe::App

source ·
pub trait App {
    // Required method
    fn update(&mut self, ctx: &Context, frame: &mut Frame);

    // Provided methods
    fn save(&mut self, _storage: &mut dyn Storage) { ... }
    fn on_exit(&mut self, _gl: Option<&Context>) { ... }
    fn auto_save_interval(&self) -> Duration { ... }
    fn clear_color(&self, _visuals: &Visuals) -> [f32; 4] { ... }
    fn persist_egui_memory(&self) -> bool { ... }
}
Expand description

Implement this trait to write apps that can be compiled for both web/wasm and desktop/native using eframe.

Required Methods§

source

fn update(&mut self, ctx: &Context, frame: &mut Frame)

Called each time the UI needs repainting, which may be many times per second.

Put your widgets into a egui::SidePanel, egui::TopBottomPanel, egui::CentralPanel, egui::Window or egui::Area.

The egui::Context can be cloned and saved if you like.

To force a repaint, call egui::Context::request_repaint at any time (e.g. from another thread).

This is called for the root viewport (egui::ViewportId::ROOT). Use egui::Context::show_viewport_deferred to spawn additional viewports (windows). (A “viewport” in egui means an native OS window).

Provided Methods§

source

fn save(&mut self, _storage: &mut dyn Storage)

Called on shutdown, and perhaps at regular intervals. Allows you to save state.

Only called when the “persistence” feature is enabled.

On web the state is stored to “Local Storage”.

On native the path is picked using crate::storage_dir.

source

fn on_exit(&mut self, _gl: Option<&Context>)

Called once on shutdown, after Self::save.

If you need to abort an exit check ctx.input(|i| i.viewport().close_requested()) and respond with egui::ViewportCommand::CancelClose.

To get a glow context you need to compile with the glow feature flag, and run eframe with the glow backend.

source

fn auto_save_interval(&self) -> Duration

Time between automatic calls to Self::save

source

fn clear_color(&self, _visuals: &Visuals) -> [f32; 4]

Background color values for the app, e.g. what is sent to gl.clearColor.

This is the background of your windows if you don’t set a central panel.

ATTENTION: Since these float values go to the render as-is, any color space conversion as done e.g. by converting from [egui::Color32] to [egui::Rgba] may cause incorrect results. egui recommends that rendering backends use a normal “gamma-space” (non-sRGB-aware) blending, which means the values you return here should also be in sRGB gamma-space in the 0-1 range. You can use [egui::Color32::to_normalized_gamma_f32] for this.

source

fn persist_egui_memory(&self) -> bool

Controls whether or not the egui memory (window positions etc) will be persisted (only if the “persistence” feature is enabled).

Implementors§