ui-contract: Fixture::by_label passes over a node that labels another, so a field's control comes before its caption link

This commit is contained in:
bflatastic
2026-11-23 17:11:23 +07:00
parent 80e46cf00e
commit b72fc4200d
2 changed files with 19 additions and 2 deletions
+7 -2
View File
@@ -587,16 +587,21 @@ impl Fixture {
}
/// The node named `label`: the interactive node whose name resolves to it (its own, or the node that labels it
/// through `labelled_by`), else the first node that carries the text.
/// through `labelled_by`) and that labels no other node, so a field's control comes before its caption link;
/// else the first node that carries the text.
pub fn by_label(&self, label: &str) -> Option<Target> {
let tree = &self.tree;
let reported: HashSet<NodeKey> = tree.keys().into_iter().collect();
let labels: HashSet<NodeKey> = reported.iter().flat_map(|key| tree.labelled_by_key(*key)).collect();
let ordered = self.in_tree_order(&reported);
let node = ordered
.iter()
.copied()
.find(|key| {
super::access::name(tree, *key) == Some(label) && tree.role_of(*key) != Some(Role::LABEL) && super::access::is_interactive(tree, *key)
super::access::name(tree, *key) == Some(label)
&& tree.role_of(*key) != Some(Role::LABEL)
&& !labels.contains(key)
&& super::access::is_interactive(tree, *key)
})
.or_else(|| ordered.iter().copied().find(|key| tree.name_of(*key) == Some(label)))?;
self.target(node)
+12
View File
@@ -67,3 +67,15 @@ fn a_link_label_reports_its_click_to_the_host_and_still_scrubs() {
fixture.drag_at(link.label_at(), Vec2::new(DRAG, 0.0));
assert!(link.value.get() > START, "a drag on a link label scrubs: {}", link.value.get());
}
/// `Fixture::by_label` gives the control a link label names, not the link that carries the same name.
#[trial]
fn by_label_gives_the_control_a_link_label_names() {
let row = Row::new();
let shown = row.clone();
let mut fixture = Fixture::new(move |ui| shown.show(ui, "link", SideLabel::new().link(), ROW_A));
fixture.settle();
let dial = row.seen.borrow().id.expect("the dial ran");
let control = fixture.node_of(dial).expect("the dial is in the access tree").node;
assert_eq!(fixture.by_label("Opacity").map(|found| found.node), Some(control), "the label's name finds its control");
}