use crate::prelude::*; pub struct Sized { pub inner: WidgetHandle, pub x: Option, pub y: Option, } impl Sized { fn apply_to_outer(&self, ctx: &mut SizeCtx) { if let Some(x) = self.x { ctx.outer.x.select_len(x.apply_rest()); } if let Some(y) = self.y { ctx.outer.y.select_len(y.apply_rest()); } } } impl Widget for Sized { fn draw(&mut self, painter: &mut Painter) { painter.widget(&self.inner); } fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len { self.apply_to_outer(ctx); self.x.unwrap_or_else(|| ctx.width(&self.inner)) } fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len { self.apply_to_outer(ctx); self.y.unwrap_or_else(|| ctx.height(&self.inner)) } }