Trait epi::App

source · []
pub trait App {
    fn update(&mut self, ctx: &Context, frame: &Frame);
fn name(&self) -> &str; fn setup(
        &mut self,
        _ctx: &Context,
        _frame: &Frame,
        _storage: Option<&dyn Storage>
    ) { ... }
fn save(&mut self, _storage: &mut dyn Storage) { ... }
fn on_exit_event(&mut self) -> bool { ... }
fn on_exit(&mut self) { ... }
fn auto_save_interval(&self) -> Duration { ... }
fn max_size_points(&self) -> Vec2 { ... }
fn clear_color(&self) -> Rgba { ... }
fn persist_native_window(&self) -> bool { ... }
fn persist_egui_memory(&self) -> bool { ... }
fn warm_up_enabled(&self) -> bool { ... } }
Expand description

Implement this trait to write apps that can be compiled both natively using the egui_glium crate, and deployed as a web site using the egui_web crate.

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 and Frame can be cloned and saved if you like.

To force a repaint, call either egui::Context::request_repaint during the call to update, or call Frame::request_repaint at any time (e.g. from another thread).

The name of your App, used for the title bar of native windows and the save location of persistence (see Self::save).

Provided methods

Called once before the first frame.

Allows you to do setup code, e.g to call egui::Context::set_fonts, egui::Context::set_visuals etc.

Also allows you to restore state, if there is a storage (required the “persistence” feature).

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

Only called when the “persistence” feature is enabled.

On web the states 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 returned by Self::name().

Called before an exit that can be aborted. By returning false the exit will be aborted. To continue the exit 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 eframe/examples/confirm_exit.rs for practical usage.

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

Called once on shutdown (before or after Self::save). If you need to abort an exit use Self::on_exit_event

Time between automatic calls to Self::save

The size limit of the web app canvas.

By default the size if limited to 1024x2048.

A larger canvas can lead to bad frame rates on some browsers on some platforms. In particular, Firefox on Mac and Linux is really bad at handling large WebGL canvases: https://bugzilla.mozilla.org/show_bug.cgi?id=1010527#c0 (unfixed since 2014).

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.

Implementors