Skip to main content

bexa_ui_core/widgets/
flex.rs

1use taffy::prelude::*;
2
3use crate::framework::Widget;
4
5pub struct Flex {
6    style: Style,
7}
8
9impl Flex {
10    pub fn row(gap: f32) -> Self {
11        Self {
12            style: Style {
13                display: Display::Flex,
14                flex_direction: FlexDirection::Row,
15                flex_grow: 1.0,
16                align_items: Some(AlignItems::Stretch),
17                gap: Size {
18                    width: LengthPercentage::Length(gap),
19                    height: LengthPercentage::Length(0.0),
20                },
21                ..Default::default()
22            },
23        }
24    }
25
26    pub fn column(gap: f32, padding: f32) -> Self {
27        Self {
28            style: Style {
29                display: Display::Flex,
30                flex_direction: FlexDirection::Column,
31                flex_grow: 1.0,
32                align_items: Some(AlignItems::Stretch),
33                justify_content: Some(JustifyContent::SpaceBetween),
34                gap: Size {
35                    width: LengthPercentage::Length(0.0),
36                    height: LengthPercentage::Length(gap),
37                },
38                padding: Rect {
39                    left: LengthPercentage::Length(padding),
40                    right: LengthPercentage::Length(padding),
41                    top: LengthPercentage::Length(padding),
42                    bottom: LengthPercentage::Length(padding),
43                },
44                ..Default::default()
45            },
46        }
47    }
48}
49
50impl Widget for Flex {
51    fn style(&self) -> Style {
52        self.style.clone()
53    }
54}