1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

eframe: Replace Frame::update with fn logic and fn ui (#7775)

* Part of https://github.com/emilk/egui/issues/5113
* Part of https://github.com/emilk/egui/issues/3524

## What
This deprecates `eframe::App::update` and replaces it with two new
functions:

```rs
pub trait App {
	/// Called just before `ui`, and in the future this will
    /// also be called for background apps when needed.
	fn logic(&mut self, ctx: &egui::Context, frame: &mut Frame) { }
	
    /// Show your user interface to the user.
	fn ui(&mut self, ui: &mut egui::Ui, frame: &mut Frame);

	…
}
```

Similarly, `Context::run` is deprecated in favor of `Context::run_ui`.

`Plugin`s are now handed a `Ui` instead of just a `Context` in
`on_begin/end_frame`.

## TODO
…either in this PR or a later one
* [x] Deprecate `App::update`
* [x] Deprecate `Context::run`
* [x] Change plugins to get a `Ui`
* [x] Update kittest
* [x] Change viewports to get UI:s (`show_viewport_immediate` etc)
  - https://github.com/emilk/egui/pull/7779

## Later PRs
* [ ] Deprecate `Panel::show`
* [ ] Deprecate `CentralPanel::show`
* [ ] Deprecate `CentralPanel` ?
This commit is contained in:
Emil Ernerfeldt
2025-12-16 17:05:50 +01:00
committed by GitHub
parent 9487dc35ec
commit 2f6fe9c572
52 changed files with 417 additions and 321 deletions

View File

@@ -2,7 +2,7 @@
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
use eframe::{CreationContext, NativeOptions, egui};
use egui::{Button, CentralPanel, Context, UserAttentionType};
use egui::{Button, CentralPanel, UserAttentionType};
use std::time::{Duration, SystemTime};
@@ -55,12 +55,12 @@ impl Application {
}
impl eframe::App for Application {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
if let Some(request_at) = self.request_at
&& request_at < SystemTime::now()
{
self.request_at = None;
ctx.send_viewport_cmd(egui::ViewportCommand::RequestUserAttention(self.attention));
ui.send_viewport_cmd(egui::ViewportCommand::RequestUserAttention(self.attention));
if self.auto_reset {
self.auto_reset = false;
self.reset_at = Some(SystemTime::now() + Self::attention_reset_timeout());
@@ -71,12 +71,12 @@ impl eframe::App for Application {
&& reset_at < SystemTime::now()
{
self.reset_at = None;
ctx.send_viewport_cmd(egui::ViewportCommand::RequestUserAttention(
ui.send_viewport_cmd(egui::ViewportCommand::RequestUserAttention(
UserAttentionType::Reset,
));
}
CentralPanel::default().show(ctx, |ui| {
CentralPanel::default().show_inside(ui, |ui| {
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label("Attention type:");
@@ -131,6 +131,6 @@ impl eframe::App for Application {
});
});
ctx.request_repaint_after(Self::repaint_max_timeout());
ui.request_repaint_after(Self::repaint_max_timeout());
}
}