Skip to content

App::logic #5113

@emilk

Description

@emilk

Calling the full App::update when the application is hidden (background thread or minimized on native, for instance) is bad for several reasons:

A) we don't always know what the size of the viewport is/should be
B) we pay the cost of GUI even though we may only need to process some events

I think therefor it makes sense to split App::update into two functions:

trait App {
    /// You can run logic here, but can't show any GUI.
    ///
    /// Called once before each call to [`Self::show`], but may also be called
    /// without a subsequent call to `show`,
    /// for instance if the application is hidden and [`Context::request_repaint`] has been called.
    ///
    /// The egui context may ONLY be used to schedule repaints, nothing else.
    fn logic(&mut self, ctx: &egui::Context, frame: &mut Frame) {
    }

    /// Show the GUI. Each call to this is preceded by a call to [`Self::tick`].
    fn ui(&mut self, ui: &mut egui::Ui, frame: &mut Frame);
}

Ideally we should do this without too much of a breaking change though

Metadata

Metadata

Assignees

Labels

eframeRelates to epi and eframeperformanceLower CPU/GPU usage (optimize)

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions