Retain layout sizes by pixel axis
This commit is contained in:
1 parent
82fa6c1123
commit
b1b3eca1c0
11 files changed
+371
-69
No files matched your search
@@ -7,17 +7,31 @@ pub struct Aligned {
|
||||
|
||||
impl Widget for Aligned {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
// Drawn where it may be too big, then given its aligned box once its
|
||||
// size is known.
|
||||
let size = painter.place(&self.inner, UiRegion::FULL).size();
|
||||
let known = match self.align.tuple() {
|
||||
(Some(_), Some(_)) => painter
|
||||
.known_len(&self.inner, Axis::X, UiRegion::FULL)
|
||||
.zip(painter.known_len(&self.inner, Axis::Y, UiRegion::FULL))
|
||||
.map(|(x, y)| Size { x, y }),
|
||||
(Some(_), None) => painter
|
||||
.known_len(&self.inner, Axis::X, UiRegion::FULL)
|
||||
.map(|x| Size { x, y: Len::REST }),
|
||||
(None, Some(_)) => painter
|
||||
.known_len(&self.inner, Axis::Y, UiRegion::FULL)
|
||||
.map(|y| Size { x: Len::REST, y }),
|
||||
(None, None) => Some(Size::REST),
|
||||
};
|
||||
// Drawn where it may be too big only when the aligned axes are not
|
||||
// already known, then given its aligned box once its size is known.
|
||||
let had_size = known.is_some();
|
||||
let size = known.unwrap_or_else(|| painter.place(&self.inner, UiRegion::FULL).size());
|
||||
let region = match self.align.tuple() {
|
||||
(Some(x), Some(y)) => size.to_uivec2().align(RegionAlign { x, y }),
|
||||
(Some(x), None) => UiRegion::new(size.x.apply_rest().align(x), UiSpan::FULL),
|
||||
(None, Some(y)) => UiRegion::new(UiSpan::FULL, size.y.apply_rest().align(y)),
|
||||
(None, None) => UiRegion::FULL,
|
||||
};
|
||||
painter.place(&self.inner, region);
|
||||
size
|
||||
let placed = painter.place(&self.inner, region).size();
|
||||
if had_size { placed } else { size }
|
||||
}
|
||||
|
||||
/// The aligned box is a fraction of its own, so the child keeps its
|
||||
|
||||
Reference in new issue
Block a user