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:
@@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
struct MyTestApp {}
|
||||
|
||||
impl eframe::App for MyTestApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
use glow::HasContext as _;
|
||||
let gl = frame.gl().unwrap();
|
||||
|
||||
@@ -37,7 +37,7 @@ impl eframe::App for MyTestApp {
|
||||
gl.clear(glow::COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
egui::Window::new("Floating Window").show(ctx, |ui| {
|
||||
egui::Window::new("Floating Window").show(ui.ctx(), |ui| {
|
||||
ui.label("The background should be purple.");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ fn main() -> eframe::Result {
|
||||
env_logger::init(); // Use `RUST_LOG=debug` to see logs.
|
||||
|
||||
let options = eframe::NativeOptions::default();
|
||||
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
|
||||
eframe::run_ui_native("My egui App", options, move |ui, _frame| {
|
||||
// A bottom panel to force the tooltips to consider if the fit below or under the widget:
|
||||
egui::Panel::bottom("bottom").show(ctx, |ui| {
|
||||
egui::Panel::bottom("bottom").show_inside(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.label("Single tooltips:");
|
||||
@@ -33,10 +33,10 @@ fn main() -> eframe::Result {
|
||||
});
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Reset egui memory").clicked() {
|
||||
ctx.memory_mut(|mem| *mem = Default::default());
|
||||
ui.memory_mut(|mem| *mem = Default::default());
|
||||
}
|
||||
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::BOTTOM), |ui| {
|
||||
|
||||
@@ -31,10 +31,10 @@ struct MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
ctx.all_styles_mut(|style| style.interaction.tooltip_delay = 0.0);
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
ui.all_styles_mut(|style| style.interaction.tooltip_delay = 0.0);
|
||||
|
||||
egui::Panel::left("side_panel_left").show(ctx, |ui| {
|
||||
egui::Panel::left("side_panel_left").show_inside(ui, |ui| {
|
||||
ui.heading("Information");
|
||||
ui.label(
|
||||
"This is a demo/test environment of the `UiStack` feature. The tables display \
|
||||
@@ -49,7 +49,7 @@ impl eframe::App for MyApp {
|
||||
ui.checkbox(&mut self.show_memory, "📝 Memory");
|
||||
ui.add_space(10.0);
|
||||
if ui.button("Reset egui memory").clicked() {
|
||||
ctx.memory_mut(|mem| *mem = Default::default());
|
||||
ui.memory_mut(|mem| *mem = Default::default());
|
||||
}
|
||||
ui.add_space(20.0);
|
||||
|
||||
@@ -82,7 +82,7 @@ impl eframe::App for MyApp {
|
||||
});
|
||||
});
|
||||
|
||||
egui::Panel::right("side_panel_right").show(ctx, |ui| {
|
||||
egui::Panel::right("side_panel_right").show_inside(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
stack_ui(ui);
|
||||
|
||||
@@ -92,7 +92,7 @@ impl eframe::App for MyApp {
|
||||
});
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
ui.label("stack here:");
|
||||
stack_ui(ui);
|
||||
@@ -172,7 +172,7 @@ impl eframe::App for MyApp {
|
||||
|
||||
egui::Panel::bottom("bottom_panel")
|
||||
.resizable(true)
|
||||
.show(ctx, |ui| {
|
||||
.show_inside(ui, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink(false)
|
||||
.show(ui, |ui| {
|
||||
@@ -186,30 +186,31 @@ impl eframe::App for MyApp {
|
||||
|
||||
egui::Window::new("Window")
|
||||
.pivot(egui::Align2::RIGHT_TOP)
|
||||
.show(ctx, |ui| {
|
||||
.show(ui.ctx(), |ui| {
|
||||
full_span_widget(ui, false);
|
||||
ui.add_space(20.0);
|
||||
stack_ui(ui);
|
||||
});
|
||||
|
||||
let ctx = ui.ctx().clone();
|
||||
egui::Window::new("🔧 Settings")
|
||||
.open(&mut self.show_settings)
|
||||
.vscroll(true)
|
||||
.show(ctx, |ui| {
|
||||
.show(&ctx, |ui| {
|
||||
ctx.settings_ui(ui);
|
||||
});
|
||||
|
||||
egui::Window::new("🔍 Inspection")
|
||||
.open(&mut self.show_inspection)
|
||||
.vscroll(true)
|
||||
.show(ctx, |ui| {
|
||||
.show(&ctx, |ui| {
|
||||
ctx.inspection_ui(ui);
|
||||
});
|
||||
|
||||
egui::Window::new("📝 Memory")
|
||||
.open(&mut self.show_memory)
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
.show(&ctx, |ui| {
|
||||
ctx.memory_ui(ui);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -153,18 +153,18 @@ impl Default for App {
|
||||
}
|
||||
|
||||
impl eframe::App for App {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
ui.heading("Root viewport");
|
||||
{
|
||||
let mut embed_viewports = ctx.embed_viewports();
|
||||
let mut embed_viewports = ui.embed_viewports();
|
||||
ui.checkbox(&mut embed_viewports, "Embed all viewports");
|
||||
if ui.button("Open all viewports").clicked() {
|
||||
for viewport in &self.top {
|
||||
viewport.write().set_visible_recursive(true);
|
||||
}
|
||||
}
|
||||
ctx.set_embed_viewports(embed_viewports);
|
||||
ui.set_embed_viewports(embed_viewports);
|
||||
}
|
||||
ui.checkbox(&mut self.close_button, "with close button");
|
||||
generic_ui(ui, &self.top, self.close_button);
|
||||
|
||||
Reference in New Issue
Block a user