Skip to main content

iced_layout_core/
lib.rs

1#[derive(Default)]
2pub struct Padding {
3    pub top: Option<f32>,
4    pub right: Option<f32>,
5    pub bottom: Option<f32>,
6    pub left: Option<f32>,
7}
8
9#[derive(Clone, Copy)]
10pub struct Color {
11    pub r: f32,
12    pub g: f32,
13    pub b: f32,
14    pub a: f32,
15}
16
17#[derive(Clone, Copy)]
18pub enum Length {
19    Fill,
20    FillPortion(u16),
21    Shrink,
22    Fixed(f32),
23}
24
25#[derive(Clone, Copy)]
26pub enum Horizontal {
27    Left,
28    Center,
29    Right,
30}
31
32#[derive(Clone, Copy)]
33pub enum Vertical {
34    Top,
35    Center,
36    Bottom,
37}
38
39#[derive(Clone, Copy)]
40pub enum LineHeight {
41    Relative(f32),
42    Absolute(f32),
43}
44
45#[derive(Clone, Copy)]
46pub enum TextAlignment {
47    Default,
48    Left,
49    Center,
50    Right,
51    Justified,
52}
53
54#[derive(Clone, Copy)]
55pub enum Shaping {
56    Auto,
57    Basic,
58    Advanced,
59}
60
61#[derive(Clone, Copy)]
62pub enum Wrapping {
63    None,
64    Word,
65    Glyph,
66    WordOrGlyph,
67}
68
69#[derive(Clone, Copy)]
70pub enum FontWeight {
71    Thin,
72    ExtraLight,
73    Light,
74    Normal,
75    Medium,
76    Semibold,
77    Bold,
78    ExtraBold,
79    Black,
80}
81
82#[derive(Clone, Copy)]
83pub enum FontStretch {
84    UltraCondensed,
85    ExtraCondensed,
86    Condensed,
87    SemiCondensed,
88    Normal,
89    SemiExpanded,
90    Expanded,
91    ExtraExpanded,
92    UltraExpanded,
93}
94
95#[derive(Clone, Copy)]
96pub enum FontStyle {
97    Normal,
98    Italic,
99    Oblique,
100}
101
102#[derive(Default)]
103pub struct FontDef {
104    pub family: Option<String>,
105    pub weight: Option<FontWeight>,
106    pub stretch: Option<FontStretch>,
107    pub style: Option<FontStyle>,
108}
109
110#[derive(Default)]
111pub struct TextAttrs {
112    pub size: Option<f32>,
113    pub line_height: Option<LineHeight>,
114    pub width: Option<Length>,
115    pub height: Option<Length>,
116    pub align_x: Option<TextAlignment>,
117    pub align_y: Option<Vertical>,
118    pub color: Option<Color>,
119    pub font: Option<String>,
120}
121
122#[derive(Default)]
123pub struct BorderRadius {
124    pub top_left: Option<f32>,
125    pub top_right: Option<f32>,
126    pub bottom_right: Option<f32>,
127    pub bottom_left: Option<f32>,
128}
129
130#[derive(Default)]
131pub struct ContainerStyle {
132    pub text_color: Option<Color>,
133    pub background_color: Option<Color>,
134    pub border_color: Option<Color>,
135    pub border_width: Option<f32>,
136    pub border_radius: BorderRadius,
137    pub shadow_color: Option<Color>,
138    pub shadow_offset_x: Option<f32>,
139    pub shadow_offset_y: Option<f32>,
140    pub shadow_blur_radius: Option<f32>,
141    pub snap: Option<bool>,
142}
143
144#[derive(Default)]
145pub struct TextStyle {
146    pub color: Option<Color>,
147}
148
149#[derive(Default)]
150pub struct ButtonStyleFields {
151    pub text_color: Option<Color>,
152    pub background_color: Option<Color>,
153    pub border_color: Option<Color>,
154    pub border_width: Option<f32>,
155    pub border_radius: BorderRadius,
156    pub shadow_color: Option<Color>,
157    pub shadow_offset_x: Option<f32>,
158    pub shadow_offset_y: Option<f32>,
159    pub shadow_blur_radius: Option<f32>,
160    pub snap: Option<bool>,
161}
162
163#[derive(Default)]
164pub struct ButtonStyle {
165    pub base: ButtonStyleFields,
166    pub active: Option<ButtonStyleFields>,
167    pub hovered: Option<ButtonStyleFields>,
168    pub pressed: Option<ButtonStyleFields>,
169    pub disabled: Option<ButtonStyleFields>,
170}
171
172#[derive(Default)]
173pub struct CheckboxStyle {
174    pub background_color: Option<Color>,
175    pub icon_color: Option<Color>,
176    pub border_color: Option<Color>,
177    pub border_width: Option<f32>,
178    pub border_radius: BorderRadius,
179    pub text_color: Option<Color>,
180}
181
182#[derive(Default)]
183pub struct TextInputStyleFields {
184    pub background_color: Option<Color>,
185    pub border_color: Option<Color>,
186    pub border_width: Option<f32>,
187    pub border_radius: BorderRadius,
188    pub icon_color: Option<Color>,
189    pub placeholder_color: Option<Color>,
190    pub value_color: Option<Color>,
191    pub selection_color: Option<Color>,
192}
193
194#[derive(Default)]
195pub struct TextInputStyle {
196    pub base: TextInputStyleFields,
197    pub active: Option<TextInputStyleFields>,
198    pub hovered: Option<TextInputStyleFields>,
199    pub disabled: Option<TextInputStyleFields>,
200}
201
202pub struct Layout {
203    pub container_styles: Vec<(String, ContainerStyle)>,
204    pub text_styles: Vec<(String, TextStyle)>,
205    pub button_styles: Vec<(String, ButtonStyle)>,
206    pub checkbox_styles: Vec<(String, CheckboxStyle)>,
207    pub text_input_styles: Vec<(String, TextInputStyle)>,
208    pub font_defs: Vec<(String, FontDef)>,
209    pub root: Node,
210}
211
212#[derive(Clone, Copy)]
213pub enum TooltipPosition {
214    Top,
215    Bottom,
216    Left,
217    Right,
218    FollowCursor,
219}
220
221pub enum Node {
222    Container {
223        id: Option<String>,
224        style: Option<String>,
225        padding: Padding,
226        children: Vec<Node>,
227    },
228    Text {
229        content: String,
230        style: Option<String>,
231        attrs: TextAttrs,
232    },
233    Row {
234        spacing: Option<f32>,
235        padding: Padding,
236        width: Option<Length>,
237        height: Option<Length>,
238        align_y: Option<Vertical>,
239        clip: Option<bool>,
240        children: Vec<Node>,
241    },
242    Column {
243        spacing: Option<f32>,
244        padding: Padding,
245        width: Option<Length>,
246        height: Option<Length>,
247        max_width: Option<f32>,
248        align_x: Option<Horizontal>,
249        clip: Option<bool>,
250        children: Vec<Node>,
251    },
252    Button {
253        style: Option<String>,
254        padding: Padding,
255        width: Option<Length>,
256        height: Option<Length>,
257        clip: Option<bool>,
258        on_press: Option<String>,
259        on_press_with: Option<String>,
260        on_press_maybe: Option<String>,
261        children: Vec<Node>,
262    },
263    Stack {
264        width: Option<Length>,
265        height: Option<Length>,
266        clip: Option<bool>,
267        children: Vec<Node>,
268    },
269    Space {
270        width: Option<Length>,
271        height: Option<Length>,
272    },
273    TextInput {
274        placeholder: String,
275        value: String,
276        id: Option<String>,
277        secure: Option<bool>,
278        on_input: Option<String>,
279        on_submit: Option<String>,
280        on_submit_maybe: Option<String>,
281        on_paste: Option<String>,
282        width: Option<Length>,
283        padding: Padding,
284        size: Option<f32>,
285        line_height: Option<LineHeight>,
286        align_x: Option<Horizontal>,
287        style: Option<String>,
288        font: Option<String>,
289    },
290    Checkbox {
291        label: String,
292        is_checked: String,
293        on_toggle: Option<String>,
294        on_toggle_maybe: Option<String>,
295        size: Option<f32>,
296        width: Option<Length>,
297        spacing: Option<f32>,
298        text_size: Option<f32>,
299        text_line_height: Option<LineHeight>,
300        text_shaping: Option<Shaping>,
301        text_wrapping: Option<Wrapping>,
302        style: Option<String>,
303        font: Option<String>,
304    },
305    If {
306        condition: String,
307        true_branch: Box<Node>,
308        false_branch: Option<Box<Node>>,
309    },
310    ForEach {
311        iterable: String,
312        body: Box<Node>,
313    },
314    Widget {
315        method: String,
316        args: Vec<String>,
317        child: Option<Box<Node>>,
318    },
319    VerticalSlider {
320        range_start: f32,
321        range_end: f32,
322        value: String,
323        on_change: String,
324        default: Option<f32>,
325        on_release: Option<String>,
326        width: Option<f32>,
327        height: Option<Length>,
328        step: Option<String>,
329        shift_step: Option<f32>,
330    },
331    Tooltip {
332        position: TooltipPosition,
333        gap: Option<f32>,
334        padding: Option<f32>,
335        delay: Option<u64>,
336        snap_within_viewport: Option<bool>,
337        style: Option<String>,
338        children: Vec<Node>,
339    },
340}