1use crate::ffi::{AlignItems, CursorStyle, FlexDirection, JustifyContent};
2use crate::node::Border;
3
4#[derive(Clone, Copy, Debug, PartialEq)]
5pub struct EdgeInsets {
6 pub left: f32,
7 pub top: f32,
8 pub right: f32,
9 pub bottom: f32,
10}
11
12impl EdgeInsets {
13 pub const fn new(left: f32, top: f32, right: f32, bottom: f32) -> Self {
14 Self {
15 left,
16 top,
17 right,
18 bottom,
19 }
20 }
21
22 pub const fn all(value: f32) -> Self {
23 Self::new(value, value, value, value)
24 }
25}
26
27#[derive(Clone, Copy, Debug, PartialEq)]
28pub struct Corners {
29 pub top_left: f32,
30 pub top_right: f32,
31 pub bottom_right: f32,
32 pub bottom_left: f32,
33}
34
35impl Corners {
36 pub const fn new(top_left: f32, top_right: f32, bottom_right: f32, bottom_left: f32) -> Self {
37 Self {
38 top_left,
39 top_right,
40 bottom_right,
41 bottom_left,
42 }
43 }
44
45 pub const fn all(value: f32) -> Self {
46 Self::new(value, value, value, value)
47 }
48}
49
50#[derive(Clone, Copy, Debug, PartialEq)]
51pub struct Shadow {
52 pub color: u32,
53 pub offset_x: f32,
54 pub offset_y: f32,
55 pub blur_sigma: f32,
56 pub spread: f32,
57}
58
59impl Shadow {
60 pub fn new(color: u32, offset_x: f32, offset_y: f32, blur_sigma: f32, spread: f32) -> Self {
61 Self {
62 color,
63 offset_x,
64 offset_y,
65 blur_sigma: blur_sigma.max(0.0),
66 spread,
67 }
68 }
69}
70
71#[derive(Clone, Copy, Debug, Default, PartialEq)]
72pub struct PresenterHostStyle {
73 pub flex_direction: Option<FlexDirection>,
74 pub justify_content: Option<JustifyContent>,
75 pub align_items: Option<AlignItems>,
76 pub background: Option<u32>,
77 pub padding: Option<EdgeInsets>,
78 pub corners: Option<Corners>,
79 pub border: Option<Border>,
80 pub shadow: Option<Shadow>,
81 pub cursor: Option<CursorStyle>,
82 pub opacity: Option<f32>,
83}
84
85impl PresenterHostStyle {
86 pub const fn new() -> Self {
87 Self {
88 flex_direction: None,
89 justify_content: None,
90 align_items: None,
91 background: None,
92 padding: None,
93 corners: None,
94 border: None,
95 shadow: None,
96 cursor: None,
97 opacity: None,
98 }
99 }
100
101 pub fn flex_direction(mut self, value: FlexDirection) -> Self {
102 self.flex_direction = Some(value);
103 self
104 }
105
106 pub fn justify_content(mut self, value: JustifyContent) -> Self {
107 self.justify_content = Some(value);
108 self
109 }
110
111 pub fn align_items(mut self, value: AlignItems) -> Self {
112 self.align_items = Some(value);
113 self
114 }
115
116 pub fn background(mut self, value: u32) -> Self {
117 self.background = Some(value);
118 self
119 }
120
121 pub fn padding(mut self, value: EdgeInsets) -> Self {
122 self.padding = Some(value);
123 self
124 }
125
126 pub fn corners(mut self, value: Corners) -> Self {
127 self.corners = Some(value);
128 self
129 }
130
131 pub fn border(mut self, value: Border) -> Self {
132 self.border = Some(value);
133 self
134 }
135
136 pub fn shadow(mut self, value: Shadow) -> Self {
137 self.shadow = Some(value);
138 self
139 }
140
141 pub fn cursor(mut self, value: CursorStyle) -> Self {
142 self.cursor = Some(value);
143 self
144 }
145
146 pub fn opacity(mut self, value: f32) -> Self {
147 self.opacity = Some(value.clamp(0.0, 1.0));
148 self
149 }
150
151 pub(crate) fn overlay(self, fallback: Self) -> Self {
152 Self {
153 flex_direction: self.flex_direction.or(fallback.flex_direction),
154 justify_content: self.justify_content.or(fallback.justify_content),
155 align_items: self.align_items.or(fallback.align_items),
156 background: self.background.or(fallback.background),
157 padding: self.padding.or(fallback.padding),
158 corners: self.corners.or(fallback.corners),
159 border: self.border.or(fallback.border),
160 shadow: self.shadow.or(fallback.shadow),
161 cursor: self.cursor.or(fallback.cursor),
162 opacity: self.opacity.or(fallback.opacity),
163 }
164 }
165}
166
167#[derive(Clone, Copy, Debug, Default)]
168pub(crate) struct HostStyleLayers {
169 pub local: PresenterHostStyle,
170 pub presenter: PresenterHostStyle,
171}
172
173impl HostStyleLayers {
174 pub fn resolved(self) -> PresenterHostStyle {
175 self.local.overlay(self.presenter)
176 }
177}