rosace_widgets/tree/
spacer.rs1use rosace_core::types::Size;
2use super::{Widget, LayoutCtx, PaintCtx};
3
4pub struct Spacer {
6 pub width: f32,
7 pub height: f32,
8}
9
10impl Spacer {
11 pub fn new(size: f32) -> Self { Self { width: size, height: size } }
12 pub fn w(width: f32) -> Self { Self { width, height: 0.0 } }
13 pub fn h(height: f32) -> Self { Self { width: 0.0, height } }
14 pub fn gap(width: f32, height: f32) -> Self { Self { width, height } }
16}
17
18impl Widget for Spacer {
19 fn layout(&self, _ctx: &LayoutCtx) -> Size {
20 Size { width: self.width, height: self.height }
21 }
22 fn paint(&self, _ctx: &mut PaintCtx) {}
23}
24
25pub struct Expanded {
29 pub factor: f32,
30 pub child: Option<Box<dyn Widget>>,
31}
32
33impl Expanded {
34 pub fn empty() -> Self { Self { factor: 1.0, child: None } }
36
37 pub fn new(child: impl Widget + 'static) -> Self {
39 Self { factor: 1.0, child: Some(Box::new(child)) }
40 }
41
42 pub fn with_factor(mut self, f: f32) -> Self { self.factor = f; self }
43}
44
45impl Widget for Expanded {
46 fn children(&self) -> super::Children<'_> {
47 match &self.child {
48 Some(c) => super::Children::One(&**c),
49 None => super::Children::None,
50 }
51 }
52
53 fn flex_factor(&self) -> f32 { self.factor }
57}