From 2ebd32d5984aa35ea250a05fd67d686c0028e93e Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 06:12:52 +0000 Subject: [PATCH] DIAG: the press winner's candidates (every shape under the press per root, with order and clip) and each root's start decision, for the six press-routing tests of round I --- crates/ui-contract/src/primitives/sensing.rs | 11 +++ crates/ui-contract/src/runtime/pointer.rs | 72 ++++++++++++++++++-- 2 files changed, 77 insertions(+), 6 deletions(-) diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index bf36467ea..0cd415bae 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -803,6 +803,17 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab }; let allowed = crate::runtime::sampler::root_takes_press(ctx, root, layer, at, untargeted) && root.is_some_and(|own| pointer::press_winner(ctx, at, targets).is_some_and(|(_, winner)| winner == own)); + if let Some(test) = pointer::diag_test() + && state.root.is_some_and(|own| own.rect.contains(at)) + { + eprintln!( + "DIAG {test}: start root {:?} enabled {enabled} allowed {allowed} untargeted {untargeted} takes {} layer {layer:?} rect {:?} clip {:?}", + root.map(pointer::diag_id), + crate::runtime::sampler::root_takes_press(ctx, root, layer, at, untargeted), + state.root.map(|own| own.rect), + state.root.map(|own| own.clip), + ); + } if !enabled || !allowed { if !state.previous.is_empty() && ctx.input(|i| i.pointer.button_pressed(egui::PointerButton::Secondary)) { eprintln!( diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 3b9f8edf0..b81c51fa9 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -550,15 +550,17 @@ pub(crate) fn press_winner(ctx: &Context, at: Pos2, targets: PressTargets) -> Op } fn find_press_winner(ctx: &Context, viewport: ViewportId, at: Pos2, targets: PressTargets) -> Option<(Winner, Id)> { - let layer = areas::layer_at(ctx, at)?; + let Some(layer) = areas::layer_at(ctx, at) else { + if let Some(test) = diag_test() { + eprintln!("DIAG {test}: press_winner at {at:?}: no layer"); + } + return None; + }; let to_layer = |layer: Layer| areas::layer_map(ctx, layer).map_or(at, |map| map.to_layer(at)); let body = PerViewport::::with(ctx, viewport, |record| record.last_bodies.get(&layer).copied()); let beneath = body.map(|(root, parent)| (root, parent, to_layer(parent))); let on_layer = to_layer(layer); - PerViewport::::with(ctx, viewport, |record| { - if targets.click.is_some_and(|widget| !registered_in(&record.last, widget)) { - return None; - } + let found = PerViewport::::with(ctx, viewport, |record| { // Bottom to top: the body layer's root on its own layer, then the roots on the layer in paint order. let mut stack: Vec<(u8, Id, &RootRecord, Pos2)> = Vec::new(); if let Some((root, parent, point)) = beneath @@ -570,6 +572,36 @@ fn find_press_winner(ctx: &Context, viewport: ViewportId, at: Pos2, targets: Pre 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))); + if let Some(test) = diag_test() { + let hits: Vec = stack + .iter() + .flat_map(|(tier, root, entry, point)| { + entry.shapes.iter().zip(&entry.placed).filter(|(shape, _)| shape.hits(*point)).map(move |(shape, placed)| { + format!( + "[tier {tier} root {} owner {} part {:?} sense {:?} level {:?} pos {} order {} clip_in {}]", + diag_id(*root), + diag_id(shape.owner), + shape.part, + shape.sense, + shape.priority.level, + shape.position, + placed.order, + placed.clip.contains(*point) + ) + }) + }) + .collect(); + let foreign = |widget: Option| widget.map(|widget| (diag_id(widget), !registered_in(&record.last, widget))); + eprintln!( + "DIAG {test}: press_winner at {at:?} layer {layer:?} body {:?} click {:?} drag {:?} shown {shown} hits {hits:?}", + beneath.map(|(root, parent, _)| (diag_id(root), parent)), + foreign(targets.click), + foreign(targets.drag) + ); + } + if targets.click.is_some_and(|widget| !registered_in(&record.last, widget)) { + return None; + } stack .into_iter() .filter_map(|(tier, root, entry, point)| { @@ -587,7 +619,35 @@ fn find_press_winner(ctx: &Context, viewport: ViewportId, at: Pos2, targets: Pre }) .max_by_key(|(rank, ..)| *rank) .map(|(_, winner, root)| (winner, root)) - }) + }); + if let Some(test) = diag_test() { + eprintln!( + "DIAG {test}: press_winner at {at:?} -> {:?}", + found.map(|(winner, root)| (diag_id(root), diag_id(winner.owner), winner.part, winner.sense)) + ); + } + found +} + +/// DIAG: the test under study this thread runs, if any. +pub(crate) fn diag_test() -> Option<&'static str> { + const TESTS: [&str; 6] = [ + "gradient_map_stop_picker_closed_without_a_colour_changes_nothing", + "photo_filter_colour_picker_previews_live_cancel_restores_and_ok_is_one_step", + "every_paragraph_box_handle_resizes_the_box_with_snapping_on", + "click_inside_the_paragraph_box_off_the_glyphs_moves_the_caret", + "a_crop_drag_begun_before_the_dialog_still_ends_under_it", + "move_pointer_still_reaches_the_liquify_workspace", + ]; + let thread = std::thread::current(); + let name = thread.name()?; + TESTS.into_iter().find(|test| name.ends_with(test)) +} + +/// DIAG: the tail of an id's path. +pub(crate) fn diag_id(id: Id) -> String { + let text = format!("{id:?}"); + text.char_indices().rev().nth(90).map_or(text.clone(), |(at, _)| text[at..].to_owned()) } /// Whether some root registered the egui widget `widget` in `layers`.