use super::input;
use crate::keymap::{CenterTab, InspectorTab};
use crate::paint_probe::Painted;
pub(super) fn visible(output: &egui::FullOutput) -> Vec<Painted> {
crate::paint_probe::seen_of(output)
.into_iter()
.map(|seen| (seen.text, seen.shown))
.collect()
}
pub(super) fn overlaps(painted: &[Painted]) -> Vec<String> {
let mut found = Vec::new();
for (index, (first, here)) in painted.iter().enumerate() {
for (second, there) in painted.iter().skip(index + 1) {
let shared = here.intersect(*there);
if shared.width() > 1.0 && shared.height() > 1.0 {
found.push(format!("{first:?} {here:?} over {second:?} {there:?}"));
}
}
}
found
}
fn collisions(w: f32, h: f32, trail: bool, tab: CenterTab) -> Vec<String> {
overlaps(&visible(&super::window(
w,
h,
trail,
tab,
InspectorTab::Transcript,
)))
}
#[test]
fn no_two_runs_of_text_share_pixels_at_any_window_size() {
let mut report = Vec::new();
for (w, h) in super::SIZES {
for trail in [false, true] {
for tab in [CenterTab::Conversation, CenterTab::Config] {
let found = collisions(w, h, trail, tab);
if !found.is_empty() {
report.push(format!(
"{} runs share pixels at {w}x{h} (trail {trail}, {tab:?}):\n{}",
found.len(),
found.join("\n")
));
}
}
}
}
assert!(report.is_empty(), "{}", report.join("\n\n"));
}
#[test]
fn the_walk_reports_a_frame_that_really_does_stack_two_runs() {
let ctx = egui::Context::default();
let out = ctx.run(input(), |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
let seat =
egui::Rect::from_min_size(egui::Pos2::new(40.0, 40.0), egui::vec2(200.0, 20.0));
for text in ["under", "over"] {
ui.put(seat, egui::Label::new(text));
}
});
});
let found = overlaps(&visible(&out));
assert!(
found
.iter()
.any(|pair| pair.contains("under") && pair.contains("over")),
"two labels on one rect must be reported: {found:?}"
);
}