An overlay layer's own Area widget stands for no widget in the pointer resolution

egui gives the press to an interactable Area's own widget wherever no widget on the layer is.
The overlay host records that widget, and find_under and foreign_target read it as no target,
so the layer's shapes take the press and hover there (a menu's scroll strips).
This commit is contained in:
aiongg
2026-11-17 11:40:58 +00:00
parent 8c66b02cf1
commit 3e234bcd8d
2 changed files with 26 additions and 7 deletions
@@ -229,6 +229,9 @@ pub(crate) fn show_layer(ctx: &Context, spec: &LayerSpec, body: impl FnOnce(&mut
.constrain(false)
.interactable(spec.interactable)
.show(ctx, body);
// The `Area`'s own widget senses a click over the whole layer, beneath the layer's widgets: it stands for none of
// the layer's components.
crate::runtime::pointer::record_layer_widget(ctx, shown.response.id);
LayerShown { rect: shown.response.rect, layer: shown.response.layer_id }
}
+23 -7
View File
@@ -13,7 +13,7 @@ use craft_behavior::{
};
use craft_keymap::Mods;
use craft_theme::HitSizes;
use egui::{Context, Id, IdMap, Pos2, Rect, Vec2, ViewportId};
use egui::{Context, Id, IdMap, IdSet, Pos2, Rect, Vec2, ViewportId};
use smallvec::SmallVec;
use std::collections::HashMap;
use std::sync::Arc;
@@ -136,6 +136,10 @@ pub(crate) struct Shapes {
/// the last, each with its component: such a widget takes its press itself.
this_texts: IdMap<Id>,
last_texts: IdMap<Id>,
/// The layers' own egui widgets (an overlay `Area`'s, which senses a click where nothing on the layer does) in the
/// running pass and the last: such a widget lies under every widget and shape on its layer and stands for none.
this_grounds: IdSet,
last_grounds: IdSet,
/// The paint order the running pass's next registration takes.
next: u32,
/// What lies under the pass's hover point, found over `last` at the begin hook with the pass's egui targets:
@@ -218,6 +222,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) {
shapes.last = std::mem::take(&mut shapes.this);
shapes.last_bodies = std::mem::take(&mut shapes.this_bodies);
shapes.last_texts = std::mem::take(&mut shapes.this_texts);
shapes.last_grounds = std::mem::take(&mut shapes.this_grounds);
shapes.next = 0;
shapes.hover = None;
shapes.winner = None;
@@ -385,6 +390,15 @@ pub(crate) fn record_text_widget(ctx: &Context, widget: Id, owner: Id) {
});
}
/// Records the egui widget `widget` that a layer shows beneath everything on it (an overlay `Area`'s own): egui gives
/// it the press where no widget on the layer is, and the press and hover there go to the layer's shapes as if egui
/// had named no target.
pub(crate) fn record_layer_widget(ctx: &Context, widget: Id) {
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
record.this_grounds.insert(widget);
});
}
/// Records that `layer` shows the transformed body of the root `root`, which is itself shown on `parent`: a press on
/// the body layer reaches the root's own shapes beneath the body's.
pub(crate) fn record_body_layer(ctx: &Context, layer: Layer, parent: Layer, root: Id) {
@@ -608,8 +622,9 @@ impl PressWinners {
/// it shows inside its clip. The members of an arena whose host withholds them (`withhold_members`) do not count.
/// Where egui's hit test gives the point to a widget no component made (a raw egui widget on top), no press or hover
/// goes to a root; where it gives it to a widget a component made for its own text, the press is that widget's and the
/// hover goes to that component's topmost shape under the point. The roots that contain the point are those with a
/// shape under it either way.
/// hover goes to that component's topmost shape under the point. A layer's own widget, beneath everything on the layer
/// ([`record_layer_widget`]), is no widget there. The roots that contain the point are those with a shape under it
/// either way.
///
/// Hover shows where a press goes: the press winners' shapes hover, and so does the topmost shape under the point when
/// it takes no press (a label with a tooltip over a clickable row). A shape that takes a press and loses it does not.
@@ -699,8 +714,9 @@ fn find_under(ctx: &Context, viewport: ViewportId, at: Pos2, targets: PressTarge
stack.extend(roots.iter().map(|(root, entry)| (1, *root, entry, on_layer)));
}
let shown = stack.iter().any(|(_, _, entry, point)| entry.placed.iter().any(|placed| placed.clip.contains(*point)));
let text_of = targets.click.and_then(|widget| record.last_texts.get(&widget).copied());
let foreign = text_of.is_none() && targets.click.is_some_and(|widget| !registered_in(&record.last, widget));
let click = targets.click.filter(|widget| !record.last_grounds.contains(widget));
let text_of = click.and_then(|widget| record.last_texts.get(&widget).copied());
let foreign = text_of.is_none() && click.is_some_and(|widget| !registered_in(&record.last, widget));
let mut under = Under::default();
// The topmost shape under the point (of the text widget's component, when one takes the press), and each root's
// topmost shape that takes a press, ranked by tier and then by the place in paint order of the registration
@@ -847,10 +863,10 @@ fn registered_in(layers: &LayerRecord, widget: Id) -> bool {
}
/// Whether the egui widget `widget`, one of the latest press's targets, is one no component registered or made for its
/// text in the pass the press was hit-tested against: a raw egui widget.
/// text, and no layer shows beneath everything on it, in the pass the press was hit-tested against: a raw egui widget.
pub(crate) fn foreign_target(ctx: &Context, widget: Id) -> bool {
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
!registered_in(&record.last, widget) && !record.last_texts.contains_key(&widget)
!registered_in(&record.last, widget) && !record.last_texts.contains_key(&widget) && !record.last_grounds.contains(&widget)
})
}