Make alignment a widget property
This commit is contained in:
1 parent
8220a78d4a
commit
d3b0ebf90c
21 files changed
+823
-300
No files matched your search
+29
-5
@@ -74,17 +74,39 @@ fn an_empty_widget_takes_a_share_of_a_span() {
|
||||
#[test]
|
||||
fn a_child_drawn_twice_moves_once() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
// `Aligned` draws its child twice; listing it twice would move it twice.
|
||||
// The span measures a child and then places it; listing it twice would
|
||||
// move it twice. The span's own fixed total is shorter than the window,
|
||||
// so the span is centred in it and everything under it carries that.
|
||||
let inner = rect(Color::BLUE).add(&mut h.rsc);
|
||||
let centered = inner.center().width(200).add(&mut h.rsc);
|
||||
let left = rect(Color::RED).width(100).add(&mut h.rsc);
|
||||
h.set_root((left, centered).span(Dir::RIGHT));
|
||||
assert_corners!(h, inner, (100, 0), (300, 200));
|
||||
assert_corners!(h, inner, (150, 0), (350, 200));
|
||||
|
||||
h.set_len(left, Axis::X, 150);
|
||||
h.frame();
|
||||
|
||||
assert_corners!(h, inner, (150, 0), (350, 200));
|
||||
assert_corners!(h, inner, (175, 0), (375, 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alignment_accepts_an_arbitrary_fraction_and_changes_at_runtime() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let fixed = rect(Color::BLUE).sized((100, 100)).add(&mut h.rsc);
|
||||
h.rsc
|
||||
.widgets_mut()
|
||||
.set_alignment(fixed, Axis::X, AxisAlign::new(0.25));
|
||||
h.rsc
|
||||
.widgets_mut()
|
||||
.set_alignment(fixed, Axis::Y, AxisAlign::NEG);
|
||||
h.set_root(fixed);
|
||||
assert_corners!(h, fixed, (75, 0), (175, 100));
|
||||
|
||||
h.rsc
|
||||
.widgets_mut()
|
||||
.set_alignment(fixed, Axis::X, AxisAlign::new(0.75));
|
||||
h.frame();
|
||||
assert_corners!(h, fixed, (225, 0), (325, 100));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -143,15 +165,17 @@ fn a_moved_subtree_takes_its_children_with_it() {
|
||||
let first = rect(Color::RED).height(40).add(&mut h.rsc);
|
||||
let inner = rect(Color::BLUE).add(&mut h.rsc);
|
||||
let row = inner.pad(10).height(40).region_node().add(&mut h.rsc);
|
||||
// 80 of fixed rows in a 400 window, so the span takes 80 and sits in the
|
||||
// middle of what it was given.
|
||||
h.set_root((first, row).span(Dir::DOWN));
|
||||
assert_corners!(h, inner, (10, 50), (390, 70));
|
||||
assert_corners!(h, inner, (10, 210), (390, 230));
|
||||
|
||||
h.set_len(first, Axis::Y, 80);
|
||||
h.frame();
|
||||
|
||||
// The row opted into one movable region, so its descendants follow one
|
||||
// entry rather than having their primitive regions rewritten.
|
||||
assert_corners!(h, inner, (10, 90), (390, 110));
|
||||
assert_corners!(h, inner, (10, 230), (390, 250));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user