1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Remove some uses of top-level panels in our examples (#7729)

We're phasing out top-level panels (panels that use `Context` directly,
instead of being inside another `Ui`).
As a first step, stop using them in our demo library and application.

* Part of https://github.com/emilk/egui/issues/3524
This commit is contained in:
Emil Ernerfeldt
2025-11-21 20:22:01 +01:00
committed by GitHub
parent d53a4a9c1d
commit d5869bfeaf
13 changed files with 165 additions and 136 deletions

View File

@@ -976,15 +976,25 @@ pub struct CentralPanel {
} }
impl CentralPanel { impl CentralPanel {
/// A central panel with no margin or background color
pub fn no_frame() -> Self {
Self {
frame: Some(Frame::NONE),
}
}
/// A central panel with a background color and some inner margins
pub fn default_margins() -> Self {
Self { frame: None }
}
/// Change the background color, margins, etc. /// Change the background color, margins, etc.
#[inline] #[inline]
pub fn frame(mut self, frame: Frame) -> Self { pub fn frame(mut self, frame: Frame) -> Self {
self.frame = Some(frame); self.frame = Some(frame);
self self
} }
}
impl CentralPanel {
/// Show the panel inside a [`Ui`]. /// Show the panel inside a [`Ui`].
pub fn show_inside<R>( pub fn show_inside<R>(
self, self,

View File

@@ -22,26 +22,27 @@ impl Custom3d {
} }
} }
impl eframe::App for Custom3d { impl crate::DemoApp for Custom3d {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { // TODO(emilk): Use `ScrollArea::inner_margin`
egui::ScrollArea::both() egui::CentralPanel::default().show_inside(ui, |ui| {
.auto_shrink(false) egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
.show(ui, |ui| { ui.horizontal(|ui| {
ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0;
ui.spacing_mut().item_spacing.x = 0.0; ui.label("The triangle is being painted using ");
ui.label("The triangle is being painted using "); ui.hyperlink_to("glow", "https://github.com/grovesNL/glow");
ui.hyperlink_to("glow", "https://github.com/grovesNL/glow"); ui.label(" (OpenGL).");
ui.label(" (OpenGL).");
});
ui.label("It's not a very impressive demo, but it shows you can embed 3D inside of egui.");
egui::Frame::canvas(ui.style()).show(ui, |ui| {
self.custom_painting(ui);
});
ui.label("Drag to rotate!");
ui.add(egui_demo_lib::egui_github_link_file!());
}); });
ui.label(
"It's not a very impressive demo, but it shows you can embed 3D inside of egui.",
);
egui::Frame::canvas(ui.style()).show(ui, |ui| {
self.custom_painting(ui);
});
ui.label("Drag to rotate!");
ui.add(egui_demo_lib::egui_github_link_file!());
});
}); });
} }

View File

@@ -98,26 +98,27 @@ impl Custom3d {
} }
} }
impl eframe::App for Custom3d { impl crate::DemoApp for Custom3d {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { // TODO(emilk): Use `ScrollArea::inner_margin`
egui::ScrollArea::both() egui::CentralPanel::default().show_inside(ui, |ui| {
.auto_shrink(false) egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
.show(ui, |ui| { ui.horizontal(|ui| {
ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 0.0;
ui.spacing_mut().item_spacing.x = 0.0; ui.label("The triangle is being painted using ");
ui.label("The triangle is being painted using "); ui.hyperlink_to("WGPU", "https://wgpu.rs");
ui.hyperlink_to("WGPU", "https://wgpu.rs"); ui.label(" (Portable Rust graphics API awesomeness)");
ui.label(" (Portable Rust graphics API awesomeness)");
});
ui.label("It's not a very impressive demo, but it shows you can embed 3D inside of egui.");
egui::Frame::canvas(ui.style()).show(ui, |ui| {
self.custom_painting(ui);
});
ui.label("Drag to rotate!");
ui.add(egui_demo_lib::egui_github_link_file!());
}); });
ui.label(
"It's not a very impressive demo, but it shows you can embed 3D inside of egui.",
);
egui::Frame::canvas(ui.style()).show(ui, |ui| {
self.custom_painting(ui);
});
ui.label("Drag to rotate!");
ui.add(egui_demo_lib::egui_github_link_file!());
});
}); });
} }
} }

View File

