use crate::prelude::*; use std::marker::Unsize; /// One widget in a box of its own, doing as little as possible on the way: /// it draws its child in the whole of its box and reports back what the child /// said. It exists because a length and an alignment are properties of one /// widget, so a widget cannot both be 100 wide and take two shares of a row /// -- the two lengths need two widgets, and this is the smaller one. /// /// Its child is optional so it can also be the swappable slot a tab bar /// needs, which is what it was written for. pub struct Wrapper { pub inner: Option, } impl Widget for Wrapper { fn draw(&mut self, painter: &mut Painter) -> Size { match &self.inner { Some(id) => painter.widget(id).size(), None => Size::default(), } } } impl Wrapper { pub fn new() -> Self { Self::default() } pub fn empty() -> Self { Self { inner: Default::default(), } } pub fn set>(&mut self, to: StrongWidget) { self.inner = Some(to) } pub fn replace>( &mut self, to: StrongWidget, ) -> Option { self.inner.replace(to) } } impl Default for Wrapper { fn default() -> Self { Self::empty() } }