vizia_core/animation/
animation_builder.rs
1use crate::prelude::*;
2
3use vizia_style::{BorderWidth, Property};
4
5pub struct AnimationBuilder<'a> {
7 pub(crate) keyframes: Vec<KeyframeBuilder<'a>>,
8}
9
10impl Default for AnimationBuilder<'_> {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl AnimationBuilder<'_> {
17 pub fn new() -> Self {
19 Self { keyframes: Vec::new() }
20 }
21
22 pub fn keyframe(
24 mut self,
25 time: f32,
26 keyframe: impl FnOnce(KeyframeBuilder) -> KeyframeBuilder,
27 ) -> Self {
28 let keyframe = (keyframe)(KeyframeBuilder::new(time));
29 self.keyframes.push(keyframe);
30
31 self
32 }
33}
34
35pub struct KeyframeBuilder<'a> {
37 pub(crate) time: f32,
38 pub(crate) properties: Vec<Property<'a>>,
39}
40
41impl<'a> KeyframeBuilder<'a> {
42 pub(crate) fn new(time: f32) -> Self {
44 Self { time, properties: Vec::new() }
45 }
46
47 pub fn display(mut self, val: impl Into<Display>) -> Self {
51 self.properties.push(Property::Display(val.into()));
52
53 self
54 }
55
56 pub fn opacity(mut self, val: impl Into<Opacity>) -> Self {
58 self.properties.push(Property::Opacity(val.into()));
59
60 self
61 }
62
63 pub fn clip_path(mut self, val: impl Into<ClipPath>) -> Self {
65 self.properties.push(Property::ClipPath(val.into()));
66
67 self
68 }
69
70 pub fn transform(mut self, val: impl Into<Vec<Transform>>) -> Self {
74 self.properties.push(Property::Transform(val.into()));
75
76 self
77 }
78
79 pub fn transform_origin(mut self, val: impl Into<Position>) -> Self {
81 self.properties.push(Property::TransformOrigin(val.into()));
82
83 self
84 }
85
86 pub fn translate(mut self, val: impl Into<Translate>) -> Self {
88 self.properties.push(Property::Translate(val.into()));
89
90 self
91 }
92
93 pub fn rotate(mut self, val: impl Into<Angle>) -> Self {
95 self.properties.push(Property::Rotate(val.into()));
96
97 self
98 }
99
100 pub fn scale(mut self, val: impl Into<Scale>) -> Self {
102 self.properties.push(Property::Scale(val.into()));
103
104 self
105 }
106
107 pub fn border_width(mut self, val: impl Into<BorderWidth>) -> Self {
111 self.properties.push(Property::BorderWidth(val.into()));
112
113 self
114 }
115
116 pub fn border_color(mut self, val: impl Into<Color>) -> Self {
118 self.properties.push(Property::BorderColor(val.into()));
119
120 self
121 }
122
123 pub fn corner_top_left_radius(mut self, val: impl Into<LengthOrPercentage>) -> Self {
126 self.properties.push(Property::CornerTopLeftRadius(val.into()));
127
128 self
129 }
130
131 pub fn corner_top_right_radius(mut self, val: impl Into<LengthOrPercentage>) -> Self {
132 self.properties.push(Property::CornerTopRightRadius(val.into()));
133
134 self
135 }
136
137 pub fn corner_bottom_left_radius(mut self, val: impl Into<LengthOrPercentage>) -> Self {
138 self.properties.push(Property::CornerBottomLeftRadius(val.into()));
139
140 self
141 }
142
143 pub fn corner_bottom_right_radius(mut self, val: impl Into<LengthOrPercentage>) -> Self {
144 self.properties.push(Property::CornerBottomRightRadius(val.into()));
145
146 self
147 }
148
149 pub fn outline_width(mut self, val: impl Into<BorderWidth>) -> Self {
152 self.properties.push(Property::OutlineWidth(val.into()));
153
154 self
155 }
156
157 pub fn outline_color(mut self, val: impl Into<Color>) -> Self {
158 self.properties.push(Property::OutlineColor(val.into()));
159
160 self
161 }
162
163 pub fn outline_offset(mut self, val: impl Into<LengthOrPercentage>) -> Self {
164 self.properties.push(Property::OutlineOffset(val.into()));
165
166 self
167 }
168
169 pub fn background_color(mut self, val: impl Into<Color>) -> Self {
172 self.properties.push(Property::BackgroundColor(val.into()));
173
174 self
175 }
176
177 pub fn background_image(mut self, val: impl Into<Vec<BackgroundImage<'a>>>) -> Self {
178 self.properties.push(Property::BackgroundImage(val.into()));
179
180 self
181 }
182
183 pub fn background_size(mut self, val: impl Into<Vec<BackgroundSize>>) -> Self {
184 self.properties.push(Property::BackgroundSize(val.into()));
185
186 self
187 }
188
189 pub fn shadow(mut self, val: impl Into<Vec<Shadow>>) -> Self {
192 self.properties.push(Property::Shadow(val.into()));
193
194 self
195 }
196
197 pub fn color(mut self, val: impl Into<Color>) -> Self {
200 self.properties.push(Property::FontColor(val.into()));
201
202 self
203 }
204
205 pub fn font_size(mut self, val: impl Into<FontSize>) -> Self {
206 self.properties.push(Property::FontSize(val.into()));
207
208 self
209 }
210
211 pub fn caret_color(mut self, val: impl Into<Color>) -> Self {
212 self.properties.push(Property::CaretColor(val.into()));
213
214 self
215 }
216
217 pub fn selection_color(mut self, val: impl Into<Color>) -> Self {
218 self.properties.push(Property::SelectionColor(val.into()));
219
220 self
221 }
222
223 pub fn left(mut self, val: impl Into<Units>) -> Self {
226 self.properties.push(Property::Left(val.into()));
227
228 self
229 }
230
231 pub fn right(mut self, val: impl Into<Units>) -> Self {
232 self.properties.push(Property::Right(val.into()));
233
234 self
235 }
236
237 pub fn top(mut self, val: impl Into<Units>) -> Self {
238 self.properties.push(Property::Top(val.into()));
239
240 self
241 }
242
243 pub fn bottom(mut self, val: impl Into<Units>) -> Self {
244 self.properties.push(Property::Bottom(val.into()));
245
246 self
247 }
248
249 pub fn padding_left(mut self, val: impl Into<Units>) -> Self {
252 self.properties.push(Property::PaddingLeft(val.into()));
253
254 self
255 }
256
257 pub fn padding_right(mut self, val: impl Into<Units>) -> Self {
258 self.properties.push(Property::PaddingRight(val.into()));
259
260 self
261 }
262
263 pub fn padding_top(mut self, val: impl Into<Units>) -> Self {
264 self.properties.push(Property::PaddingTop(val.into()));
265
266 self
267 }
268
269 pub fn padding_bottom(mut self, val: impl Into<Units>) -> Self {
270 self.properties.push(Property::PaddingBottom(val.into()));
271
272 self
273 }
274
275 pub fn horizontal_gap(mut self, val: impl Into<Units>) -> Self {
276 self.properties.push(Property::HorizontalGap(val.into()));
277
278 self
279 }
280
281 pub fn vertical_gap(mut self, val: impl Into<Units>) -> Self {
282 self.properties.push(Property::VerticalGap(val.into()));
283
284 self
285 }
286
287 pub fn width(mut self, val: impl Into<Units>) -> Self {
290 self.properties.push(Property::Width(val.into()));
291
292 self
293 }
294
295 pub fn height(mut self, val: impl Into<Units>) -> Self {
296 self.properties.push(Property::Height(val.into()));
297
298 self
299 }
300
301 pub fn min_width(mut self, val: impl Into<Units>) -> Self {
303 self.properties.push(Property::MinWidth(val.into()));
304
305 self
306 }
307
308 pub fn max_width(mut self, val: impl Into<Units>) -> Self {
309 self.properties.push(Property::MaxWidth(val.into()));
310
311 self
312 }
313
314 pub fn min_height(mut self, val: impl Into<Units>) -> Self {
315 self.properties.push(Property::MinHeight(val.into()));
316
317 self
318 }
319
320 pub fn max_height(mut self, val: impl Into<Units>) -> Self {
321 self.properties.push(Property::MaxHeight(val.into()));
322
323 self
324 }
325}