36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
use crate::prelude::*;
|
|
|
|
pub struct Aligned {
|
|
pub inner: WidgetHandle,
|
|
pub align: Align,
|
|
}
|
|
|
|
impl Widget for Aligned {
|
|
fn draw(&mut self, painter: &mut Painter) {
|
|
let region = match self.align.tuple() {
|
|
(Some(x), Some(y)) => painter
|
|
.size(&self.inner)
|
|
.to_uivec2()
|
|
.align(RegionAlign { x, y }),
|
|
(Some(x), None) => {
|
|
let x = painter.size_ctx().width(&self.inner).apply_rest().align(x);
|
|
UiRegion::new(x, UiSpan::FULL)
|
|
}
|
|
(None, Some(y)) => {
|
|
let y = painter.size_ctx().height(&self.inner).apply_rest().align(y);
|
|
UiRegion::new(UiSpan::FULL, y)
|
|
}
|
|
(None, None) => UiRegion::FULL,
|
|
};
|
|
painter.widget_within(&self.inner, region);
|
|
}
|
|
|
|
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
|
|
ctx.width(&self.inner)
|
|
}
|
|
|
|
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
|
|
ctx.height(&self.inner)
|
|
}
|
|
}
|