diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index 6ed34fd7c..24a4d24d2 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -1044,6 +1044,7 @@ impl CentralPanel { } /// Show the panel at the top level. + #[deprecated = "Use show_inside() instead"] pub fn show( self, ctx: &Context, diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 67abb0556..dc5f06207 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -19,8 +19,8 @@ use crate::{ ImmediateViewportRendererCallback, Key, KeyboardShortcut, Label, LayerId, Memory, ModifierNames, Modifiers, NumExt as _, Order, Painter, RawInput, Response, RichText, SafeAreaInsets, ScrollArea, Sense, Style, TextStyle, TextureHandle, TextureOptions, Ui, - ViewportBuilder, ViewportCommand, ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, - ViewportOutput, Visuals, Widget as _, WidgetRect, WidgetText, + UiBuilder, ViewportBuilder, ViewportCommand, ViewportId, ViewportIdMap, ViewportIdPair, + ViewportIdSet, ViewportOutput, Visuals, Widget as _, WidgetRect, WidgetText, animation_manager::AnimationManager, containers::{self, area::AreaState}, data::output::PlatformOutput, @@ -793,11 +793,23 @@ impl Context { let plugins = self.read(|ctx| ctx.plugins.ordered_plugins()); #[expect(deprecated)] self.run(new_input, |ctx| { - crate::CentralPanel::no_frame().show(ctx, |ui| { - plugins.on_begin_pass(ui); - run_ui(ui); - plugins.on_end_pass(ui); - }); + let mut top_ui = Ui::new( + ctx.clone(), + Id::new((ctx.viewport_id(), "__top_ui")), + UiBuilder::new() + .layer_id(LayerId::background()) + .max_rect(ctx.globally_available_rect().round_ui()), + ); + + { + plugins.on_begin_pass(&mut top_ui); + run_ui(&mut top_ui); + plugins.on_end_pass(&mut top_ui); + } + + // Inform ctx about what we actually used, so we can shrink the native window to fit. + // TODO(emilk): make better use of this somehow + ctx.pass_state_mut(|state| state.allocate_central_panel(top_ui.min_rect())); }) } @@ -3628,7 +3640,7 @@ impl Context { /// If AccessKit support is active for the current frame, get or create /// a node builder with the specified ID and return a mutable reference to it. /// For newly created nodes, the parent is the parent [`Ui`]s ID. - /// And an [`Ui`]s parent can be set with [`crate::UiBuilder::accessibility_parent`]. + /// And an [`Ui`]s parent can be set with [`UiBuilder::accessibility_parent`]. /// /// The `Context` lock is held while the given closure is called! /// diff --git a/crates/egui_demo_lib/benches/benchmark.rs b/crates/egui_demo_lib/benches/benchmark.rs index 36564de25..114a818a1 100644 --- a/crates/egui_demo_lib/benches/benchmark.rs +++ b/crates/egui_demo_lib/benches/benchmark.rs @@ -140,19 +140,19 @@ pub fn criterion_benchmark(c: &mut Criterion) { let ctx = egui::Context::default(); ctx.begin_pass(RawInput::default()); - egui::CentralPanel::default().show(&ctx, |ui| { - c.bench_function("Painter::rect", |b| { - let painter = ui.painter(); - let rect = ui.max_rect(); - b.iter(|| { - painter.rect( - rect, - 2.0, - egui::Color32::RED, - (1.0, egui::Color32::WHITE), - egui::StrokeKind::Inside, - ); - }); + let painter = + egui::Painter::new(ctx.clone(), egui::LayerId::background(), ctx.content_rect()); + + c.bench_function("Painter::rect", |b| { + let rect = painter.clip_rect(); + b.iter(|| { + painter.rect( + rect, + 2.0, + egui::Color32::RED, + (1.0, egui::Color32::WHITE), + egui::StrokeKind::Inside, + ); }); }); diff --git a/crates/egui_kittest/tests/accesskit.rs b/crates/egui_kittest/tests/accesskit.rs index 40c833f71..2b14d0fa1 100644 --- a/crates/egui_kittest/tests/accesskit.rs +++ b/crates/egui_kittest/tests/accesskit.rs @@ -18,8 +18,8 @@ fn empty_ui_should_return_tree_with_only_root_window() { assert_eq!( output.nodes.len(), - 4, - "Expected the root node and two Uis and a Frame for the panel" + 2, + "Expected the root node and the top level Ui; found: {output:#?}", ); assert_eq!( @@ -28,8 +28,8 @@ fn empty_ui_should_return_tree_with_only_root_window() { .iter() .filter(|(_, n)| n.role() == Role::GenericContainer) .count(), - 3, - "Expected two Uis and one Frame as GenericContainer nodes.", + 1, + "Expected a single Ui as a GenericContainer node.", ); let (id, root) = &output.nodes[0]; diff --git a/examples/custom_window_frame/src/main.rs b/examples/custom_window_frame/src/main.rs index 4fa31c1f9..49b3276f0 100644 --- a/examples/custom_window_frame/src/main.rs +++ b/examples/custom_window_frame/src/main.rs @@ -32,7 +32,7 @@ impl eframe::App for MyApp { } fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { - custom_window_frame(ui.ctx(), "egui with custom frame", |ui| { + custom_window_frame(ui, "egui with custom frame", |ui| { ui.label("This is just the contents of the window."); ui.horizontal(|ui| { ui.label("egui theme:"); @@ -42,18 +42,20 @@ impl eframe::App for MyApp { } } -fn custom_window_frame(ctx: &egui::Context, title: &str, add_contents: impl FnOnce(&mut egui::Ui)) { - use egui::{CentralPanel, UiBuilder}; +fn custom_window_frame(ui: &mut egui::Ui, title: &str, add_contents: impl FnOnce(&mut egui::Ui)) { + use egui::UiBuilder; let panel_frame = egui::Frame::new() - .fill(ctx.global_style().visuals.window_fill()) + .fill(ui.global_style().visuals.window_fill()) .corner_radius(10) - .stroke(ctx.global_style().visuals.widgets.noninteractive.fg_stroke) + .stroke(ui.global_style().visuals.widgets.noninteractive.fg_stroke) .outer_margin(1); // so the stroke is within the bounds - CentralPanel::default().frame(panel_frame).show(ctx, |ui| { + panel_frame.show(ui, |ui| { let app_rect = ui.max_rect(); + ui.expand_to_include_rect(app_rect); // Expand frame to include it all + let title_bar_height = 32.0; let title_bar_rect = { let mut rect = app_rect;