Trait eframe::App

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

    fn as_any_mut(&mut self) -> Option<&mut dyn Any> { ... }
    fn save(&mut self, _storage: &mut dyn Storage) { ... }
    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) -> Rgba { ... }
    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§

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§

Get a handle to the app.

Can be used from web to interact or other external context.

You need to implement this if you want to be able to access the application from JS using crate::web::backend::AppRunner.

This is needed because downcasting Box<dyn App> -> Box<dyn Any> to get &ConcreteApp is not simple in current rust.

Just copy-paste this as your implementation:

#[cfg(target_arch = "wasm32")]
fn as_any_mut(&mut self) -> Option<&mut dyn std::any::Any> {
    Some(&mut *self)
}

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.

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.

Time between automatic calls to Self::save

The size limit of the web app canvas.

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

A large canvas can lead to bad frame rates on some older browsers on some platforms (see https://bugzilla.mozilla.org/show_bug.cgi?id=1010527#c0).

Background color 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.

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

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

If true a warm-up call to Self::update will be issued where ctx.memory().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.

Called each time after the rendering the UI.

Can be used to access pixel data with get_pixels

Implementors§