Browse Source

[drag-and-drop] Disable interactions with Tooltip layer

strong-ids
Emil Ernerfeldt 4 years ago
parent
commit
c9c12f2d79
  1. 5
      egui/src/containers/area.rs
  2. 4
      egui/src/context.rs
  3. 19
      egui/src/layers.rs
  4. 5
      egui/src/ui.rs

5
egui/src/containers/area.rs

@ -53,10 +53,7 @@ impl Area {
} }
pub fn layer(&self) -> LayerId { pub fn layer(&self) -> LayerId {
LayerId { LayerId::new(self.order, self.id)
order: self.order,
id: self.id,
}
} }
/// moveable by dragging the area? /// moveable by dragging the area?

4
egui/src/context.rs

@ -458,8 +458,8 @@ impl Context {
.map(|id| self.memory().has_kb_focus(id)) .map(|id| self.memory().has_kb_focus(id))
.unwrap_or(false); .unwrap_or(false);
if interaction_id.is_none() || sense == Sense::nothing() { if interaction_id.is_none() || sense == Sense::nothing() || !layer_id.allow_interaction() {
// Not interested in input: // Not interested or allowed input:
return Response { return Response {
ctx: self.clone(), ctx: self.clone(),
sense, sense,

19
egui/src/layers.rs

@ -11,8 +11,10 @@ pub enum Order {
/// Normal moveable windows that you reorder by click /// Normal moveable windows that you reorder by click
Middle, Middle,
/// Popups, menus etc that should always be painted on top of windows /// Popups, menus etc that should always be painted on top of windows
Foreground,
/// Foreground objects can also have tooltips /// Foreground objects can also have tooltips
Foreground,
/// Things floating on top of everything else, like tooltips.
/// You cannot interact with these.
Tooltip, Tooltip,
/// Debug layer, always painted last / on top /// Debug layer, always painted last / on top
Debug, Debug,
@ -26,6 +28,13 @@ impl Order {
Self::Tooltip, Self::Tooltip,
Self::Debug, 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. /// An identifier for a paint layer.
@ -38,6 +47,10 @@ pub struct LayerId {
} }
impl LayerId { impl LayerId {
pub fn new(order: Order, id: Id) -> Self {
Self { order, id }
}
pub fn debug() -> Self { pub fn debug() -> Self {
Self { Self {
order: Order::Debug, order: Order::Debug,
@ -51,6 +64,10 @@ impl LayerId {
id: Id::background(), id: Id::background(),
} }
} }
pub fn allow_interaction(&self) -> bool {
self.order.allow_interaction()
}
} }
/// A unique identifier of a specific `PaintCmd` in a `PaintList`. /// A unique identifier of a specific `PaintCmd` in a `PaintList`.

5
egui/src/ui.rs

@ -109,10 +109,7 @@ impl Ui {
let mut ctx = Context::new(); let mut ctx = Context::new();
ctx.begin_frame(Default::default()); ctx.begin_frame(Default::default());
let id = Id::new("__test"); let id = Id::new("__test");
let layer_id = LayerId { let layer_id = LayerId::new(Order::Middle, id);
order: Order::Middle,
id,
};
let rect = Rect::from_min_size(Pos2::new(0.0, 0.0), vec2(1000.0, 1000.0)); 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) Self::new(ctx, layer_id, id, rect, rect)
} }

Loading…
Cancel
Save