Constrain offered boxes with independent widget size bounds
This commit is contained in:
1 parent
4cb6f6882a
commit
2ac0843cb2
18 files changed
+554
-379
No files matched your search
@@ -0,0 +1,60 @@
|
||||
//! CPU comparison of bounds attributes and the former wrapper, using the
|
||||
//! same builder calls and geometry. Run the release executable under perf;
|
||||
//! process totals include the cold frame. MODE=plain|exact|cap, REDRAW=0|1.
|
||||
use iris::{harness::Harness, prelude::*};
|
||||
|
||||
#[test]
|
||||
#[ignore = "instruction-count measurement"]
|
||||
fn bounds_cost() {
|
||||
let mode = std::env::var("MODE").unwrap_or_else(|_| "cap".into());
|
||||
let redraw = std::env::var("REDRAW").is_ok_and(|value| value == "1");
|
||||
let frames = std::env::var("FRAMES")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(2000);
|
||||
let mut h = Harness::new((300, 512));
|
||||
let mut column = Span::empty(Dir::DOWN);
|
||||
let mut leaves = Vec::new();
|
||||
for _ in 0..128 {
|
||||
let first = match mode.as_str() {
|
||||
"plain" => rect(Color::RED).add_strong(&mut h.rsc).any(),
|
||||
"exact" => rect(Color::RED).width(40).add_strong(&mut h.rsc).any(),
|
||||
"cap" => rect(Color::RED).max_width(80).add_strong(&mut h.rsc).any(),
|
||||
_ => panic!("unknown MODE {mode}"),
|
||||
};
|
||||
leaves.push(first.id());
|
||||
let second = rect(Color::BLUE).add_strong(&mut h.rsc);
|
||||
let row = Span {
|
||||
children: vec![first, second],
|
||||
dir: Dir::RIGHT,
|
||||
gap: Px::ZERO,
|
||||
};
|
||||
column.push(row.height(4).add_strong(&mut h.rsc));
|
||||
}
|
||||
h.set_root(column);
|
||||
let ids: Vec<_> = h.render.active.keys().copied().collect();
|
||||
println!(
|
||||
"mode={mode}, widgets={}, rule_bytes={}",
|
||||
ids.len(),
|
||||
std::mem::size_of::<SizeRule>()
|
||||
);
|
||||
for frame in 0..frames {
|
||||
if redraw {
|
||||
for &id in &ids {
|
||||
h.rsc.widgets_mut().mark_for_redraw(id);
|
||||
}
|
||||
}
|
||||
let width = if frame % 2 == 0 { 100 } else { 300 };
|
||||
h.resize((width, 512));
|
||||
h.frame();
|
||||
let expected = match mode.as_str() {
|
||||
"plain" => width / 2,
|
||||
"exact" => 40,
|
||||
"cap" => (width / 2).min(80),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
for id in &leaves {
|
||||
assert_eq!(h.region(id).unwrap().size().x, Px::from_int(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user