1use nalgebra::Vector2;
2pub use taffy::{
3 AlignContent, AlignItems, AlignSelf, Dimension, Display, FlexDirection, FlexWrap, GridAutoFlow,
4 GridPlacement, JustifyContent, JustifyItems, JustifySelf, Layout, LengthPercentage,
5 LengthPercentageAuto, Line, NodeId, Overflow, Position, Rect, TaffyError, TaffyResult,
6 TaffyTree,
7};
8
9#[derive(Clone, PartialEq, Debug)]
11pub struct LayoutStyle {
12 pub display: Display,
14
15 pub overflow: (Overflow, Overflow),
17
18 pub scrollbar_width: f32,
20
21 pub position: Position,
23
24 pub inset: Rect<LengthPercentageAuto>,
26
27 pub size: Vector2<Dimension>,
29
30 pub min_size: Vector2<Dimension>,
32
33 pub max_size: Vector2<Dimension>,
35
36 pub aspect_ratio: Option<f32>,
40
41 pub margin: Rect<LengthPercentageAuto>,
43
44 pub padding: Rect<LengthPercentage>,
46
47 pub border: Rect<LengthPercentage>,
49
50 pub align_items: Option<AlignItems>,
52
53 pub align_self: Option<AlignSelf>,
56
57 pub justify_items: Option<AlignItems>,
59
60 pub justify_self: Option<AlignSelf>,
63
64 pub align_content: Option<AlignContent>,
66
67 pub justify_content: Option<JustifyContent>,
69
70 pub gap: Vector2<LengthPercentage>,
72
73 pub flex_direction: FlexDirection,
75
76 pub flex_wrap: FlexWrap,
78
79 pub flex_basis: Dimension,
81
82 pub flex_grow: f32,
86
87 pub flex_shrink: f32,
91
92 pub grid_auto_flow: GridAutoFlow,
94
95 pub grid_row: Line<GridPlacement>,
97
98 pub grid_column: Line<GridPlacement>,
100}
101
102impl Default for LayoutStyle {
103 fn default() -> Self {
104 LayoutStyle {
105 display: Display::default(),
106 overflow: (Overflow::Visible, Overflow::Visible),
107 scrollbar_width: 0.0,
108 position: Position::Relative,
109 inset: Rect::auto(),
110 margin: Rect::zero(),
111 padding: Rect::zero(),
112 border: Rect::zero(),
113 size: Vector2::new(Dimension::auto(), Dimension::auto()),
114 min_size: Vector2::new(Dimension::auto(), Dimension::auto()),
115 max_size: Vector2::new(Dimension::auto(), Dimension::auto()),
116 aspect_ratio: None,
117 gap: Vector2::new(LengthPercentage::length(0.0), LengthPercentage::length(0.0)),
118 align_items: None,
119 align_self: None,
120 justify_items: None,
121 justify_self: None,
122 align_content: None,
123 justify_content: None,
124 flex_direction: FlexDirection::Row,
125 flex_wrap: FlexWrap::NoWrap,
126 flex_grow: 0.0,
127 flex_shrink: 1.0,
128 flex_basis: Dimension::auto(),
129 grid_auto_flow: GridAutoFlow::Row,
130 grid_row: Line {
131 start: GridPlacement::Auto,
132 end: GridPlacement::Auto,
133 },
134 grid_column: Line {
135 start: GridPlacement::Auto,
136 end: GridPlacement::Auto,
137 },
138 }
139 }
140}
141
142impl From<LayoutStyle> for taffy::Style {
143 fn from(value: LayoutStyle) -> Self {
144 taffy::Style {
145 display: value.display,
146 overflow: taffy::Point {
147 x: value.overflow.0,
148 y: value.overflow.1,
149 },
150 scrollbar_width: value.scrollbar_width,
151 position: value.position,
152 inset: value.inset,
153 margin: value.margin,
154 padding: value.padding,
155 border: value.border,
156 size: taffy::Size {
157 width: value.size.x,
158 height: value.size.y,
159 },
160 min_size: taffy::Size {
161 width: value.min_size.x,
162 height: value.min_size.y,
163 },
164 max_size: taffy::Size {
165 width: value.max_size.x,
166 height: value.max_size.y,
167 },
168 aspect_ratio: value.aspect_ratio,
169 gap: taffy::Size {
170 width: value.gap.x,
171 height: value.gap.y,
172 },
173 align_items: value.align_items,
174 align_self: value.align_self,
175 justify_items: value.justify_items,
176 justify_self: value.justify_self,
177 align_content: value.align_content,
178 justify_content: value.justify_content,
179 flex_direction: value.flex_direction,
180 flex_wrap: value.flex_wrap,
181 flex_grow: value.flex_grow,
182 flex_shrink: value.flex_shrink,
183 flex_basis: value.flex_basis,
184 grid_auto_flow: value.grid_auto_flow,
185 grid_row: value.grid_row,
186 grid_column: value.grid_column,
187 ..Default::default()
188 }
189 }
190}
191
192#[derive(Debug)]
194pub struct LayoutNode {
195 pub layout: Layout,
197 pub children: Vec<LayoutNode>,
199}
200
201pub struct StyleNode {
203 pub style: LayoutStyle,
205 pub children: Vec<StyleNode>,
207}