From d7d2ba44e3db78896c424ca5319946fa5c7c10bd Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 17:02:21 -0500 Subject: [PATCH] Hand passed drags to arena background parts --- crates/ui-contract/src/contract/cx/parts.rs | 2 +- crates/ui-contract/src/runtime/pointer.rs | 4 ++-- .../ui-contract/tests/it/runtime/pointer.rs | 22 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/contract/cx/parts.rs b/crates/ui-contract/src/contract/cx/parts.rs index 1fab11e0d..c434554ce 100644 --- a/crates/ui-contract/src/contract/cx/parts.rs +++ b/crates/ui-contract/src/contract/cx/parts.rs @@ -96,7 +96,7 @@ pub(crate) struct PartExtras { } impl PartBuilder<'_> { - /// Send a passed drag to the enclosing arena root, retaining clicks on this part. + /// Send a passed drag to the enclosing arena root or one of its draggable parts, retaining clicks on this part. /// Declare `CLICK | PASSES_DRAG` as the part's sense. pub fn drag_to_root(self) -> Self { self.decl.drag_to_root = true; diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 43548c587..955f65c17 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -811,7 +811,7 @@ fn find_under(ctx: &Context, viewport: ViewportId, at: Pos2, targets: PressTarge let shape = &entry.shapes[index]; index != winner.index && shape.sense.contains(craft_behavior::Sense::DRAG) - && (!winner.drag_to_root || (shape.owner == root && shape.part.is_none())) + && (!winner.drag_to_root || shape.owner == root) }) .collect(); pick(&dragging, ResolveFor::Press) @@ -863,7 +863,7 @@ fn winners_of(mut ranked: Vec<((u8, u32), Winner, Id, bool)>) -> PressWinner // shape that passes its drag, the next shape that drags takes it, in the same root or one below. (true, false) => { let passes = winners.click.is_some_and(|(top, _)| top.sense.contains(craft_behavior::Sense::PASSES_DRAG)); - let root_target = winners.click.is_some_and(|(top, owner)| top.drag_to_root && (root != owner || winner.part.is_some())); + let root_target = winners.click.is_some_and(|(top, owner)| top.drag_to_root && root != owner); if drags && !root_target && (passes || !(clicks || root_clicks)) { winners.drag = Some((winner, root)); } diff --git a/crates/ui-contract/tests/it/runtime/pointer.rs b/crates/ui-contract/tests/it/runtime/pointer.rs index fccaab269..4c91f2386 100644 --- a/crates/ui-contract/tests/it/runtime/pointer.rs +++ b/crates/ui-contract/tests/it/runtime/pointer.rs @@ -568,6 +568,28 @@ fn one_pointer_resolution_per_pass_whatever_the_number_of_roots() { const LINK: PartKey = PartKey::new("link"); const SURFACE: PartKey = PartKey::new("surface"); +#[trial] +fn passed_drag_reaches_an_arena_roots_background_part() { + let page = rect(100.0, 100.0, 400.0, 300.0); + let area = rect(150.0, 150.0, 60.0, 40.0); + let background = ProbePart::new(BACKGROUND, page, Sense::CLICK | Sense::DRAG).level(HitLevel::Background, 0); + let field = ProbePart::new(SURFACE, area, Sense::CLICK | Sense::DRAG); + let overlay = ProbePart::new(LINK, area, Sense::CLICK | Sense::PASSES_DRAG).level(HitLevel::Edge, 0).drag_to_root(); + let root = ProbeRoot::new("canvas", page, Sense::FOCUS | Sense::WHEEL) + .arena() + .part(background) + .member(ProbeMember::new("parts", page, Sense::empty()).part(field).part(overlay)); + let (mut show_frame, log) = scene(vec![root]); + let mut frames = Frames::new(); + frames.idle(2, &mut show_frame); + drag(&mut frames, area.center(), Vec2::new(40.0, 30.0), &mut show_frame); + assert_eq!(drags(&log.borrow().root_phases(0, Some(BACKGROUND))), 1, "background part takes the drag"); + assert_eq!(drags(&log.borrow().member_phases(0, "parts", Some(SURFACE))), 0, "field does not drag"); + log.borrow_mut().clear(); + pointer::click(&mut frames, area.center(), &mut show_frame); + assert!(log.borrow().member_phases(0, "parts", Some(LINK)).iter().any(|phase| matches!(phase, PressPhase::Release { click: true, .. }))); +} + /// A clickable overlay can send its drag to the canvas root past a draggable field. #[trial] fn passed_drag_can_target_the_arena_root_past_a_field() {