mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -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:
@@ -976,15 +976,25 @@ pub struct 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.
|
||||
#[inline]
|
||||
pub fn frame(mut self, frame: Frame) -> Self {
|
||||
self.frame = Some(frame);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl CentralPanel {
|
||||
/// Show the panel inside a [`Ui`].
|
||||
pub fn show_inside<R>(
|
||||
self,
|
||||
|
||||
@@ -22,26 +22,27 @@ impl Custom3d {
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for Custom3d {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::both()
|
||||
.auto_shrink(false)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("The triangle is being painted using ");
|
||||
ui.hyperlink_to("glow", "https://github.com/grovesNL/glow");
|
||||
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!());
|
||||
impl crate::DemoApp for Custom3d {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
// TODO(emilk): Use `ScrollArea::inner_margin`
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("The triangle is being painted using ");
|
||||
ui.hyperlink_to("glow", "https://github.com/grovesNL/glow");
|
||||
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!());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -98,26 +98,27 @@ impl Custom3d {
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for Custom3d {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::both()
|
||||
.auto_shrink(false)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("The triangle is being painted using ");
|
||||
ui.hyperlink_to("WGPU", "https://wgpu.rs");
|
||||
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!());
|
||||
impl crate::DemoApp for Custom3d {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
// TODO(emilk): Use `ScrollArea::inner_margin`
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
egui::ScrollArea::both().auto_shrink(false).show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("The triangle is being painted using ");
|
||||
ui.hyperlink_to("WGPU", "https://wgpu.rs");
|
||||
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!());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,16 +59,16 @@ impl Default for HttpApp {
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for HttpApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::Panel::bottom("http_bottom").show(ctx, |ui| {
|
||||
impl crate::DemoApp for HttpApp {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
egui::Panel::bottom("http_bottom").show_inside(ui, |ui| {
|
||||
let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true);
|
||||
ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| {
|
||||
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 trigger_fetch = ui_url(ui, frame, &mut self.url);
|
||||
|
||||
@@ -80,7 +80,7 @@ impl eframe::App for HttpApp {
|
||||
});
|
||||
|
||||
if trigger_fetch {
|
||||
let ctx = ctx.clone();
|
||||
let ctx = ui.ctx().clone();
|
||||
let (sender, promise) = Promise::new();
|
||||
let request = ehttp::Request::get(&self.url);
|
||||
ehttp::fetch(request, move |response| {
|
||||
|
||||
@@ -48,15 +48,15 @@ impl Default for ImageViewer {
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for ImageViewer {
|
||||
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
|
||||
egui::Panel::top("url bar").show(ctx, |ui| {
|
||||
impl crate::DemoApp for ImageViewer {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _: &mut eframe::Frame) {
|
||||
egui::Panel::top("url bar").show_inside(ui, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
let label = ui.label("URI:");
|
||||
ui.text_edit_singleline(&mut self.uri_edit_text)
|
||||
.labelled_by(label.id);
|
||||
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.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
|
||||
ui.label("UV");
|
||||
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| {
|
||||
let mut image = egui::Image::from_uri(&self.current_uri);
|
||||
image = image.uv(self.image_options.uv);
|
||||
|
||||
@@ -15,6 +15,14 @@ pub(crate) fn seconds_since_midnight() -> 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")]
|
||||
pub mod accessibility_inspector;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use egui_demo_lib::is_mobile;
|
||||
use egui_demo_lib::{DemoWindows, is_mobile};
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
use eframe::glow;
|
||||
@@ -6,29 +6,25 @@ use eframe::glow;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use core::any::Any;
|
||||
|
||||
use crate::DemoApp;
|
||||
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
struct EasyMarkApp {
|
||||
editor: egui_demo_lib::easy_mark::EasyMarkEditor,
|
||||
}
|
||||
|
||||
impl eframe::App for EasyMarkApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.editor.panels(ctx);
|
||||
impl DemoApp for EasyMarkApp {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
self.editor.panels(ui);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct DemoApp {
|
||||
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);
|
||||
impl DemoApp for DemoWindows {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
self.ui(ui);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,15 +37,12 @@ pub struct FractalClockApp {
|
||||
pub mock_time: Option<f64>,
|
||||
}
|
||||
|
||||
impl eframe::App for FractalClockApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default()
|
||||
.frame(
|
||||
egui::Frame::dark_canvas(&ctx.style())
|
||||
.stroke(egui::Stroke::NONE)
|
||||
.corner_radius(0),
|
||||
)
|
||||
.show(ctx, |ui| {
|
||||
impl DemoApp for FractalClockApp {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||
egui::Frame::dark_canvas(ui.style())
|
||||
.stroke(egui::Stroke::NONE)
|
||||
.corner_radius(0)
|
||||
.show(ui, |ui| {
|
||||
self.fractal_clock
|
||||
.ui(ui, self.mock_time.or(Some(crate::seconds_since_midnight())));
|
||||
});
|
||||
@@ -64,13 +57,13 @@ pub struct ColorTestApp {
|
||||
color_test: egui_demo_lib::ColorTest,
|
||||
}
|
||||
|
||||
impl eframe::App for ColorTestApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
impl DemoApp for ColorTestApp {
|
||||
fn demo_ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
if frame.is_web() {
|
||||
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();
|
||||
}
|
||||
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", serde(default))]
|
||||
pub struct State {
|
||||
demo: DemoApp,
|
||||
demo: DemoWindows,
|
||||
easy_mark_editor: EasyMarkApp,
|
||||
#[cfg(feature = "http")]
|
||||
http: crate::apps::HttpApp,
|
||||
@@ -209,34 +202,34 @@ impl WrapApp {
|
||||
|
||||
pub fn apps_iter_mut(
|
||||
&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![
|
||||
(
|
||||
"✨ Demos",
|
||||
Anchor::Demo,
|
||||
&mut self.state.demo as &mut dyn eframe::App,
|
||||
&mut self.state.demo as &mut dyn DemoApp,
|
||||
),
|
||||
(
|
||||
"🖹 EasyMark editor",
|
||||
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")]
|
||||
(
|
||||
"⬇ HTTP",
|
||||
Anchor::Http,
|
||||
&mut self.state.http as &mut dyn eframe::App,
|
||||
&mut self.state.http as &mut dyn DemoApp,
|
||||
),
|
||||
(
|
||||
"🕑 Fractal Clock",
|
||||
Anchor::Clock,
|
||||
&mut self.state.clock as &mut dyn eframe::App,
|
||||
&mut self.state.clock as &mut dyn DemoApp,
|
||||
),
|
||||
#[cfg(feature = "image_viewer")]
|
||||
(
|
||||
"🖼 Image Viewer",
|
||||
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((
|
||||
"🔺 3D painting",
|
||||
Anchor::Custom3d,
|
||||
custom3d as &mut dyn eframe::App,
|
||||
custom3d as &mut dyn DemoApp,
|
||||
));
|
||||
}
|
||||
|
||||
vec.push((
|
||||
"🎨 Rendering test",
|
||||
Anchor::Rendering,
|
||||
&mut self.state.rendering_test as &mut dyn eframe::App,
|
||||
&mut self.state.rendering_test as &mut dyn DemoApp,
|
||||
));
|
||||
|
||||
vec.into_iter()
|
||||
@@ -306,11 +299,13 @@ impl eframe::App for WrapApp {
|
||||
|
||||
self.state.backend_panel.update(ctx, frame);
|
||||
|
||||
if !is_mobile(ctx) {
|
||||
cmd = self.backend_panel(ctx, frame);
|
||||
}
|
||||
egui::CentralPanel::no_frame().show(ctx, |ui| {
|
||||
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);
|
||||
|
||||
@@ -333,17 +328,16 @@ impl eframe::App for 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.
|
||||
// We show a little animation when the user switches it.
|
||||
let is_open =
|
||||
self.state.backend_panel.open || ctx.memory(|mem| mem.everything_is_visible());
|
||||
let is_open = self.state.backend_panel.open || ui.memory(|mem| mem.everything_is_visible());
|
||||
|
||||
let mut cmd = Command::Nothing;
|
||||
|
||||
egui::Panel::left("backend_panel")
|
||||
.resizable(false)
|
||||
.show_animated(ctx, is_open, |ui| {
|
||||
.show_animated_inside(ui, is_open, |ui| {
|
||||
ui.add_space(4.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
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;
|
||||
for (_name, anchor, app) in self.apps_iter_mut() {
|
||||
if anchor == selected_anchor || ctx.memory(|mem| mem.everything_is_visible()) {
|
||||
app.update(ctx, frame);
|
||||
if anchor == selected_anchor || ui.memory(|mem| mem.everything_is_visible()) {
|
||||
app.demo_ui(ui, frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("demo_with_tessellate__realistic", |b| {
|
||||
b.iter(|| {
|
||||
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)
|
||||
});
|
||||
@@ -38,13 +40,17 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("demo_no_tessellate", |b| {
|
||||
b.iter(|| {
|
||||
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| {
|
||||
demo_windows.ui(ctx);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
demo_windows.ui(ui);
|
||||
});
|
||||
});
|
||||
c.bench_function("demo_only_tessellate", |b| {
|
||||
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| {
|
||||
b.iter(|| {
|
||||
ctx.run(RawInput::default(), |ctx| {
|
||||
demo_windows.ui(ctx);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
demo_windows.ui(ui);
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -195,11 +195,11 @@ impl Default for DemoWindows {
|
||||
|
||||
impl DemoWindows {
|
||||
/// Show the app ui (menu bar and windows).
|
||||
pub fn ui(&mut self, ctx: &Context) {
|
||||
if is_mobile(ctx) {
|
||||
self.mobile_ui(ctx);
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
if is_mobile(ui.ctx()) {
|
||||
self.mobile_ui(ui);
|
||||
} else {
|
||||
self.desktop_ui(ctx);
|
||||
self.desktop_ui(ui);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,36 +207,36 @@ impl DemoWindows {
|
||||
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() {
|
||||
let mut close = false;
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink(false)
|
||||
.show(ui, |ui| {
|
||||
self.groups.about.ui(ui);
|
||||
ui.add_space(12.0);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
if ui
|
||||
.button(egui::RichText::new("Continue to the demo!").size(20.0))
|
||||
.clicked()
|
||||
{
|
||||
close = true;
|
||||
}
|
||||
});
|
||||
|
||||
egui::ScrollArea::vertical()
|
||||
.auto_shrink(false)
|
||||
.show(ui, |ui| {
|
||||
self.groups.about.ui(ui);
|
||||
ui.add_space(12.0);
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
if ui
|
||||
.button(egui::RichText::new("Continue to the demo!").size(20.0))
|
||||
.clicked()
|
||||
{
|
||||
close = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if close {
|
||||
set_open(&mut self.open, About::default().name(), false);
|
||||
}
|
||||
} else {
|
||||
self.mobile_top_bar(ctx);
|
||||
self.groups.windows(ctx, &mut self.open);
|
||||
self.mobile_top_bar(ui);
|
||||
self.groups.windows(ui.ctx(), &mut self.open);
|
||||
}
|
||||
}
|
||||
|
||||
fn mobile_top_bar(&mut self, ctx: &Context) {
|
||||
egui::Panel::top("menu_bar").show(ctx, |ui| {
|
||||
fn mobile_top_bar(&mut self, ui: &mut egui::Ui) {
|
||||
egui::Panel::top("menu_bar").show_inside(ui, |ui| {
|
||||
menu::MenuBar::new()
|
||||
.config(menu::MenuConfig::new().style(StyleModifier::default()))
|
||||
.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")
|
||||
.resizable(false)
|
||||
.default_size(160.0)
|
||||
.min_size(160.0)
|
||||
.show(ctx, |ui| {
|
||||
.show_inside(ui, |ui| {
|
||||
ui.add_space(4.0);
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.heading("✒ egui demos");
|
||||
@@ -289,13 +289,13 @@ impl DemoWindows {
|
||||
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| {
|
||||
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) {
|
||||
|
||||
@@ -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| {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.heading("Central Panel");
|
||||
|
||||
@@ -32,15 +32,15 @@ impl Default for EasyMarkEditor {
|
||||
}
|
||||
|
||||
impl EasyMarkEditor {
|
||||
pub fn panels(&mut self, ctx: &egui::Context) {
|
||||
egui::Panel::bottom("easy_mark_bottom").show(ctx, |ui| {
|
||||
pub fn panels(&mut self, ui: &mut egui::Ui) {
|
||||
egui::Panel::bottom("easy_mark_bottom").show_inside(ui, |ui| {
|
||||
let layout = egui::Layout::top_down(egui::Align::Center).with_main_justify(true);
|
||||
ui.allocate_ui_with_layout(ui.available_size(), layout, |ui| {
|
||||
ui.add(crate::egui_github_link_file!())
|
||||
})
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::CentralPanel::default().show_inside(ui, |ui| {
|
||||
self.ui(ui);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,7 +74,9 @@ fn test_egui_e2e() {
|
||||
const NUM_FRAMES: usize = 5;
|
||||
for _ in 0..NUM_FRAMES {
|
||||
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);
|
||||
assert!(!clipped_primitives.is_empty());
|
||||
@@ -93,7 +95,9 @@ fn test_egui_zero_window_size() {
|
||||
const NUM_FRAMES: usize = 5;
|
||||
for _ in 0..NUM_FRAMES {
|
||||
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);
|
||||
assert!(
|
||||
|
||||
@@ -45,6 +45,8 @@ impl eframe::App for MyApp {
|
||||
ui.set_height(32.0);
|
||||
});
|
||||
|
||||
self.demo.ui(ctx);
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
self.demo.ui(ui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user