diff --git a/crates/egui/src/containers/menu.rs b/crates/egui/src/containers/menu.rs index f2aaee046..a25e4e7ab 100644 --- a/crates/egui/src/containers/menu.rs +++ b/crates/egui/src/containers/menu.rs @@ -161,15 +161,14 @@ impl MenuState { if state.last_visible_pass + 1 < pass_nr { state.open_item = None; } - if let Some(item) = state.open_item { - if data + if let Some(item) = state.open_item + && data .get_temp(item.with(Self::ID)) .is_none_or(|item: Self| item.last_visible_pass + 1 < pass_nr) { // If the open item wasn't shown for at least a frame, reset the open item state.open_item = None; } - } let r = f(&mut state); data.insert_temp(state_id, state); r diff --git a/crates/egui/src/containers/mod.rs b/crates/egui/src/containers/mod.rs index a34ed1647..48ba79da7 100644 --- a/crates/egui/src/containers/mod.rs +++ b/crates/egui/src/containers/mod.rs @@ -27,7 +27,7 @@ pub use { frame::Frame, modal::{Modal, ModalResponse}, old_popup::*, - panel::{CentralPanel, HorizontalSide, Panel, PanelSide, VerticalSide}, + panel::*, popup::*, resize::Resize, scene::{DragPanButtons, Scene}, diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index 5d22ee747..fa6f166a0 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -18,8 +18,8 @@ use emath::{GuiRounding as _, Pos2}; use crate::{ - lerp, vec2, Align, Context, CursorIcon, Frame, Id, InnerResponse, LayerId, Layout, NumExt, - Rangef, Rect, Sense, Stroke, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, + Align, Context, CursorIcon, Frame, Id, InnerResponse, LayerId, Layout, NumExt as _, Rangef, + Rect, Sense, Stroke, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, lerp, vec2, }; fn animate_expansion(ctx: &Context, id: Id, is_expanded: bool) -> f32 { @@ -73,23 +73,23 @@ pub enum PanelSide { impl PanelSide { fn opposite(self) -> Self { - let opposite_vertical = |side: VerticalSide| -> PanelSide { + let opposite_vertical = |side: VerticalSide| -> Self { match side { - VerticalSide::Left => PanelSide::Vertical(VerticalSide::Right), - VerticalSide::Right => PanelSide::Vertical(VerticalSide::Left), + VerticalSide::Left => Self::Vertical(VerticalSide::Right), + VerticalSide::Right => Self::Vertical(VerticalSide::Left), } }; - let opposite_horizontal = |side: HorizontalSide| -> PanelSide { + let opposite_horizontal = |side: HorizontalSide| -> Self { match side { - HorizontalSide::Top => PanelSide::Horizontal(HorizontalSide::Bottom), - HorizontalSide::Bottom => PanelSide::Horizontal(HorizontalSide::Top), + HorizontalSide::Top => Self::Horizontal(HorizontalSide::Bottom), + HorizontalSide::Bottom => Self::Horizontal(HorizontalSide::Top), } }; match self { - PanelSide::Vertical(side) => opposite_vertical(side), - PanelSide::Horizontal(side) => opposite_horizontal(side), + Self::Vertical(side) => opposite_vertical(side), + Self::Horizontal(side) => opposite_horizontal(side), } } @@ -105,8 +105,8 @@ impl PanelSide { }; match self { - PanelSide::Vertical(side) => set_rect_size_vertical(side), - PanelSide::Horizontal(side) => set_rect_size_horizontal(side), + Self::Vertical(side) => set_rect_size_vertical(side), + Self::Horizontal(side) => set_rect_size_horizontal(side), } } @@ -126,8 +126,8 @@ impl PanelSide { }; match self { - PanelSide::Vertical(side) => side_axe_vertical(side, rect), - PanelSide::Horizontal(side) => side_axe_horizontal(side, rect), + Self::Vertical(side) => side_axe_vertical(side, rect), + Self::Horizontal(side) => side_axe_horizontal(side, rect), } } @@ -147,8 +147,8 @@ impl PanelSide { }; match self { - PanelSide::Vertical(side) => sign_vertical(side), - PanelSide::Horizontal(side) => sign_horizontal(side), + Self::Vertical(side) => sign_vertical(side), + Self::Horizontal(side) => sign_horizontal(side), } } } @@ -619,7 +619,7 @@ impl Panel { HorizontalSide::Top => cursor.min.y = rect.max.y, HorizontalSide::Bottom => cursor.max.y = rect.min.y, }, - }; + } ui.set_cursor(cursor); } @@ -846,7 +846,7 @@ impl Panel { } } - fn get_animated_size(ctx: &Context, panel: &Panel) -> f32 { + fn get_animated_size(ctx: &Context, panel: &Self) -> f32 { let get_rect_state_size = |state: PanelState| match panel.side { PanelSide::Vertical(_) => state.rect.width(), PanelSide::Horizontal(_) => state.rect.height(), @@ -976,3 +976,38 @@ fn clamp_to_range(x: f32, range: Rangef) -> f32 { let range = range.as_positive(); x.clamp(range.min, range.max) } + +// ---------------------------------------------------------------------------- + +mod legacy { + #![expect(deprecated)] + + use super::{Id, Panel}; + + #[deprecated = "Use Panel::left or Panel::right instead"] + pub struct SidePanel {} + + impl SidePanel { + pub fn left(id: impl Into) -> Panel { + Panel::left(id) + } + pub fn right(id: impl Into) -> Panel { + Panel::right(id) + } + } + + #[deprecated = "Use Panel::top or Panel::bottom instead"] + pub struct TopBottomPanel {} + + impl TopBottomPanel { + pub fn top(id: impl Into) -> Panel { + Panel::top(id) + } + pub fn bottom(id: impl Into) -> Panel { + Panel::bottom(id) + } + } +} + +#[expect(deprecated)] +pub use legacy::{SidePanel, TopBottomPanel}; diff --git a/crates/egui/src/memory/mod.rs b/crates/egui/src/memory/mod.rs index 6192f3e72..c106c154c 100644 --- a/crates/egui/src/memory/mod.rs +++ b/crates/egui/src/memory/mod.rs @@ -1271,9 +1271,7 @@ impl Areas { pub fn top_layer_id(&self, order: Order) -> Option { self.order - .iter() - .filter(|layer| layer.order == order && !self.is_sublayer(layer)) - .next_back() + .iter().rfind(|layer| layer.order == order && !self.is_sublayer(layer)) .copied() } diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index 4144a8cd9..e5fb04b0d 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -634,7 +634,7 @@ impl SubMenu { /// Usually you don't need to use it directly. pub struct MenuState { /// The opened sub-menu and its [`Id`] - sub_menu: Option<(Id, Arc>)>, + sub_menu: Option<(Id, Arc>)>, /// Bounding box of this menu (without the sub-menu), /// including the frame and everything. diff --git a/crates/egui/src/ui_stack.rs b/crates/egui/src/ui_stack.rs index 0caf97f4f..07026c45b 100644 --- a/crates/egui/src/ui_stack.rs +++ b/crates/egui/src/ui_stack.rs @@ -209,7 +209,7 @@ pub struct UiStack { pub layout_direction: Direction, pub min_rect: Rect, pub max_rect: Rect, - pub parent: Option>, + pub parent: Option>, } // these methods act on this specific node diff --git a/crates/egui_demo_app/src/accessibility_inspector.rs b/crates/egui_demo_app/src/accessibility_inspector.rs index f721b710c..9ba3a8082 100644 --- a/crates/egui_demo_app/src/accessibility_inspector.rs +++ b/crates/egui_demo_app/src/accessibility_inspector.rs @@ -1,12 +1,13 @@ +use std::mem; + use accesskit::{Action, ActionRequest, NodeId}; use accesskit_consumer::{FilterResult, Node, Tree, TreeChangeHandler}; + use eframe::epaint::text::TextWrapMode; -use egui::collapsing_header::CollapsingState; use egui::{ Button, Color32, Context, Event, Frame, FullOutput, Id, Key, KeyboardShortcut, Label, - Modifiers, RawInput, RichText, ScrollArea, SidePanel, TopBottomPanel, Ui, + Modifiers, Panel, RawInput, RichText, ScrollArea, Ui, collapsing_header::CollapsingState, }; -use std::mem; /// This [`egui::Plugin`] adds an inspector Panel. /// @@ -86,10 +87,10 @@ impl egui::Plugin for AccessibilityInspectorPlugin { ctx.enable_accesskit(); - SidePanel::right(Self::id()).show(ctx, |ui| { + Panel::right(Self::id()).show(ctx, |ui| { ui.heading("🔎 AccessKit Inspector"); if let Some(selected_node) = self.selected_node { - TopBottomPanel::bottom(Self::id().with("details_panel")) + Panel::bottom(Self::id().with("details_panel")) .frame(Frame::new()) .show_separator_line(false) .show_inside(ui, |ui| { diff --git a/crates/egui_demo_app/src/apps/image_viewer.rs b/crates/egui_demo_app/src/apps/image_viewer.rs index c341d2385..052996eef 100644 --- a/crates/egui_demo_app/src/apps/image_viewer.rs +++ b/crates/egui_demo_app/src/apps/image_viewer.rs @@ -2,8 +2,6 @@ use egui::ImageFit; use egui::Slider; use egui::Vec2; use egui::emath::Rot2; -use egui::panel::Side; -use egui::panel::TopBottomSide; #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ImageViewer { @@ -52,7 +50,7 @@ impl Default for ImageViewer { impl eframe::App for ImageViewer { fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { - egui::TopBottomPanel::new(TopBottomSide::Top, "url bar").show(ctx, |ui| { + egui::Panel::top("url bar").show(ctx, |ui| { ui.horizontal_centered(|ui| { let label = ui.label("URI:"); ui.text_edit_singleline(&mut self.uri_edit_text) @@ -73,7 +71,7 @@ impl eframe::App for ImageViewer { }); }); - egui::SidePanel::new(Side::Left, "controls").show(ctx, |ui| { + egui::Panel::left("controls").show(ctx, |ui| { // uv ui.label("UV"); ui.add(Slider::new(&mut self.image_options.uv.min.x, 0.0..=1.0).text("min x")); diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index 8033539dd..179543680 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -236,7 +236,7 @@ impl DemoWindows { } fn mobile_top_bar(&mut self, ctx: &Context) { - egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| { + egui::Panel::top("menu_bar").show(ctx, |ui| { menu::MenuBar::new() .config(menu::MenuConfig::new().style(StyleModifier::default())) .ui(ui, |ui| { @@ -262,10 +262,10 @@ impl DemoWindows { } fn desktop_ui(&mut self, ctx: &Context) { - egui::SidePanel::right("egui_demo_panel") + egui::Panel::right("egui_demo_panel") .resizable(false) - .default_width(160.0) - .min_width(160.0) + .default_size(160.0) + .min_size(160.0) .show(ctx, |ui| { ui.add_space(4.0); ui.vertical_centered(|ui| { @@ -289,7 +289,7 @@ impl DemoWindows { self.demo_list_ui(ui); }); - egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| { + egui::Panel::top("menu_bar").show(ctx, |ui| { menu::MenuBar::new().ui(ui, |ui| { file_menu_button(ui); }); diff --git a/crates/epaint/src/shapes/shape.rs b/crates/epaint/src/shapes/shape.rs index 8ee852c61..fa8a3e75c 100644 --- a/crates/epaint/src/shapes/shape.rs +++ b/crates/epaint/src/shapes/shape.rs @@ -30,7 +30,7 @@ pub enum Shape { /// Recursively nest more shapes - sometimes a convenience to be able to do. /// For performance reasons it is better to avoid it. - Vec(Vec), + Vec(Vec), /// Circle with optional outline and fill. Circle(CircleShape), diff --git a/examples/hello_android/src/lib.rs b/examples/hello_android/src/lib.rs index c138b97e1..1de7684f5 100644 --- a/examples/hello_android/src/lib.rs +++ b/examples/hello_android/src/lib.rs @@ -41,7 +41,7 @@ impl eframe::App for MyApp { // TODO(lucasmerlin): This is a pretty big hack, should be fixed once safe_area implemented // for android: // https://github.com/rust-windowing/winit/issues/3910 - egui::TopBottomPanel::top("status_bar_space").show(ctx, |ui| { + egui::Panel::top("status_bar_space").show(ctx, |ui| { ui.set_height(32.0); });