mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -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:
@@ -5,11 +5,11 @@ use accesskit_consumer::{FilterResult, Node, Tree, TreeChangeHandler};
|
||||
|
||||
use eframe::epaint::text::TextWrapMode;
|
||||
use egui::{
|
||||
Button, Color32, Context, Event, Frame, FullOutput, Id, Key, KeyboardShortcut, Label,
|
||||
Modifiers, Panel, RawInput, RichText, ScrollArea, Ui, collapsing_header::CollapsingState,
|
||||
Button, Color32, Event, Frame, FullOutput, Id, Key, KeyboardShortcut, Label, Modifiers, Panel,
|
||||
RawInput, RichText, ScrollArea, Ui, collapsing_header::CollapsingState,
|
||||
};
|
||||
|
||||
/// This [`egui::Plugin`] adds an inspector Panel.
|
||||
/// This [`egui::Plugin`] adds an inspector panel.
|
||||
///
|
||||
/// It can be opened with the `(Cmd/Ctrl)+Alt+I`. It shows the current AccessKit tree and details
|
||||
/// for the selected node.
|
||||
@@ -71,8 +71,8 @@ impl egui::Plugin for AccessibilityInspectorPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn on_begin_pass(&mut self, ctx: &Context) {
|
||||
if ctx.input_mut(|i| {
|
||||
fn on_begin_pass(&mut self, ui: &mut Ui) {
|
||||
if ui.input_mut(|i| {
|
||||
i.consume_shortcut(&KeyboardShortcut::new(
|
||||
Modifiers::COMMAND | Modifiers::ALT,
|
||||
Key::I,
|
||||
@@ -85,9 +85,9 @@ impl egui::Plugin for AccessibilityInspectorPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.enable_accesskit();
|
||||
ui.enable_accesskit();
|
||||
|
||||
Panel::right(Self::id()).show(ctx, |ui| {
|
||||
Panel::right(Self::id()).show_inside(ui, |ui| {
|
||||
ui.heading("🔎 AccessKit Inspector");
|
||||
if let Some(selected_node) = self.selected_node {
|
||||
Panel::bottom(Self::id().with("details_panel"))
|
||||
|
||||
@@ -271,7 +271,7 @@ impl eframe::App for WrapApp {
|
||||
color.to_normalized_gamma_f32()
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if let Some(anchor) = frame
|
||||
.info()
|
||||
@@ -285,36 +285,36 @@ impl eframe::App for WrapApp {
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
if ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::F11)) {
|
||||
let fullscreen = ctx.input(|i| i.viewport().fullscreen.unwrap_or(false));
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Fullscreen(!fullscreen));
|
||||
if ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::F11)) {
|
||||
let fullscreen = ui.input(|i| i.viewport().fullscreen.unwrap_or(false));
|
||||
ui.send_viewport_cmd(egui::ViewportCommand::Fullscreen(!fullscreen));
|
||||
}
|
||||
|
||||
let mut cmd = Command::Nothing;
|
||||
egui::Panel::top("wrap_app_top_bar")
|
||||
.frame(egui::Frame::new().inner_margin(4))
|
||||
.show(ctx, |ui| {
|
||||
.show_inside(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.visuals_mut().button_frame = false;
|
||||
self.bar_contents(ui, frame, &mut cmd);
|
||||
});
|
||||
});
|
||||
|
||||
self.state.backend_panel.update(ctx, frame);
|
||||
self.state.backend_panel.update(ui.ctx(), frame);
|
||||
|
||||
egui::CentralPanel::no_frame().show(ctx, |ui| {
|
||||
if !is_mobile(ctx) {
|
||||
egui::CentralPanel::no_frame().show_inside(ui, |ui| {
|
||||
if !is_mobile(ui.ctx()) {
|
||||
cmd = self.backend_panel(ui, frame);
|
||||
}
|
||||
|
||||
self.show_selected_app(ui, frame);
|
||||
});
|
||||
|
||||
self.state.backend_panel.end_of_frame(ctx);
|
||||
self.state.backend_panel.end_of_frame(ui.ctx());
|
||||
|
||||
self.ui_file_drag_and_drop(ctx);
|
||||
self.ui_file_drag_and_drop(ui.ctx());
|
||||
|
||||
self.run_cmd(ctx, cmd);
|
||||
self.run_cmd(ui.ctx(), cmd);
|
||||
}
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
|
||||
Reference in New Issue
Block a user