Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App::tick #5113

Open
emilk opened this issue Sep 16, 2024 · 0 comments
Open

App::tick #5113

emilk opened this issue Sep 16, 2024 · 0 comments
Labels
eframe Relates to epi and eframe performance Lower CPU/GPU usage (optimize)

Comments

@emilk
Copy link
Owner

emilk commented Sep 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe performance Lower CPU/GPU usage (optimize)
Projects
None yet
Development

No branches or pull requests

1 participant