use crate::prelude::*; pub struct Aligned { pub inner: StrongWidget, pub align: Align, } 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 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 } /// The aligned box is a fraction of its own, so the child keeps its /// length and stays against the edge it was aligned to. fn on_resize(&self, _: Axis) -> OnResize { OnResize::Scale } }