@@ -59,16 +59,16 @@ impl Default for HttpApp {
} }
} }
impl eframe::App for HttpApp { impl crate::DemoApp for HttpApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
egui::Panel::bottom("http_bottom").show(ctx, |ui| { egui::Panel::bottom("http_bottom").show_inside(ui, |ui| {
let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true); let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true);
ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| { ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| {
ui.add(egui_demo_lib::egui_github_link_file!()) ui.add(egui_demo_lib::egui_github_link_file!())
}) })
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show_inside(ui, |ui| {
let prev_url = self.url.clone(); let prev_url = self.url.clone();
let trigger_fetch = ui_url(ui, frame, &mut self.url); let trigger_fetch = ui_url(ui, frame, &mut self.url);
@@ -80,7 +80,7 @@ impl eframe::App for HttpApp {
}); });
if trigger_fetch { if trigger_fetch {
let ctx = ctx.clone(); let ctx = ui.ctx().clone();
let (sender, promise) = Promise::new(); let (sender, promise) = Promise::new();
let request = ehttp::Request::get(&self.url); let request = ehttp::Request::get(&self.url);
ehttp::fetch(request, move |response| { ehttp::fetch(request, move |response| {

View File

@@ -48,15 +48,15 @@ impl Default for ImageViewer {
} }
} }
impl eframe::App for ImageViewer { impl crate::DemoApp for ImageViewer {
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame) {
egui::Panel::top("url bar").show(ctx, |ui| { egui::Panel::top("url bar").show_inside(ui, |ui| {
ui.horizontal_centered(|ui| { ui.horizontal_centered(|ui| {
let label = ui.label("URI:"); let label = ui.label("URI:");
ui.text_edit_singleline(&mut self.uri_edit_text) ui.text_edit_singleline(&mut self.uri_edit_text)
.labelled_by(label.id); .labelled_by(label.id);
if ui.small_button("").clicked() { if ui.small_button("").clicked() {
ctx.forget_image(&self.current_uri); ui.ctx().forget_image(&self.current_uri);
self.uri_edit_text = self.uri_edit_text.trim().to_owned(); self.uri_edit_text = self.uri_edit_text.trim().to_owned();
self.current_uri = self.uri_edit_text.clone(); self.current_uri = self.uri_edit_text.clone();
} }
@@ -71,7 +71,7 @@ impl eframe::App for ImageViewer {
}); });
}); });
egui::Panel::left("controls").show(ctx, |ui| { egui::Panel::left("controls").show_inside(ui, |ui| {
// uv // uv
ui.label("UV"); ui.label("UV");
ui.add(Slider::new(&mut self.image_options.uv.min.x, 0.0..=1.0).text("min x")); ui.add(Slider::new(&mut self.image_options.uv.min.x, 0.0..=1.0).text("min x"));
@@ -197,7 +197,7 @@ impl eframe::App for ImageViewer {
} }
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show_inside(ui, |ui| {
egui::ScrollArea::both().show(ui, |ui| { egui::ScrollArea::both().show(ui, |ui| {
let mut image = egui::Image::from_uri(&self.current_uri); let mut image = egui::Image::from_uri(&self.current_uri);
image = image.uv(self.image_options.uv); image = image.uv(self.image_options.uv);

View File

@@ -15,6 +15,14 @@ pub(crate) fn seconds_since_midnight() -> f64 {
time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64) time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64)
} }
/// Trait that wraps different parts of the demo app.
pub trait DemoApp {
fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame);
#[cfg(feature = "glow")]
fn on_exit(&mut self, _gl: Option<&eframe::glow::Context>) {}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#[cfg(feature = "accessibility_inspector")] #[cfg(feature = "accessibility_inspector")]
pub mod accessibility_inspector; pub mod accessibility_inspector;

View File

@@ -1,4 +1,4 @@
use egui_demo_lib::is_mobile; use egui_demo_lib::{DemoWindows, is_mobile};
#[cfg(feature = "glow")] #[cfg(feature = "glow")]
use eframe::glow; use eframe::glow;
@@ -6,29 +6,25 @@ use eframe::glow;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use core::any::Any; use core::any::Any;
use crate::DemoApp;
#[derive(Default)] #[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
struct EasyMarkApp { struct EasyMarkApp {
editor: egui_demo_lib::easy_mark::EasyMarkEditor, editor: egui_demo_lib::easy_mark::EasyMarkEditor,
} }
impl eframe::App for EasyMarkApp { impl DemoApp for EasyMarkApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
self.editor.panels(ctx); self.editor.panels(ui);
} }
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#[derive(Default)] impl DemoApp for DemoWindows {
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
pub struct DemoApp { self.ui(ui);
demo_windows: egui_demo_lib::DemoWindows,
}
impl eframe::App for DemoApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.demo_windows.ui(ctx);
} }
} }
@@ -41,15 +37,12 @@ pub struct FractalClockApp {
pub mock_time: Option<f64>, pub mock_time: Option<f64>,
} }
impl eframe::App for FractalClockApp { impl DemoApp for FractalClockApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
egui::CentralPanel::default() egui::Frame::dark_canvas(ui.style())
.frame( .stroke(egui::Stroke::NONE)
egui::Frame::dark_canvas(&ctx.style()) .corner_radius(0)
.stroke(egui::Stroke::NONE) .show(ui, |ui| {
.corner_radius(0),
)
.show(ctx, |ui| {
self.fractal_clock self.fractal_clock
.ui(ui, self.mock_time.or(Some(crate::seconds_since_midnight()))); .ui(ui, self.mock_time.or(Some(crate::seconds_since_midnight())));
}); });
@@ -64,13 +57,13 @@ pub struct ColorTestApp {
color_test: egui_demo_lib::ColorTest, color_test: egui_demo_lib::ColorTest,
} }
impl eframe::App for ColorTestApp { impl DemoApp for ColorTestApp {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show_inside(ui, |ui| {
if frame.is_web() { if frame.is_web() {
ui.label( ui.label(
"NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.", "NOTE: Some old browsers stuck on WebGL1 without sRGB support will not pass the color test.",
); );
ui.separator(); ui.separator();
} }
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| { egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
@@ -155,7 +148,7 @@ enum Command {
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))] #[cfg_attr(feature = "serde", serde(default))]
pub struct State { pub struct State {
demo: DemoApp, demo: DemoWindows,
easy_mark_editor: EasyMarkApp, easy_mark_editor: EasyMarkApp,
#[cfg(feature = "http")] #[cfg(feature = "http")]
http: crate::apps::HttpApp, http: crate::apps::HttpApp,
@@ -209,34 +202,34 @@ impl WrapApp {
pub fn apps_iter_mut( pub fn apps_iter_mut(
&mut self, &mut self,
) -> impl Iterator<Item = (&'static str, Anchor, &mut dyn eframe::App)> { ) -> impl Iterator<Item = (&'static str, Anchor, &mut dyn DemoApp)> {
let mut vec = vec![ let mut vec = vec![
( (
"✨ Demos", "✨ Demos",
Anchor::Demo, Anchor::Demo,
&mut self.state.demo as &mut dyn eframe::App, &mut self.state.demo as &mut dyn DemoApp,
), ),
( (
"🖹 EasyMark editor", "🖹 EasyMark editor",
Anchor::EasyMarkEditor, Anchor::EasyMarkEditor,
&mut self.state.easy_mark_editor as &mut dyn eframe::App, &mut self.state.easy_mark_editor as &mut dyn DemoApp,
), ),
#[cfg(feature = "http")] #[cfg(feature = "http")]
( (
"⬇ HTTP", "⬇ HTTP",
Anchor::Http, Anchor::Http,
&mut self.state.http as &mut dyn eframe::App, &mut self.state.http as &mut dyn DemoApp,
), ),
( (
"🕑 Fractal Clock", "🕑 Fractal Clock",
Anchor::Clock, Anchor::Clock,
&mut self.state.clock as &mut dyn eframe::App, &mut self.state.clock as &mut dyn DemoApp,
), ),
#[cfg(feature = "image_viewer")] #[cfg(feature = "image_viewer")]
( (
"🖼 Image Viewer", "🖼 Image Viewer",
Anchor::ImageViewer, Anchor::ImageViewer,
&mut self.state.image_viewer as &mut dyn eframe::App, &mut self.state.image_viewer as &mut dyn DemoApp,
), ),
]; ];
@@ -245,14 +238,14 @@ impl WrapApp {
vec.push(( vec.push((
"🔺 3D painting", "🔺 3D painting",
Anchor::Custom3d, Anchor::Custom3d,
custom3d as &mut dyn eframe::App, custom3d as &mut dyn DemoApp,
)); ));
} }
vec.push(( vec.push((
"🎨 Rendering test", "🎨 Rendering test",
Anchor::Rendering, Anchor::Rendering,
&mut self.state.rendering_test as &mut dyn eframe::App, &mut self.state.rendering_test as &mut dyn DemoApp,
)); ));
vec.into_iter() vec.into_iter()
@@ -306,11 +299,13 @@ impl eframe::App for WrapApp {
self.state.backend_panel.update(ctx, frame); self.state.backend_panel.update(ctx, frame);
if !is_mobile(ctx) { egui::CentralPanel::no_frame().show(ctx, |ui| {
cmd = self.backend_panel(ctx, frame); if !is_mobile(ctx) {
} cmd = self.backend_panel(ui, frame);
}
self.show_selected_app(ctx, frame); self.show_selected_app(ui, frame);
});
self.state.backend_panel.end_of_frame(ctx); self.state.backend_panel.end_of_frame(ctx);
@@ -333,17 +328,16 @@ impl eframe::App for WrapApp {
} }
impl WrapApp { impl WrapApp {
fn backend_panel(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) -> Command { fn backend_panel(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) -> Command {
// The backend-panel can be toggled on/off. // The backend-panel can be toggled on/off.
// We show a little animation when the user switches it. // We show a little animation when the user switches it.
let is_open = let is_open = self.state.backend_panel.open || ui.memory(|mem| mem.everything_is_visible());
self.state.backend_panel.open || ctx.memory(|mem| mem.everything_is_visible());
let mut cmd = Command::Nothing; let mut cmd = Command::Nothing;
egui::Panel::left("backend_panel") egui::Panel::left("backend_panel")
.resizable(false) .resizable(false)
.show_animated(ctx, is_open, |ui| { .show_animated_inside(ui, is_open, |ui| {
ui.add_space(4.0); ui.add_space(4.0);
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.heading("💻 Backend"); ui.heading("💻 Backend");
@@ -393,11 +387,11 @@ impl WrapApp {
}); });
} }
fn show_selected_app(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { fn show_selected_app(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
let selected_anchor = self.state.selected_anchor; let selected_anchor = self.state.selected_anchor;
for (_name, anchor, app) in self.apps_iter_mut() { for (_name, anchor, app) in self.apps_iter_mut() {
if anchor == selected_anchor || ctx.memory(|mem| mem.everything_is_visible()) { if anchor == selected_anchor || ui.memory(|mem| mem.everything_is_visible()) {
app.update(ctx, frame); app.demo_ui(ui, frame);
} }
} }
} }

View File

@@ -29,7 +29,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_with_tessellate__realistic", |b| { c.bench_function("demo_with_tessellate__realistic", |b| {
b.iter(|| { b.iter(|| {
let full_output = ctx.run(RawInput::default(), |ctx| { let full_output = ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}); });
ctx.tessellate(full_output.shapes, full_output.pixels_per_point) ctx.tessellate(full_output.shapes, full_output.pixels_per_point)
}); });
@@ -38,13 +40,17 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_no_tessellate", |b| { c.bench_function("demo_no_tessellate", |b| {
b.iter(|| { b.iter(|| {
ctx.run(RawInput::default(), |ctx| { ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}) })
}); });
}); });
let full_output = ctx.run(RawInput::default(), |ctx| { let full_output = ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}); });
c.bench_function("demo_only_tessellate", |b| { c.bench_function("demo_only_tessellate", |b| {
b.iter(|| ctx.tessellate(full_output.shapes.clone(), full_output.pixels_per_point)); b.iter(|| ctx.tessellate(full_output.shapes.clone(), full_output.pixels_per_point));
@@ -58,7 +64,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_full_no_tessellate", |b| { c.bench_function("demo_full_no_tessellate", |b| {
b.iter(|| { b.iter(|| {
ctx.run(RawInput::default(), |ctx| { ctx.run(RawInput::default(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}) })
}); });
}); });

View File

@@ -195,11 +195,11 @@ impl Default for DemoWindows {
impl DemoWindows { impl DemoWindows {
/// Show the app ui (menu bar and windows). /// Show the app ui (menu bar and windows).
pub fn ui(&mut self, ctx: &Context) { pub fn ui(&mut self, ui: &mut egui::Ui) {
if is_mobile(ctx) { if is_mobile(ui.ctx()) {
self.mobile_ui(ctx); self.mobile_ui(ui);
} else { } else {
self.desktop_ui(ctx); self.desktop_ui(ui);
} }
} }
@@ -207,36 +207,36 @@ impl DemoWindows {
self.open.contains(About::default().name()) self.open.contains(About::default().name())
} }
fn mobile_ui(&mut self, ctx: &Context) { fn mobile_ui(&mut self, ui: &mut egui::Ui) {
if self.about_is_open() { if self.about_is_open() {
let mut close = false; let mut close = false;
egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
.auto_shrink(false) .auto_shrink(false)
.show(ui, |ui| { .show(ui, |ui| {
self.groups.about.ui(ui); self.groups.about.ui(ui);
ui.add_space(12.0); ui.add_space(12.0);
ui.vertical_centered_justified(|ui| { ui.vertical_centered_justified(|ui| {
if ui if ui
.button(egui::RichText::new("Continue to the demo!").size(20.0)) .button(egui::RichText::new("Continue to the demo!").size(20.0))
.clicked() .clicked()
{ {
close = true; close = true;
} }
});
}); });
}); });
if close { if close {
set_open(&mut self.open, About::default().name(), false); set_open(&mut self.open, About::default().name(), false);
} }
} else { } else {
self.mobile_top_bar(ctx); self.mobile_top_bar(ui);
self.groups.windows(ctx, &mut self.open); self.groups.windows(ui.ctx(), &mut self.open);
} }
} }
fn mobile_top_bar(&mut self, ctx: &Context) { fn mobile_top_bar(&mut self, ui: &mut egui::Ui) {
egui::Panel::top("menu_bar").show(ctx, |ui| { egui::Panel::top("menu_bar").show_inside(ui, |ui| {
menu::MenuBar::new() menu::MenuBar::new()
.config(menu::MenuConfig::new().style(StyleModifier::default())) .config(menu::MenuConfig::new().style(StyleModifier::default()))
.ui(ui, |ui| { .ui(ui, |ui| {
@@ -261,12 +261,12 @@ impl DemoWindows {
}); });
} }
fn desktop_ui(&mut self, ctx: &Context) { fn desktop_ui(&mut self, ui: &mut egui::Ui) {
egui::Panel::right("egui_demo_panel") egui::Panel::right("egui_demo_panel")
.resizable(false) .resizable(false)
.default_size(160.0) .default_size(160.0)
.min_size(160.0) .min_size(160.0)
.show(ctx, |ui| { .show_inside(ui, |ui| {
ui.add_space(4.0); ui.add_space(4.0);
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.heading("✒ egui demos"); ui.heading("✒ egui demos");
@@ -289,13 +289,13 @@ impl DemoWindows {
self.demo_list_ui(ui); self.demo_list_ui(ui);
}); });
egui::Panel::top("menu_bar").show(ctx, |ui| { egui::Panel::top("menu_bar").show_inside(ui, |ui| {
menu::MenuBar::new().ui(ui, |ui| { menu::MenuBar::new().ui(ui, |ui| {
file_menu_button(ui); file_menu_button(ui);
}); });
}); });
self.groups.windows(ctx, &mut self.open); self.groups.windows(ui.ctx(), &mut self.open);
} }
fn demo_list_ui(&mut self, ui: &mut egui::Ui) { fn demo_list_ui(&mut self, ui: &mut egui::Ui) {

View File

@@ -72,6 +72,7 @@ impl crate::View for Panels {
}); });
}); });
// TODO(emilk): This extra panel is superfluous - just use what's left of `ui` instead
egui::CentralPanel::default().show_inside(ui, |ui| { egui::CentralPanel::default().show_inside(ui, |ui| {
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
ui.heading("Central Panel"); ui.heading("Central Panel");

View File

@@ -32,15 +32,15 @@ impl Default for EasyMarkEditor {
} }
impl EasyMarkEditor { impl EasyMarkEditor {
pub fn panels(&mut self, ctx: &egui::Context) { pub fn panels(&mut self, ui: &mut egui::Ui) {
egui::Panel::bottom("easy_mark_bottom").show(ctx, |ui| { egui::Panel::bottom("easy_mark_bottom").show_inside(ui, |ui| {
let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true); let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true);
ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| { ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| {
ui.add(crate::egui_github_link_file!()) ui.add(crate::egui_github_link_file!())
}) })
}); });
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show_inside(ui, |ui| {
self.ui(ui); self.ui(ui);
}); });
} }

View File

@@ -74,7 +74,9 @@ fn test_egui_e2e() {
const NUM_FRAMES: usize = 5; const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES { for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| { let full_output = ctx.run(raw_input.clone(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}); });
let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point); let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
assert!(!clipped_primitives.is_empty()); assert!(!clipped_primitives.is_empty());
@@ -93,7 +95,9 @@ fn test_egui_zero_window_size() {
const NUM_FRAMES: usize = 5; const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES { for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| { let full_output = ctx.run(raw_input.clone(), |ctx| {
demo_windows.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
demo_windows.ui(ui);
});
}); });
let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point); let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
assert!( assert!(

View File

@@ -45,6 +45,8 @@ impl eframe::App for MyApp {
ui.set_height(32.0); ui.set_height(32.0);
}); });
self.demo.ui(ctx); egui::CentralPanel::default().show(ctx, |ui| {
self.demo.ui(ui);
});
} }
} }