Coalesce resize layout diagnostics
This commit is contained in:
1 parent
480f0bc99f
commit
82fa6c1123
7 files changed
+316
-28
No files matched your search
+31
-1
@@ -18,6 +18,33 @@ use iris::random::{Edits, Lens, Rng, SpanEdit, Tree, grow};
|
||||
|
||||
const DEPTH: usize = 4;
|
||||
const SEEDS: [u64; 6] = [1, 2, 3, 5, 8, 13];
|
||||
const REGION_ULPS: u32 = 4;
|
||||
|
||||
fn ordered_bits(value: f32) -> u32 {
|
||||
const SIGN: u32 = 1 << 31;
|
||||
let bits = value.to_bits();
|
||||
match bits & SIGN {
|
||||
0 => bits | SIGN,
|
||||
_ => !bits,
|
||||
}
|
||||
}
|
||||
|
||||
fn same_coordinate(got: f32, want: f32) -> bool {
|
||||
got == want || ordered_bits(got).abs_diff(ordered_bits(want)) <= REGION_ULPS
|
||||
}
|
||||
|
||||
fn same_region(got: Option<PixelRegion>, want: Option<PixelRegion>) -> bool {
|
||||
match (got, want) {
|
||||
(Some(got), Some(want)) => {
|
||||
same_coordinate(got.top_left.x, want.top_left.x)
|
||||
&& same_coordinate(got.top_left.y, want.top_left.y)
|
||||
&& same_coordinate(got.bot_right.x, want.bot_right.x)
|
||||
&& same_coordinate(got.bot_right.y, want.bot_right.y)
|
||||
}
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn plant(h: &mut Harness, seed: u64, edits: &Edits) -> Tree {
|
||||
let (root, tree) = grow(&mut h.rsc, seed, DEPTH, edits);
|
||||
@@ -138,7 +165,10 @@ fn assert_same(seed: u64, what: &str, warm: (&Harness, &Tree), cold: (&Harness,
|
||||
for (i, (&w, &c)) in wt.ids.iter().zip(&ct.ids).enumerate() {
|
||||
let (got, want) = (wh.region(&w), ch.region(&c));
|
||||
drawn += usize::from(got.is_some());
|
||||
if got == want {
|
||||
// Equivalent composition orders can differ by a few f32 ULPs. Bound
|
||||
// that representation drift directly, while whether a widget drew
|
||||
// remains exact.
|
||||
if same_region(got, want) {
|
||||
continue;
|
||||
}
|
||||
wrong += 1;
|
||||
|
||||
@@ -21,6 +21,53 @@ use std::time::Instant;
|
||||
|
||||
const OUTPUT: (f32, f32) = (1920.0, 1200.0);
|
||||
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
#[test]
|
||||
fn a_selected_widget_retains_its_layout_events() {
|
||||
use iris::core::layout_diagnostics::{self as diagnostics, TraceEvent};
|
||||
|
||||
diagnostics::clear_traced_widgets();
|
||||
let _ = diagnostics::take();
|
||||
let mut harness = Harness::new((400, 200));
|
||||
let leaf = rect(Color::RED).add(&mut harness.rsc);
|
||||
let other = rect(Color::BLUE).add(&mut harness.rsc);
|
||||
let root = (leaf, other).span(Dir::RIGHT).add(&mut harness.rsc);
|
||||
harness.set_root(root);
|
||||
diagnostics::trace_widget(leaf.id());
|
||||
let _ = diagnostics::take();
|
||||
|
||||
let _ = harness.rsc.widgets_mut().get_dyn_mut(root.id());
|
||||
let _ = harness.rsc.widgets_mut().get_dyn_mut(leaf.id());
|
||||
harness.frame();
|
||||
|
||||
let report = diagnostics::take();
|
||||
assert!(
|
||||
report
|
||||
.traces()
|
||||
.iter()
|
||||
.any(|event| matches!(event, TraceEvent::Placed { id, .. } if *id == leaf.id()))
|
||||
);
|
||||
assert!(
|
||||
report
|
||||
.traces()
|
||||
.iter()
|
||||
.any(|event| matches!(event, TraceEvent::DrawRequest { id, .. } if *id == leaf.id()))
|
||||
);
|
||||
assert!(
|
||||
report
|
||||
.traces()
|
||||
.iter()
|
||||
.any(|event| matches!(event, TraceEvent::SizeRead { id, .. } if *id == leaf.id()))
|
||||
);
|
||||
assert!(
|
||||
report
|
||||
.traces()
|
||||
.iter()
|
||||
.any(|event| matches!(event, TraceEvent::SizeReported { id, .. } if *id == leaf.id()))
|
||||
);
|
||||
diagnostics::clear_traced_widgets();
|
||||
}
|
||||
|
||||
fn env<T: std::str::FromStr>(name: &str, fallback: T) -> T {
|
||||
std::env::var(name)
|
||||
.ok()
|
||||
|
||||
@@ -227,6 +227,24 @@ fn a_resize_redraws_what_read_the_output() {
|
||||
assert_eq!(draws.get(), settled + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reporting_the_same_output_size_does_not_start_a_resize() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let draws = Rc::new(Cell::new(0));
|
||||
let leaf = ReadsOutput {
|
||||
draws: draws.clone(),
|
||||
}
|
||||
.add(&mut h.rsc);
|
||||
h.set_root(leaf);
|
||||
let settled = draws.get();
|
||||
|
||||
h.resize((400, 200));
|
||||
|
||||
assert!(!h.needs_redraw());
|
||||
h.frame();
|
||||
assert_eq!(draws.get(), settled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn narrowing_the_output_reflows_text_and_relays_out_around_it() {
|
||||
let mut h = Harness::new((600, 400));
|
||||
|
||||
Reference in new issue
Block a user