kobalt_core/layout.rs
1//! Layout primitives and alignment enums
2
3/// Main axis alignment (vertical for Column, horizontal for Row)
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum MainAxisAlignment {
6 /// Place children at the start of the axis
7 Start,
8 /// Place children at the end of the axis
9 End,
10 /// Place children at the center of the axis
11 Center,
12 /// Place children with equal spacing between them
13 SpaceBetween,
14 /// Place children with equal spacing around them
15 SpaceAround,
16 /// Place children with equal spacing evenly distributed
17 SpaceEvenly,
18}
19
20impl Default for MainAxisAlignment {
21 fn default() -> Self {
22 Self::Start
23 }
24}
25
26/// Cross axis alignment (horizontal for Column, vertical for Row)
27#[derive(Debug, Clone, Copy, PartialEq)]
28pub enum CrossAxisAlignment {
29 /// Align children to the start of the cross axis
30 Start,
31 /// Align children to the end of the cross axis
32 End,
33 /// Align children to the center of the cross axis
34 Center,
35 /// Stretch children to fill the cross axis
36 Stretch,
37}
38
39impl Default for CrossAxisAlignment {
40 fn default() -> Self {
41 Self::Start
42 }
43}
44
45/// Edge insets for padding/margin
46#[derive(Debug, Clone, Copy, PartialEq)]
47pub struct EdgeInsets {
48 pub top: f32,
49 pub right: f32,
50 pub bottom: f32,
51 pub left: f32,
52}
53
54impl EdgeInsets {
55 /// Creates edge insets with all sides equal
56 pub fn all(value: f32) -> Self {
57 Self {
58 top: value,
59 right: value,
60 bottom: value,
61 left: value,
62 }
63 }
64
65 /// Creates edge insets with symmetric values
66 pub fn symmetric(vertical: f32, horizontal: f32) -> Self {
67 Self {
68 top: vertical,
69 right: horizontal,
70 bottom: vertical,
71 left: horizontal,
72 }
73 }
74
75 /// Creates edge insets with individual values
76 pub fn only(top: f32, right: f32, bottom: f32, left: f32) -> Self {
77 Self {
78 top,
79 right,
80 bottom,
81 left,
82 }
83 }
84
85 /// Creates zero edge insets
86 pub fn zero() -> Self {
87 Self {
88 top: 0.0,
89 right: 0.0,
90 bottom: 0.0,
91 left: 0.0,
92 }
93 }
94
95 /// Returns the total horizontal insets
96 pub fn horizontal(&self) -> f32 {
97 self.left + self.right
98 }
99
100 /// Returns the total vertical insets
101 pub fn vertical(&self) -> f32 {
102 self.top + self.bottom
103 }
104}
105
106impl Default for EdgeInsets {
107 fn default() -> Self {
108 Self::zero()
109 }
110}