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_close_event(&mut self) -> bool { ... }
    fn on_exit(&mut self, _gl: Option<&Context>) { ... }
    fn auto_save_interval(&self) -> Duration { ... }
    fn max_size_points(&self) -> Vec2 { ... }
    fn clear_color(&self, _visuals: &Visuals) -> [f32; 4] { ... }
    fn persist_native_window(&self) -> bool { ... }
    fn persist_egui_memory(&self) -> bool { ... }
    fn warm_up_enabled(&self) -> bool { ... }
    fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &Frame) { ... }
}
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).

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 directories_next::ProjectDirs::data_dir which is:

  • Linux: /home/UserName/.local/share/APPNAME
  • macOS: /Users/UserName/Library/Application Support/APPNAME
  • Windows: C:\Users\UserName\AppData\Roaming\APPNAME

where APPNAME is what is given to eframe::run_native.

source

fn on_close_event(&mut self) -> bool

Called when the user attempts to close the desktop window and/or quit the application.

By returning false the closing will be aborted. To continue the closing return true.

A scenario where this method will be run is after pressing the close button on a native window, which allows you to ask the user whether they want to do something before exiting. See the example at https://github.com/emilk/egui/blob/master/examples/confirm_exit/ for practical usage.

It will not be called on the web or when the window is forcefully closed.

source

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

Called once on shutdown, after Self::save.

If you need to abort an exit use Self::on_close_event.

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 max_size_points(&self) -> Vec2

The size limit of the web app canvas.

By default the max size is [egui::Vec2::INFINITY], i.e. unlimited.

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_native_window(&self) -> bool

Controls whether or not the native window position and size will be persisted (only if the “persistence” feature is enabled).

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

source

fn warm_up_enabled(&self) -> bool

If true a warm-up call to Self::update will be issued where ctx.memory(|mem| mem.everything_is_visible()) will be set to true.

This can help pre-caching resources loaded by different parts of the UI, preventing stutter later on.

In this warm-up call, all painted shapes will be ignored.

The default is false, and it is unlikely you will want to change this.

source

fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &Frame)

Called each time after the rendering the UI.

Can be used to access pixel data with get_pixels

Implementors§