Skip to content

App::tick #5113

Open
Open
@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 tick(&mut self, ctx: &egui::Context, frame: &mut Frame) {
    }

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions