ui-contract: the suite's row press avoids pointer-only press parts of the collection, its children and ancestors (a grid's column edges)

This commit is contained in:
bflatastic
2026-11-22 21:01:15 +07:00
parent b1af55834d
commit 1e48d97023
2 changed files with 38 additions and 10 deletions
+17
View File
@@ -757,6 +757,23 @@ pub(crate) fn child_part_bounds(ctx: &Context, subject: Id, part: craft_behavior
})
}
/// The parts in last pass's shape record that take a press (a click or a drag), each with its owner and bounds: with
/// the access tree, where the pointer-only ones lie, which have no node to read a place from.
#[cfg(feature = "suite")]
pub(crate) fn press_parts(ctx: &Context) -> Vec<(Id, craft_behavior::PartRef, egui::Rect)> {
let viewport = pass::current_viewport(ctx);
PerViewport::<Shapes>::with(ctx, viewport, |record| {
record
.last
.values()
.flat_map(|roots| roots.values())
.flat_map(|root| root.shapes.iter())
.filter(|shape| shape.sense.intersects(craft_behavior::Sense::CLICK | craft_behavior::Sense::DRAG))
.filter_map(|shape| Some((shape.owner, shape.part?, shape.shape.bounds())))
.collect()
})
}
/// The roots and egui widgets the root viewport's latest pass registered: what bypass detection counts as made by
/// components.
#[cfg(feature = "testing")]
@@ -1,27 +1,38 @@
//! The point at which the suite presses a collection row to give it the lead or pick it: a point of the row's own
//! area (17.5). A row that holds child components (a switch, a select), or that the collection draws controls over (a
//! grid's filter buttons in its header cells), is pressed where none of them is, so the press reaches the row.
//! grid's filter buttons in its header cells, its pointer-only column edges), is pressed where none of them is, so the
//! press reaches the row.
use super::nodes::subtree;
use crate::runtime::egui::access::Declared;
use crate::runtime::access::sub_node_id;
use crate::runtime::egui::access::{Declared, NodeKey};
use crate::testing::fixture::{Fixture, Target};
use egui::{Pos2, Rect};
/// The point of `row` to press: its centre when no focusable or clickable node of its collection (the row's parent:
/// the row's own children and the controls the collection shows beside or over its rows) covers it, else the middle of
/// the widest stretch of the row's centre line that none covers, and the centre when they cover the whole line. Nodes
/// outside the collection, such as the field a popup list opens over, lie under it and are not counted.
/// the row's own children and the controls the collection shows beside or over its rows) and no pointer-only part of
/// the collection, its children or its ancestors (a press part with no node, such as a grid's column edge) covers it,
/// else the middle of the widest stretch of the row's centre line that none covers, and the centre when they cover the
/// whole line. Nodes outside the collection, such as the field a popup list opens over, lie under it and are not
/// counted.
pub(super) fn point(fixture: &Fixture, row: &Target) -> Pos2 {
let tree = fixture.tree();
let centre = row.rect.center();
let collection = tree.parent_of_key(row.node).unwrap_or(row.node);
let mut covered: Vec<Rect> = subtree(tree, collection)
.into_iter()
let inside = subtree(tree, collection);
let nodes = inside
.iter()
.copied()
.filter(|node| *node != collection && *node != row.node)
.filter(|node| tree.declares_key(*node, Declared::Focus) || tree.declares_key(*node, Declared::Click))
.filter_map(|node| tree.bounds_of(node))
.filter(|bounds| bounds.min.y <= centre.y && centre.y <= bounds.max.y)
.collect();
.filter_map(|node| tree.bounds_of(node));
let owners: Vec<NodeKey> =
inside.iter().copied().chain(std::iter::successors(tree.parent_of_key(collection), |node| tree.parent_of_key(*node))).collect();
let pointer_only = crate::runtime::pointer::press_parts(fixture.ctx())
.into_iter()
.filter(|(owner, part, _)| owners.contains(&NodeKey::of(*owner)) && tree.bounds_of(NodeKey::of(sub_node_id(*owner, *part))).is_none())
.map(|(_, _, bounds)| bounds);
let mut covered: Vec<Rect> = nodes.chain(pointer_only).filter(|bounds| bounds.min.y <= centre.y && centre.y <= bounds.max.y).collect();
if !covered.iter().any(|bounds| bounds.contains(centre)) {
return centre;
}