1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -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

@@ -137,8 +137,8 @@ impl<'a, State> Harness<'a, State> {
// We need to run egui for a single frame so that the AccessKit state can be initialized
// and users can immediately start querying for widgets.
let mut output = ctx.run(input.clone(), |ctx| {
response = app.run(ctx, &mut state, false);
let mut output = ctx.run_ui(input.clone(), |ui| {
response = app.run(ui, &mut state, false);
});
renderer.handle_delta(&output.textures_delta);
@@ -204,7 +204,9 @@ impl<'a, State> Harness<'a, State> {
/// assert_eq!(*harness.state(), true);
/// ```
#[track_caller]
#[deprecated = "use `new_ui_state` instead"]
pub fn new_state(app: impl FnMut(&egui::Context, &mut State) + 'a, state: State) -> Self {
#[expect(deprecated)]
Self::builder().build_state(app, state)
}
@@ -287,8 +289,8 @@ impl<'a, State> Harness<'a, State> {
fn _step(&mut self, sizing_pass: bool) {
self.input.predicted_dt = self.step_dt;
let mut output = self.ctx.run(self.input.take(), |ctx| {
self.response = self.app.run(ctx, &mut self.state, sizing_pass);
let mut output = self.ctx.run_ui(self.input.take(), |ui| {
self.response = self.app.run(ui, &mut self.state, sizing_pass);
});
self.kittest.update(
output
@@ -735,7 +737,9 @@ impl<'a> Harness<'a> {
/// });
/// ```
#[track_caller]
#[deprecated = "use `new_ui` instead"]
pub fn new(app: impl FnMut(&egui::Context) + 'a) -> Self {
#[expect(deprecated)]
Self::builder().build(app)
}