Say the environment once, and stop a hint read going uncounted
The eleventh sweep, over the built-in bounds work in2ac0843. `Painter::size_hint` refused to answer for a bounded widget by returning above the diagnostics, so that read was neither a hint hit nor a miss and `hint_read` recorded nothing. It is a miss now, with the reason on it. The two `for axis in Axis::BOTH` loops that `draw_widget` grew, both writing `own_holds`, are one loop, and the comment about combining the ask's holds no longer sits between a comment and the code it describes. `Declared::from_axes` lost its only caller with `Widgets::declared_lens`; `Bounds::from_axes` and `SizeRule::declared` never had one. The scenario shrinker printed a rule with derived `Debug`, which is 130 characters an axis in a line that carries every ancestor, in the one function whose job is output a tree can be rebuilt from. It prints its parts again. `bounds_cost` invented three environment-reading spellings where four copies of one `env` helper already existed; there is now one, in `tests/rig`, and the four copies are gone. It also verified 128 regions inside its measured loop, which the other rigs deliberately do before theirs; that measured 0.65% of the total, and none of it is layout. The 250-window row with a 300 cap was built by two tests, and the one that still explained itself tested less; they are one. The half of `a_cap_attribute_narrows_the_widgets_box` that the wrapper's removal left without its deciding assertion is the allocator's path instead, which nothing at the root covered. Format, workspace clippy under -D warnings with and without layout-diagnostics, 206 ordinary and 210 diagnostic tests, 400 depth-5 trees warm against cold in 64.19s, and the cold dump byte-identical to2ac0843across all 34,986 boxes.
This commit is contained in:
1 parent
2ac0843cb2
commit
ea1f836bf9
16 files changed
+178
-146
No files matched your search
+41
-32
@@ -1005,46 +1005,72 @@ fn a_region_node_root_is_a_region_node() {
|
||||
assert_eq!(h.region(&probe).unwrap().size().x, Px::from_int(900));
|
||||
}
|
||||
|
||||
/// A bound holds the length a widget reports as well as narrowing the box it
|
||||
/// is offered, and the two are not the same question. Here two 200-wide rects
|
||||
/// fill a row in a 250 window, so a cap of 300 leaves the box alone and only
|
||||
/// cuts what the row reports -- which the window then centres, past both its
|
||||
/// edges -- while a floor raises the report and the rects stay where the 250
|
||||
/// box put them.
|
||||
#[test]
|
||||
fn a_bound_holds_what_a_widget_answers() {
|
||||
let row = |rule: SizeRule| {
|
||||
let bounded_row = |rule: SizeRule| {
|
||||
let mut h = Harness::new((250, 200));
|
||||
let left = rect(Color::RED).width(200).add(&mut h.rsc);
|
||||
let right = rect(Color::BLUE).width(200).add(&mut h.rsc);
|
||||
let row = (left, right).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
h.rsc.widgets_mut().set_size_rule(row, Axis::X, rule);
|
||||
h.set_root(row);
|
||||
(
|
||||
h.region(&row).unwrap().size().x,
|
||||
h.region(&left).unwrap().size().x,
|
||||
)
|
||||
(h, row, left)
|
||||
};
|
||||
let (capped, left) = row(SizeRule::max(Len::px(300.0)));
|
||||
assert_eq!(capped, Px::from_int(300), "the cap, not the 400 drawn");
|
||||
assert_eq!(left, Px::from_int(200), "the box the children were given");
|
||||
let (h, row, left) = bounded_row(SizeRule::max(Len::px(300.0)));
|
||||
assert_eq!(
|
||||
h.region(&row).unwrap().size().x,
|
||||
Px::from_int(300),
|
||||
"the cap, not the 400 drawn"
|
||||
);
|
||||
assert_eq!(
|
||||
h.region(&left).unwrap().size().x,
|
||||
Px::from_int(200),
|
||||
"the box the children were given"
|
||||
);
|
||||
assert_corners!(h, row, (-25, 0), (275, 200));
|
||||
|
||||
let (floored, _) = row(SizeRule::min(Len::px(600.0)));
|
||||
assert_eq!(floored, Px::from_int(600), "the floor, not the 400 drawn");
|
||||
let (h, row, _) = bounded_row(SizeRule::min(Len::px(600.0)));
|
||||
assert_eq!(
|
||||
h.region(&row).unwrap().size().x,
|
||||
Px::from_int(600),
|
||||
"the floor, not the 400 drawn"
|
||||
);
|
||||
|
||||
let (free, _) = row(SizeRule::FREE);
|
||||
assert_eq!(free, Px::from_int(400), "what it drew");
|
||||
let (h, row, _) = bounded_row(SizeRule::FREE);
|
||||
assert_eq!(
|
||||
h.region(&row).unwrap().size().x,
|
||||
Px::from_int(400),
|
||||
"what it drew"
|
||||
);
|
||||
}
|
||||
|
||||
/// A cap narrows the box the widget is asked in, whether a declaration of its
|
||||
/// own decides that box or the allocator divides a share into it. The cap is
|
||||
/// an attribute of the widget rather than something wrapped around it, which
|
||||
/// is what the id assertions say.
|
||||
#[test]
|
||||
fn a_cap_attribute_narrows_the_widgets_box() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
// A fraction of its box, so it says what box it was asked in.
|
||||
let fills = rect(Color::RED).width(rel(1.0)).add(&mut h.rsc);
|
||||
let capped = fills.max_width(300).add(&mut h.rsc);
|
||||
assert_eq!(fills.id(), capped.id());
|
||||
h.set_root(capped);
|
||||
|
||||
assert_eq!(h.region(&fills).unwrap().size().x, Px::from_int(300));
|
||||
|
||||
// A share with nothing beside it: the cap is composed into the request
|
||||
// and the allocator answers with it rather than the whole 400.
|
||||
let mut h = Harness::new((400, 200));
|
||||
let share = rect(Color::RED).add(&mut h.rsc);
|
||||
let share = rect(Color::RED).width(leftover(1)).add(&mut h.rsc);
|
||||
let capped = share.max_width(300).add(&mut h.rsc);
|
||||
assert_eq!(share.id(), capped.id());
|
||||
h.set_root(capped);
|
||||
|
||||
assert_eq!(h.region(&share).unwrap().size().x, Px::from_int(300));
|
||||
}
|
||||
|
||||
@@ -1082,23 +1108,6 @@ fn a_cap_is_a_fraction_of_the_box_it_was_given() {
|
||||
assert_eq!(h.region(&probe).unwrap().size().x, Px::from_int(150));
|
||||
}
|
||||
|
||||
/// A cap is a promise about the length as well as the box: a widget whose
|
||||
/// content is longer than the box it was given reports what it drew, and the
|
||||
/// cap holds that down even though it never decided the box.
|
||||
#[test]
|
||||
fn a_cap_holds_an_answer_that_overflowed_its_box() {
|
||||
let mut h = Harness::new((250, 200));
|
||||
let left = rect(Color::RED).width(200).add(&mut h.rsc);
|
||||
let right = rect(Color::BLUE).width(200).add(&mut h.rsc);
|
||||
let row = (left, right).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
h.rsc.widgets_mut().set_max_len(row, Axis::X, 300.into());
|
||||
h.set_root(row);
|
||||
|
||||
// The box is the 250 window, which the cap of 300 leaves alone, and the
|
||||
// row draws 400 of it. Its answer is the cap, and the window centres it.
|
||||
assert_corners!(h, row, (-25, 0), (275, 200));
|
||||
}
|
||||
|
||||
struct Offered {
|
||||
seen: Rc<Cell<PxVec2>>,
|
||||
answer: Size,
|
||||
|
||||
Reference in new issue
Block a user