use rosace_core::types::Size;
use super::{Widget, LayoutCtx, PaintCtx};
pub struct Spacer {
pub width: f32,
pub height: f32,
}
impl Spacer {
pub fn new(size: f32) -> Self { Self { width: size, height: size } }
pub fn w(width: f32) -> Self { Self { width, height: 0.0 } }
pub fn h(height: f32) -> Self { Self { width: 0.0, height } }
pub fn gap(width: f32, height: f32) -> Self { Self { width, height } }
}
impl Widget for Spacer {
fn layout(&self, _ctx: &LayoutCtx) -> Size {
Size { width: self.width, height: self.height }
}
fn paint(&self, _ctx: &mut PaintCtx) {}
}
pub struct Expanded {
pub factor: f32,
pub child: Option<Box<dyn Widget>>,
}
impl Expanded {
pub fn empty() -> Self { Self { factor: 1.0, child: None } }
pub fn new(child: impl Widget + 'static) -> Self {
Self { factor: 1.0, child: Some(Box::new(child)) }
}
pub fn with_factor(mut self, f: f32) -> Self { self.factor = f; self }
}
impl Widget for Expanded {
fn children(&self) -> super::Children<'_> {
match &self.child {
Some(c) => super::Children::One(&**c),
None => super::Children::None,
}
}
fn flex_factor(&self) -> f32 { self.factor }
}