diff --git a/crates/egui/src/containers/area.rs b/crates/egui/src/containers/area.rs index de348e15..557b3843 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -77,8 +77,8 @@ impl Area { self } - pub fn layer(&self) -> LayerId { - LayerId::new(self.order, self.id) + pub fn layer(&self) -> AreaLayerId { + AreaLayerId::new(self.order, self.id) } /// If false, no content responds to click @@ -187,7 +187,7 @@ impl Area { } pub(crate) struct Prepared { - layer_id: LayerId, + layer_id: AreaLayerId, state: State, move_response: Response, enabled: bool, @@ -229,7 +229,7 @@ impl Area { constrain, } = self; - let layer_id = LayerId::new(order, id); + let layer_id = AreaLayerId::new(order, id); let state = ctx.memory().areas.get(id).copied(); let is_new = state.is_none(); @@ -328,7 +328,7 @@ impl Area { return; } - let layer_id = LayerId::new(self.order, self.id); + let layer_id = AreaLayerId::new(self.order, self.id); let area_rect = ctx.memory().areas.get(self.id).map(|area| area.rect()); if let Some(area_rect) = area_rect { let clip_rect = ctx.available_rect(); @@ -416,7 +416,7 @@ impl Prepared { } } -fn pointer_pressed_on_area(ctx: &Context, layer_id: LayerId) -> bool { +fn pointer_pressed_on_area(ctx: &Context, layer_id: AreaLayerId) -> bool { if let Some(pointer_pos) = ctx.pointer_interact_pos() { let any_pressed = ctx.input().pointer.any_pressed(); any_pressed && ctx.layer_id_at(pointer_pos) == Some(layer_id) diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index e4947db3..c5e56ca3 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -331,7 +331,7 @@ impl SidePanel { ctx: &Context, add_contents: Box R + 'c>, ) -> InnerResponse { - let layer_id = LayerId::background(); + let layer_id = AreaLayerId::background(); let side = self.side; let available_rect = ctx.available_rect(); let clip_rect = ctx.input().screen_rect(); @@ -783,7 +783,7 @@ impl TopBottomPanel { ctx: &Context, add_contents: Box R + 'c>, ) -> InnerResponse { - let layer_id = LayerId::background(); + let layer_id = AreaLayerId::background(); let available_rect = ctx.available_rect(); let side = self.side; @@ -1039,7 +1039,7 @@ impl CentralPanel { add_contents: Box R + 'c>, ) -> InnerResponse { let available_rect = ctx.available_rect(); - let layer_id = LayerId::background(); + let layer_id = AreaLayerId::background(); let id = Id::new("central_panel"); let clip_rect = ctx.input().screen_rect(); diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 4decca3f..05376502 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -282,7 +282,7 @@ pub fn was_tooltip_open_last_frame(ctx: &Context, tooltip_id: Id) -> bool { for (count, (individual_id, _size)) in &state.individual_ids_and_sizes { if *individual_id == tooltip_id { let area_id = common_id.with(count); - let layer_id = LayerId::new(Order::Tooltip, area_id); + let layer_id = AreaLayerId::new(Order::Tooltip, area_id); if ctx.memory().areas.visible_last_frame(&layer_id) { return true; } diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 9d7032c5..fa8414b9 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -488,7 +488,7 @@ impl PossibleInteractions { /// Either a move or resize #[derive(Clone, Copy, Debug)] pub(crate) struct WindowInteraction { - pub(crate) area_layer_id: LayerId, + pub(crate) area_layer_id: AreaLayerId, pub(crate) start_rect: Rect, pub(crate) left: bool, pub(crate) right: bool, @@ -518,7 +518,7 @@ fn interact( window_interaction: WindowInteraction, ctx: &Context, margins: Vec2, - area_layer_id: LayerId, + area_layer_id: AreaLayerId, area: &mut area::Prepared, resize_id: Id, ) -> Option { @@ -585,7 +585,7 @@ fn move_and_resize_window(ctx: &Context, window_interaction: &WindowInteraction) fn window_interaction( ctx: &Context, possible: PossibleInteractions, - area_layer_id: LayerId, + area_layer_id: AreaLayerId, id: Id, rect: Rect, ) -> Option { @@ -626,7 +626,7 @@ fn window_interaction( fn resize_hover( ctx: &Context, possible: PossibleInteractions, - area_layer_id: LayerId, + area_layer_id: AreaLayerId, rect: Rect, ) -> Option { let pointer = ctx.input().pointer.interact_pos()?; diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index dc4a479b..c4cb687d 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -64,9 +64,9 @@ struct ContextImpl { requested_repaint_last_frame: bool, /// Written to during the frame. - layer_rects_this_frame: ahash::HashMap>, + layer_rects_this_frame: ahash::HashMap>, /// Read - layer_rects_prev_frame: ahash::HashMap>, + layer_rects_prev_frame: ahash::HashMap>, #[cfg(feature = "accesskit")] is_accesskit_enabled: bool, @@ -101,7 +101,7 @@ impl ContextImpl { // Ensure we register the background area so panels and background ui can catch clicks: let screen_rect = self.input.screen_rect(); self.memory.areas.set_state( - LayerId::background(), + AreaLayerId::background(), containers::area::State { pos: screen_rect.min, size: screen_rect.size(), @@ -377,7 +377,7 @@ impl Context { &self, clip_rect: Rect, item_spacing: Vec2, - layer_id: LayerId, + layer_id: AreaLayerId, id: Id, rect: Rect, sense: Sense, @@ -400,7 +400,7 @@ impl Context { // Whichever widget is added LAST (=on top) gets the input: if interact_rect.is_positive() && sense.interactive() { if self.style().debug.show_interactive_widgets { - Self::layer_painter(self, LayerId::debug()).rect( + Self::layer_painter(self, AreaLayerId::debug()).rect( interact_rect, 0.0, Color32::YELLOW.additive().linear_multiply(0.005), @@ -429,12 +429,12 @@ impl Context { if slf.memory.options.style.debug.show_blocking_widget { drop(slf); - Self::layer_painter(self, LayerId::debug()).debug_rect( + Self::layer_painter(self, AreaLayerId::debug()).debug_rect( interact_rect, Color32::GREEN, "Covered", ); - Self::layer_painter(self, LayerId::debug()).debug_rect( + Self::layer_painter(self, AreaLayerId::debug()).debug_rect( prev_rect, Color32::LIGHT_BLUE, "On top", @@ -456,7 +456,7 @@ impl Context { /// You specify if a thing is hovered, and the function gives a [`Response`]. pub(crate) fn interact_with_hovered( &self, - layer_id: LayerId, + layer_id: AreaLayerId, id: Id, rect: Rect, sense: Sense, @@ -604,14 +604,14 @@ impl Context { } /// Get a full-screen painter for a new or existing layer - pub fn layer_painter(&self, layer_id: LayerId) -> Painter { + pub fn layer_painter(&self, layer_id: AreaLayerId) -> Painter { let screen_rect = self.input().screen_rect(); Painter::new(self.clone(), layer_id, screen_rect) } /// Paint on top of everything else pub fn debug_painter(&self) -> Painter { - Self::layer_painter(self, LayerId::debug()) + Self::layer_painter(self, AreaLayerId::debug()) } /// How much space is still available after panels has been added. @@ -1232,25 +1232,25 @@ impl Context { impl Context { /// Move all the graphics at the given layer. /// Can be used to implement drag-and-drop (see relevant demo). - pub fn translate_layer(&self, layer_id: LayerId, delta: Vec2) { + pub fn translate_layer(&self, layer_id: AreaLayerId, delta: Vec2) { if delta != Vec2::ZERO { self.graphics().list(layer_id).translate(delta); } } /// Top-most layer at the given position. - pub fn layer_id_at(&self, pos: Pos2) -> Option { + pub fn layer_id_at(&self, pos: Pos2) -> Option { let resize_grab_radius_side = self.style().interaction.resize_grab_radius_side; self.memory().layer_id_at(pos, resize_grab_radius_side) } /// Moves the given area to the top in its [`Order`]. /// [`Area`]:s and [`Window`]:s also do this automatically when being clicked on or interacted with. - pub fn move_to_top(&self, layer_id: LayerId) { + pub fn move_to_top(&self, layer_id: AreaLayerId) { self.memory().areas.move_to_top(layer_id); } - pub(crate) fn rect_contains_pointer(&self, layer_id: LayerId, rect: Rect) -> bool { + pub(crate) fn rect_contains_pointer(&self, layer_id: AreaLayerId, rect: Rect) -> bool { rect.is_positive() && { let pointer_pos = self.input().pointer.interact_pos(); if let Some(pointer_pos) = pointer_pos { @@ -1517,7 +1517,7 @@ impl Context { ui.indent("areas", |ui| { ui.label("Visible areas, ordered back to front."); ui.label("Hover to highlight"); - let layers_ids: Vec = self.memory().areas.order().to_vec(); + let layers_ids: Vec = self.memory().areas.order().to_vec(); for layer_id in layers_ids { let area = self.memory().areas.get(layer_id.id).copied(); if let Some(area) = area { diff --git a/crates/egui/src/layers.rs b/crates/egui/src/layers.rs index 23e8b636..e619f88f 100644 --- a/crates/egui/src/layers.rs +++ b/crates/egui/src/layers.rs @@ -69,12 +69,12 @@ impl Order { /// Also acts as an identifier for [`Area`]:s. #[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -pub struct LayerId { +pub struct AreaLayerId { pub order: Order, pub id: Id, } -impl LayerId { +impl AreaLayerId { pub fn new(order: Order, id: Id) -> Self { Self { order, id } } @@ -163,13 +163,16 @@ impl PaintList { pub(crate) struct GraphicLayers([IdMap; Order::COUNT]); impl GraphicLayers { - pub fn list(&mut self, layer_id: LayerId) -> &mut PaintList { + pub fn list(&mut self, layer_id: AreaLayerId) -> &mut PaintList { self.0[layer_id.order as usize] .entry(layer_id.id) .or_default() } - pub fn drain(&mut self, area_order: &[LayerId]) -> impl ExactSizeIterator { + pub fn drain( + &mut self, + area_order: &[AreaLayerId], + ) -> impl ExactSizeIterator { let mut all_shapes: Vec<_> = Default::default(); for &order in &Order::ALL { diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index a76753f1..8692aea6 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -361,7 +361,7 @@ pub use { grid::Grid, id::{Id, IdMap}, input_state::{InputState, MultiTouchInfo, PointerState}, - layers::{LayerId, Order}, + layers::{AreaLayerId, Order}, layout::*, memory::Memory, painter::Painter, diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 271780ea..5217ede6 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -1,4 +1,4 @@ -use crate::{area, window, Id, IdMap, InputState, LayerId, Pos2, Rect, Style}; +use crate::{area, window, AreaLayerId, Id, IdMap, InputState, Pos2, Rect, Style}; // ---------------------------------------------------------------------------- @@ -357,12 +357,12 @@ impl Memory { } /// Top-most layer at the given position. - pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option { + pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option { self.areas.layer_id_at(pos, resize_interact_radius_side) } /// An iterator over all layers. Back-to-front. Top is last. - pub fn layer_ids(&self) -> impl ExactSizeIterator + '_ { + pub fn layer_ids(&self) -> impl ExactSizeIterator + '_ { self.areas.order().iter().copied() } @@ -525,16 +525,16 @@ impl Memory { pub struct Areas { areas: IdMap, /// Back-to-front. Top is last. - order: Vec, - visible_last_frame: ahash::HashSet, - visible_current_frame: ahash::HashSet, + order: Vec, + visible_last_frame: ahash::HashSet, + visible_current_frame: ahash::HashSet, /// When an area want to be on top, it is put in here. /// At the end of the frame, this is used to reorder the layers. /// This means if several layers want to be on top, they will keep their relative order. /// So if you close three windows and then reopen them all in one frame, /// they will all be sent to the top, but keep their previous internal order. - wants_to_be_on_top: ahash::HashSet, + wants_to_be_on_top: ahash::HashSet, } impl Areas { @@ -547,11 +547,11 @@ impl Areas { } /// Back-to-front. Top is last. - pub(crate) fn order(&self) -> &[LayerId] { + pub(crate) fn order(&self) -> &[AreaLayerId] { &self.order } - pub(crate) fn set_state(&mut self, layer_id: LayerId, state: area::State) { + pub(crate) fn set_state(&mut self, layer_id: AreaLayerId, state: area::State) { self.visible_current_frame.insert(layer_id); self.areas.insert(layer_id.id, state); if !self.order.iter().any(|x| *x == layer_id) { @@ -560,7 +560,7 @@ impl Areas { } /// Top-most layer at the given position. - pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option { + pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option { for layer in self.order.iter().rev() { if self.is_visible(layer) { if let Some(state) = self.areas.get(&layer.id) { @@ -578,15 +578,15 @@ impl Areas { None } - pub fn visible_last_frame(&self, layer_id: &LayerId) -> bool { + pub fn visible_last_frame(&self, layer_id: &AreaLayerId) -> bool { self.visible_last_frame.contains(layer_id) } - pub fn is_visible(&self, layer_id: &LayerId) -> bool { + pub fn is_visible(&self, layer_id: &AreaLayerId) -> bool { self.visible_last_frame.contains(layer_id) || self.visible_current_frame.contains(layer_id) } - pub fn visible_layer_ids(&self) -> ahash::HashSet { + pub fn visible_layer_ids(&self) -> ahash::HashSet { self.visible_last_frame .iter() .copied() @@ -602,7 +602,7 @@ impl Areas { .collect() } - pub fn move_to_top(&mut self, layer_id: LayerId) { + pub fn move_to_top(&mut self, layer_id: AreaLayerId) { self.visible_current_frame.insert(layer_id); self.wants_to_be_on_top.insert(layer_id); diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index cbefea88..5097a14e 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::{ emath::{Align2, Pos2, Rect, Vec2}, - layers::{LayerId, PaintList, ShapeIdx}, + layers::{AreaLayerId, PaintList, ShapeIdx}, Color32, Context, FontId, }; use epaint::{ @@ -21,7 +21,7 @@ pub struct Painter { ctx: Context, /// Where we paint - layer_id: LayerId, + layer_id: AreaLayerId, /// Everything painted in this [`Painter`] will be clipped against this. /// This means nothing outside of this rectangle will be visible on screen. @@ -34,7 +34,7 @@ pub struct Painter { impl Painter { /// Create a painter to a specific layer within a certain clip rectangle. - pub fn new(ctx: Context, layer_id: LayerId, clip_rect: Rect) -> Self { + pub fn new(ctx: Context, layer_id: AreaLayerId, clip_rect: Rect) -> Self { Self { ctx, layer_id, @@ -45,7 +45,7 @@ impl Painter { /// Redirect where you are painting. #[must_use] - pub fn with_layer_id(self, layer_id: LayerId) -> Self { + pub fn with_layer_id(self, layer_id: AreaLayerId) -> Self { Self { ctx: self.ctx, layer_id, @@ -68,7 +68,7 @@ impl Painter { } /// Redirect where you are painting. - pub fn set_layer_id(&mut self, layer_id: LayerId) { + pub fn set_layer_id(&mut self, layer_id: AreaLayerId) { self.layer_id = layer_id; } @@ -113,7 +113,7 @@ impl Painter { /// Where we paint #[inline(always)] - pub fn layer_id(&self) -> LayerId { + pub fn layer_id(&self) -> AreaLayerId { self.layer_id } diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 7e108f37..7b7ad081 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -1,6 +1,6 @@ use crate::{ emath::{Align, Pos2, Rect, Vec2}, - menu, Context, CursorIcon, Id, LayerId, PointerButton, Sense, Ui, WidgetText, + menu, AreaLayerId, Context, CursorIcon, Id, PointerButton, Sense, Ui, WidgetText, NUM_POINTER_BUTTONS, }; @@ -21,7 +21,7 @@ pub struct Response { // IN: /// Which layer the widget is part of. - pub layer_id: LayerId, + pub layer_id: AreaLayerId, /// The [`Id`] of the widget/area this response pertains. pub id: Id, diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index f8a68563..d09a32a0 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -71,7 +71,13 @@ impl Ui { /// /// Normally you would not use this directly, but instead use /// [`SidePanel`], [`TopBottomPanel`], [`CentralPanel`], [`Window`] or [`Area`]. - pub fn new(ctx: Context, layer_id: LayerId, id: Id, max_rect: Rect, clip_rect: Rect) -> Self { + pub fn new( + ctx: Context, + layer_id: AreaLayerId, + id: Id, + max_rect: Rect, + clip_rect: Rect, + ) -> Self { let style = ctx.style(); Ui { id, @@ -310,7 +316,7 @@ impl Ui { /// Use this to paint stuff within this [`Ui`]. #[inline] - pub fn layer_id(&self) -> LayerId { + pub fn layer_id(&self) -> AreaLayerId { self.painter().layer_id() } @@ -1728,7 +1734,7 @@ impl Ui { /// Redirect shapes to another paint layer. pub fn with_layer_id( &mut self, - layer_id: LayerId, + layer_id: AreaLayerId, add_contents: impl FnOnce(&mut Self) -> R, ) -> InnerResponse { self.scope(|ui| { diff --git a/crates/egui_demo_app/src/wrap_app.rs b/crates/egui_demo_app/src/wrap_app.rs index 611f1b7d..d75358de 100644 --- a/crates/egui_demo_app/src/wrap_app.rs +++ b/crates/egui_demo_app/src/wrap_app.rs @@ -354,8 +354,10 @@ impl WrapApp { } } - let painter = - ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("file_drop_target"))); + let painter = ctx.layer_painter(AreaLayerId::new( + Order::Foreground, + Id::new("file_drop_target"), + )); let screen_rect = ctx.input().screen_rect(); painter.rect_filled(screen_rect, 0.0, Color32::from_black_alpha(192)); diff --git a/crates/egui_demo_lib/src/demo/drag_and_drop.rs b/crates/egui_demo_lib/src/demo/drag_and_drop.rs index 019ace90..c38dae5a 100644 --- a/crates/egui_demo_lib/src/demo/drag_and_drop.rs +++ b/crates/egui_demo_lib/src/demo/drag_and_drop.rs @@ -15,7 +15,7 @@ pub fn drag_source(ui: &mut Ui, id: Id, body: impl FnOnce(&mut Ui)) { ui.output().cursor_icon = CursorIcon::Grabbing; // Paint the body to a new layer: - let layer_id = LayerId::new(Order::Tooltip, id); + let layer_id = AreaLayerId::new(Order::Tooltip, id); let response = ui.with_layer_id(layer_id, body).response; // Now we move the visuals of the body to where the mouse is. diff --git a/examples/file_dialog/src/main.rs b/examples/file_dialog/src/main.rs index 062e0752..182b3011 100644 --- a/examples/file_dialog/src/main.rs +++ b/examples/file_dialog/src/main.rs @@ -88,8 +88,10 @@ fn preview_files_being_dropped(ctx: &egui::Context) { } } - let painter = - ctx.layer_painter(LayerId::new(Order::Foreground, Id::new("file_drop_target"))); + let painter = ctx.layer_painter(AreaLayerId::new( + Order::Foreground, + Id::new("file_drop_target"), + )); let screen_rect = ctx.input().screen_rect(); painter.rect_filled(screen_rect, 0.0, Color32::from_black_alpha(192));