diff --git a/egui/src/containers/area.rs b/egui/src/containers/area.rs index 94ec9dcd..e686f23e 100644 --- a/egui/src/containers/area.rs +++ b/egui/src/containers/area.rs @@ -53,10 +53,7 @@ impl Area { } pub fn layer(&self) -> LayerId { - LayerId { - order: self.order, - id: self.id, - } + LayerId::new(self.order, self.id) } /// moveable by dragging the area? diff --git a/egui/src/context.rs b/egui/src/context.rs index ab621d0e..785dd123 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -458,8 +458,8 @@ impl Context { .map(|id| self.memory().has_kb_focus(id)) .unwrap_or(false); - if interaction_id.is_none() || sense == Sense::nothing() { - // Not interested in input: + if interaction_id.is_none() || sense == Sense::nothing() || !layer_id.allow_interaction() { + // Not interested or allowed input: return Response { ctx: self.clone(), sense, diff --git a/egui/src/layers.rs b/egui/src/layers.rs index ba983959..36d57b1b 100644 --- a/egui/src/layers.rs +++ b/egui/src/layers.rs @@ -11,8 +11,10 @@ pub enum Order { /// Normal moveable windows that you reorder by click Middle, /// Popups, menus etc that should always be painted on top of windows - Foreground, /// Foreground objects can also have tooltips + Foreground, + /// Things floating on top of everything else, like tooltips. + /// You cannot interact with these. Tooltip, /// Debug layer, always painted last / on top Debug, @@ -26,6 +28,13 @@ impl Order { Self::Tooltip, Self::Debug, ]; + + pub fn allow_interaction(&self) -> bool { + match self { + Self::Background | Self::Middle | Self::Foreground | Self::Debug => true, + Self::Tooltip => false, + } + } } /// An identifier for a paint layer. @@ -38,6 +47,10 @@ pub struct LayerId { } impl LayerId { + pub fn new(order: Order, id: Id) -> Self { + Self { order, id } + } + pub fn debug() -> Self { Self { order: Order::Debug, @@ -51,6 +64,10 @@ impl LayerId { id: Id::background(), } } + + pub fn allow_interaction(&self) -> bool { + self.order.allow_interaction() + } } /// A unique identifier of a specific `PaintCmd` in a `PaintList`. diff --git a/egui/src/ui.rs b/egui/src/ui.rs index d54b2036..9ec86254 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -109,10 +109,7 @@ impl Ui { let mut ctx = Context::new(); ctx.begin_frame(Default::default()); let id = Id::new("__test"); - let layer_id = LayerId { - order: Order::Middle, - id, - }; + let layer_id = LayerId::new(Order::Middle, id); let rect = Rect::from_min_size(Pos2::new(0.0, 0.0), vec2(1000.0, 1000.0)); Self::new(ctx, layer_id, id, rect, rect) }