Honor fixed child alignment inside parent-selected slots
This commit is contained in:
1 parent
2ed5503717
commit
39f7b08c6c
2 files changed
+26
-14
No files matched your search
+5
-14
@@ -712,16 +712,9 @@ pub(crate) fn placed_box(region: UiRegion, lens: UiVec2, align: RegionAlign) ->
|
||||
placed
|
||||
}
|
||||
|
||||
/// A child's own region and where in it its drawing goes, from the box it is
|
||||
/// offered, the lengths its rules declare, and what its parent chose.
|
||||
///
|
||||
/// A rule gives the region its length outright -- that is what makes a rule
|
||||
/// win, and it is why a widget under one never learns of it -- and the region
|
||||
/// then sits where its parent placed it, or where its alignment says if its
|
||||
/// parent left the axis open. With no rule the region is the whole of what
|
||||
/// was offered, since that is the area a fraction under it is a fraction of,
|
||||
/// and what the parent chose is where in it the drawing goes. So the two
|
||||
/// coordinate spaces are the same one wherever a placement survives.
|
||||
/// A declared axis gets a frame of that length, aligned within the parent's
|
||||
/// slot (or the offer). Undeclared axes keep the offered frame and chosen
|
||||
/// placement, so their reported fractions retain that reference.
|
||||
pub(crate) fn ask_box(
|
||||
mut region: UiRegion,
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
@@ -736,10 +729,8 @@ pub(crate) fn ask_box(
|
||||
};
|
||||
let span = region.axis_mut(axis);
|
||||
let len = Len::from_parts(len.rel, len.px);
|
||||
span.start = match chosen {
|
||||
Some(chosen) => chosen.start,
|
||||
None => span.start + (span.len() - len).scale(align.axis(axis).rel()),
|
||||
};
|
||||
let slot = chosen.unwrap_or(*span);
|
||||
span.start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
||||
span.end = span.start + len;
|
||||
}
|
||||
(region, placed)
|
||||
|
||||
@@ -716,3 +716,24 @@ fn a_stack_sized_by_a_child_does_not_take_that_childs_fraction_twice() {
|
||||
assert_corners!(h, half, (0, 0), (200, 200));
|
||||
assert_corners!(h, behind, (0, 0), (200, 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fixed_child_is_centered_in_its_wrappers_share() {
|
||||
let mut h = Harness::new((600, 300));
|
||||
let leaf = rect(Color::RED).sized((100, 100)).center().add(&mut h.rsc);
|
||||
let wrapper = leaf
|
||||
.wrapper()
|
||||
.width(leftover(2))
|
||||
.height(rel(1.0))
|
||||
.add(&mut h.rsc);
|
||||
let other = rect(Color::BLUE).width(200).add(&mut h.rsc);
|
||||
h.set_root((other, wrapper).span(Dir::RIGHT));
|
||||
|
||||
assert_corners!(h, wrapper, (200, 0), (600, 300));
|
||||
assert_corners!(h, leaf, (350, 100), (450, 200));
|
||||
|
||||
h.resize((900, 400));
|
||||
h.frame();
|
||||
assert_corners!(h, wrapper, (200, 0), (900, 400));
|
||||
assert_corners!(h, leaf, (500, 150), (600, 250));
|
||||
}
|
||||
Reference in new issue
Block a user