mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10330 from dotCooCoo/fix/new-document-card-tile-flake
Main: resting-card test picked Home screen cards in random node order
This commit is contained in:
1 file changed
+24
-10
@@ -1127,21 +1127,35 @@ mod tests {
|
||||
open(&mut app);
|
||||
let out = laid_out(&mut app);
|
||||
let nodes = out.platform_output.accesskit_update.as_ref().map(|u| u.nodes.clone()).unwrap_or_default();
|
||||
let card = nodes
|
||||
// The Home screen's own document cards stand behind the dialog, and the update lists nodes in no fixed order:
|
||||
// the card is looked for under the dialog only.
|
||||
let by_id: std::collections::HashMap<_, _> = nodes.iter().map(|(id, n)| (*id, n)).collect();
|
||||
let mut in_dialog = Vec::new();
|
||||
let mut stack: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == egui::accesskit::Role::Dialog).map(|(id, _)| *id).collect();
|
||||
while let Some(id) = stack.pop() {
|
||||
if let Some(node) = by_id.get(&id) {
|
||||
in_dialog.push(*node);
|
||||
stack.extend(node.children().iter().copied());
|
||||
}
|
||||
}
|
||||
let cards: Vec<_> = in_dialog
|
||||
.iter()
|
||||
.find(|(_, n)| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|l| !l.is_empty()) && n.is_selected() == Some(false))
|
||||
.and_then(|(_, n)| n.bounds())
|
||||
.filter(|n| n.role() == egui::accesskit::Role::ListItem && n.label().is_some_and(|l| !l.is_empty()) && n.is_selected() == Some(false))
|
||||
.filter_map(|n| n.bounds())
|
||||
.map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32)))
|
||||
.expect("a preset card that is not selected");
|
||||
.collect();
|
||||
assert!(!cards.is_empty(), "a preset card that is not selected");
|
||||
let shapes = crate::tests_labels::flat_painted_shapes(&out.shapes);
|
||||
let rects: Vec<_> = shapes.iter().filter_map(|shape| if let egui::Shape::Rect(rect) = shape { Some(rect) } else { None }).collect();
|
||||
let veil = |fill: egui::Color32| fill.a() > 0 && fill.a() < scrim.a() && fill.to_opaque() == scrim.to_opaque();
|
||||
assert!(
|
||||
rects.iter().any(|rect| veil(rect.fill) && rect.rect.contains_rect(card.shrink(1.0)) && card.expand(1.0).contains_rect(rect.rect)),
|
||||
"a veil of the scrim {scrim:?} covers the resting card {card:?}: {:?}",
|
||||
rects.iter().filter(|rect| card.expand(1.0).contains_rect(rect.rect)).map(|rect| (rect.rect, rect.fill)).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(rects.iter().any(|rect| rect.fill == egui::Color32::WHITE && card.contains_rect(rect.rect)), "the card's paper is on the tile");
|
||||
for card in cards {
|
||||
assert!(
|
||||
rects.iter().any(|rect| veil(rect.fill) && rect.rect.contains_rect(card.shrink(1.0)) && card.expand(1.0).contains_rect(rect.rect)),
|
||||
"a veil of the scrim {scrim:?} covers the resting card {card:?}: {:?}",
|
||||
rects.iter().filter(|rect| card.expand(1.0).contains_rect(rect.rect)).map(|rect| (rect.rect, rect.fill)).collect::<Vec<_>>()
|
||||
);
|
||||
assert!(rects.iter().any(|rect| rect.fill == egui::Color32::WHITE && card.contains_rect(rect.rect)), "the card's paper is on the tile");
|
||||
}
|
||||
}
|
||||
|
||||
/// Recent shows each entry as it was made: a portrait and a landscape A3 are two documents, and
|
||||
|
||||
Reference in new issue
Block a user