hit: a non-modal overlay's synthetic root is not a hit target; a press passes through it unless it lands on the overlay's own content
Finding nonmodal-overlay-root-swallows (thing2:verdict:cut-commands-pointer.s1). The root is the viewport or the anchor's rect, not something drawn. A modal's scrim still catches. Tests: viewport- and node-anchored at scale 1, 1.5 and Cells, plus the wheel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
71221b13bd
commit
fc6c4246fc
2 changed files with 49 additions and 1 deletions
|
|
@ -64,7 +64,10 @@ pub(super) fn reach(rendered: &Rendered, laid: &LaidTree, index: &HashMap<&NodeI
|
|||
.iter()
|
||||
.rposition(|node| node.parent.is_none() && matches!(index.get(&node.id), Some(Node::Overlay(overlay)) if overlay.modal));
|
||||
let floor = modal.map_or(0, |m| m + 1);
|
||||
let top = rendered.placed.iter().enumerate().skip(floor).rev().find(|(_, placed)| placed.visible.is_some_and(|seen| covers(seen, point)));
|
||||
// A non-modal overlay's root is only where its content is anchored: it is the viewport or the
|
||||
// anchor's rect, not something drawn, so a press that misses the content goes on through it.
|
||||
let transparent = |i: usize| laid.nodes[i].parent.is_none() && matches!(index.get(&laid.nodes[i].id), Some(Node::Overlay(_)));
|
||||
let top = rendered.placed.iter().enumerate().skip(floor).rev().find(|(i, placed)| !transparent(*i) && placed.visible.is_some_and(|seen| covers(seen, point)));
|
||||
match (top, modal) {
|
||||
(Some((i, _)), _) => Some(Reach::Node(i)),
|
||||
(None, Some(m)) => Some(Reach::Scrim(m)),
|
||||
|
|
|
|||
|
|
@ -376,6 +376,51 @@ fn a_node_outside_its_clip_is_not_hit_where_its_rect_reaches_past_the_clip() {
|
|||
}
|
||||
}
|
||||
|
||||
// ----- a non-modal overlay -----
|
||||
|
||||
fn nonmodal_surface(anchor: Anchor) -> SurfaceDocument {
|
||||
let pop = Node::Overlay(OverlayNode { common: common("pop"), anchor, modal: false, dismiss: command("dismiss"), children: vec![button("pop-button", "inside", 80.0, 48.0)] });
|
||||
surface(
|
||||
column("root", None, Overflow::Visible, vec![button("behind", "behind", 320.0, 48.0), button("other", "other", 320.0, 48.0), pop]),
|
||||
vec![decl("behind", &[]), decl("other", &[]), decl("inside", &[]), decl("dismiss", &[])],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_press_passes_through_a_non_modal_overlays_root_to_what_lies_beneath_and_its_own_content_still_takes_it() {
|
||||
let node = Anchor::Node(AnchorNode { node: nid("behind") });
|
||||
for mode in MODES {
|
||||
for anchor in [Anchor::Viewport, node.clone()] {
|
||||
let mut rig = Rig::new(MemState::new(), &nonmodal_surface(anchor.clone()), mode);
|
||||
let (behind, other, inner) = (rig.rect("behind"), rig.rect("other"), rig.rect("pop-button"));
|
||||
let (a, b) = ((behind.x + behind.w - 0.5, behind.y + 0.5), (other.x + other.w - 0.5, other.y + 0.5));
|
||||
for at in [a, b] {
|
||||
assert!(!(at.0 >= inner.x && at.0 < inner.x + inner.w && at.1 >= inner.y && at.1 < inner.y + inner.h), "{mode:?} {anchor:?}: {at:?} is clear of the overlay's content");
|
||||
assert_eq!(hit_node(&rig, at).as_deref().map(|id| id != "pop"), Some(true), "{mode:?} {anchor:?}: the overlay's root is not what is hit at {at:?}");
|
||||
}
|
||||
rig.click(a);
|
||||
assert_eq!(commands_of(&rig.minted()), ["behind"], "{mode:?} {anchor:?}: the press reaches the anchor or the node under the viewport overlay");
|
||||
rig.click(b);
|
||||
assert_eq!(commands_of(&rig.minted()), ["other"], "{mode:?} {anchor:?}");
|
||||
// The overlay's own content is drawn over them and takes its press.
|
||||
rig.click(inside(inner));
|
||||
assert_eq!(commands_of(&rig.minted()), ["inside"], "{mode:?} {anchor:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_over_a_non_modal_overlays_root_reaches_the_pane_beneath() {
|
||||
let pane = column("pane", Some((160.0, 80.0)), Overflow::Scroll, vec![fixed("fill", 160.0, 400.0)]);
|
||||
let document = surface(column("root", None, Overflow::Visible, vec![pane, overlay("pop", false, vec![fixed("pop-body", 8.0, 16.0)])]), vec![decl("dismiss", &[])]);
|
||||
for mode in MODES {
|
||||
let mut rig = Rig::new(MemState::new(), &document, mode);
|
||||
let pane = rig.rect("pane");
|
||||
rig.send(wheel((pane.x + pane.w - 0.5, pane.y + pane.h - 0.5), (0.0, 16.0), WheelUnit::Units));
|
||||
assert!(rig.offset("pane").is_some_and(|o| o.1 > 0.0), "{mode:?}");
|
||||
}
|
||||
}
|
||||
|
||||
// ----- the modal -----
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue