mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -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:
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user