28 lines
710 B
Rust
28 lines
710 B
Rust
use crate::prelude::*;
|
|
|
|
pub struct Sized {
|
|
pub inner: WidgetId,
|
|
pub x: Option<Len>,
|
|
pub y: Option<Len>,
|
|
}
|
|
|
|
impl Widget for Sized {
|
|
fn draw(&mut self, painter: &mut Painter) {
|
|
painter.widget(&self.inner);
|
|
}
|
|
|
|
fn desired_size(&mut self, ctx: &mut SizeCtx) -> Size {
|
|
let rel = ctx.size.rel;
|
|
if let Some(x) = self.x {
|
|
ctx.size.axis_mut(Axis::X).set(x.apply_rest(rel.x));
|
|
}
|
|
if let Some(y) = self.y {
|
|
ctx.size.axis_mut(Axis::Y).set(y.apply_rest(rel.y));
|
|
}
|
|
Size {
|
|
x: self.x.unwrap_or_else(|| ctx.size(&self.inner).x),
|
|
y: self.y.unwrap_or_else(|| ctx.size(&self.inner).y),
|
|
}
|
|
}
|
|
}
|