ferroui_base/rendering/composition/generated/
composition_conic_gradient_brush.rs1use bitflags::bitflags;
6use crate::RelativePoint;
7use crate::rendering::composition::ICompositionObjectHost;
8use crate::rendering::composition::animations::AnimationInstanceFactory;
9use crate::rendering::composition::animations::ICompositionAnimation;
10use crate::rendering::composition::expressions::ExpressionVariant;
11use crate::rendering::composition::server::CompositionProperty;
12use crate::rendering::composition::server::CompositionPropertyOf;
13use crate::rendering::composition::server::IServerAnimatedPropertyHost;
14use crate::rendering::composition::server::ServerPropertyValue;
15use crate::rendering::composition::server::props_of;
16use crate::rendering::composition::transport::BatchStreamReader;
17use crate::rendering::composition::transport::BatchStreamWriter;
18use crate::rendering::composition::transport::BatchValue;
19use crate::rendering::composition::transport::BatchValueReader;
20use std::any::Any;
21use std::any::TypeId;
22use std::cell::Cell;
23use std::sync::OnceLock;
24use std::time::Duration;
25
26bitflags! {
27 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
29 pub struct CompositionConicGradientBrushChangedFields: u8 {
30 const ANGLE = 1;
31 const ANGLE_ANIMATED = 2;
32 const CENTER = 4;
33 const CENTER_ANIMATED = 8;
34 }
35}
36
37impl BatchValue for CompositionConicGradientBrushChangedFields {
38 #[inline]
39 fn write_to(&self, out: &mut Vec<u8>) {
40 self.bits().write_to(out);
41 }
42
43 #[inline]
44 fn read_from(input: &mut BatchValueReader<'_>) -> Self {
45 CompositionConicGradientBrushChangedFields::from_bits_retain(u8::read_from(input))
46 }
47}
48
49pub trait CompositionConicGradientBrushHooks: ICompositionObjectHost {
52 fn base_serialize_changes_core(&self, writer: &mut BatchStreamWriter<'_>);
55
56 fn initialize_defaults_extra(&self) {}
57
58 fn validate_angle_change(&self, _old_value: f64, _new_value: f64) {}
59 fn on_angle_changed(&self) {}
60 fn on_angle_changing(&self) {}
61
62 fn validate_center_change(&self, _old_value: RelativePoint, _new_value: RelativePoint) {}
63 fn on_center_changed(&self) {}
64 fn on_center_changing(&self) {}
65}
66
67pub struct CompositionConicGradientBrushProps {
69 changed_fields_of_composition_conic_gradient_brush: Cell<CompositionConicGradientBrushChangedFields>,
70 angle: Cell<f64>,
71 center: Cell<RelativePoint>,
72}
73
74impl Default for CompositionConicGradientBrushProps {
75 fn default() -> Self {
76 Self::new()
77 }
78}
79
80impl CompositionConicGradientBrushProps {
81 pub fn new() -> Self {
85 Self {
86 changed_fields_of_composition_conic_gradient_brush: Cell::new(CompositionConicGradientBrushChangedFields::empty()),
87 angle: Cell::new(Default::default()),
88 center: Cell::new(Default::default()),
89 }
90 }
91
92 pub fn initialize_defaults(&self, host: &dyn CompositionConicGradientBrushHooks) {
95 self.initialize_own_defaults(host);
96 }
97
98 pub fn initialize_own_defaults(&self, host: &dyn CompositionConicGradientBrushHooks) {
100 CompositionConicGradientBrushHooks::initialize_defaults_extra(host);
101 }
102
103 pub fn angle(&self) -> f64 {
105 self.angle.get()
106 }
107
108 pub fn set_angle(&self, host: &dyn CompositionConicGradientBrushHooks, value: f64) {
110 let mut changed = false;
111 let old_value = self.angle.get();
112 if old_value.differs(&value) {
113 CompositionConicGradientBrushHooks::validate_angle_change(host, old_value, value);
114 CompositionConicGradientBrushHooks::on_angle_changing(host);
115 changed = true;
116 self.angle.set(value);
118 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::ANGLE);
120 host.register_for_serialization();
121 host.pending_animations().remove(ServerCompositionConicGradientBrushProps::id_of_angle_property().base());
123 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() & !CompositionConicGradientBrushChangedFields::ANGLE_ANIMATED);
124 if let Some(animation) = host.implicit_animation("Angle") {
126 if let Some(a) = animation.as_composition_animation() {
128 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::ANGLE_ANIMATED);
129 host.pending_animations().set(
130 ServerCompositionConicGradientBrushProps::id_of_angle_property().base(),
131 a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
132 );
133 }
134 host.start_animation_group(&animation, "Angle", ExpressionVariant::create(value));
136 }
137 }
138 self.angle.set(value);
139 if changed {
140 CompositionConicGradientBrushHooks::on_angle_changed(host);
141 }
142 }
143
144 pub fn center(&self) -> RelativePoint {
146 self.center.get()
147 }
148
149 pub fn set_center(&self, host: &dyn CompositionConicGradientBrushHooks, value: RelativePoint) {
151 let mut changed = false;
152 let old_value = self.center.get();
153 if old_value.differs(&value) {
154 CompositionConicGradientBrushHooks::validate_center_change(host, old_value, value);
155 CompositionConicGradientBrushHooks::on_center_changing(host);
156 changed = true;
157 self.center.set(value);
159 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::CENTER);
161 host.register_for_serialization();
162 host.pending_animations().remove(ServerCompositionConicGradientBrushProps::id_of_center_property().base());
164 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() & !CompositionConicGradientBrushChangedFields::CENTER_ANIMATED);
165 if let Some(animation) = host.implicit_animation("Center") {
167 if let Some(a) = animation.as_composition_animation() {
169 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::CENTER_ANIMATED);
170 host.pending_animations().set(
171 ServerCompositionConicGradientBrushProps::id_of_center_property().base(),
172 a.create_instance(host.server(), Some(ExpressionVariant::create(value))),
173 );
174 }
175 host.start_animation_group(&animation, "Center", ExpressionVariant::create(value));
177 }
178 }
179 self.center.set(value);
180 if changed {
181 CompositionConicGradientBrushHooks::on_center_changed(host);
182 }
183 }
184
185 pub fn start_animation(
189 &self,
190 host: &dyn CompositionConicGradientBrushHooks,
191 property_name: &str,
192 animation: &dyn ICompositionAnimation,
193 final_value: Option<ExpressionVariant>,
194 ) -> bool {
195 if property_name == "Angle" {
196 let server = animation.create_instance(host.server(), final_value);
197 host.pending_animations().set(ServerCompositionConicGradientBrushProps::id_of_angle_property().base(), server);
198 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::ANGLE_ANIMATED);
199 host.register_for_serialization();
200 return true;
201 }
202 if property_name == "Center" {
203 let server = animation.create_instance(host.server(), final_value);
204 host.pending_animations().set(ServerCompositionConicGradientBrushProps::id_of_center_property().base(), server);
205 self.changed_fields_of_composition_conic_gradient_brush.set(self.changed_fields_of_composition_conic_gradient_brush.get() | CompositionConicGradientBrushChangedFields::CENTER_ANIMATED);
206 host.register_for_serialization();
207 return true;
208 }
209 false
210 }
211
212 pub fn serialize_changes_core(&self, host: &dyn CompositionConicGradientBrushHooks, writer: &mut BatchStreamWriter<'_>) {
215 CompositionConicGradientBrushHooks::base_serialize_changes_core(host, writer);
216 let changed = self.changed_fields_of_composition_conic_gradient_brush.get();
217 writer.write(changed);
218 if changed.contains(CompositionConicGradientBrushChangedFields::ANGLE_ANIMATED) {
219 writer.write_value(host.pending_animations().get_and_remove(ServerCompositionConicGradientBrushProps::id_of_angle_property().base()));
220 } else if changed.contains(CompositionConicGradientBrushChangedFields::ANGLE) {
221 writer.write(self.angle.get());
222 }
223 if changed.contains(CompositionConicGradientBrushChangedFields::CENTER_ANIMATED) {
224 writer.write_value(host.pending_animations().get_and_remove(ServerCompositionConicGradientBrushProps::id_of_center_property().base()));
225 } else if changed.contains(CompositionConicGradientBrushChangedFields::CENTER) {
226 writer.write(self.center.get());
227 }
228 self.changed_fields_of_composition_conic_gradient_brush.set(CompositionConicGradientBrushChangedFields::empty());
229 }
230}
231
232pub trait ServerCompositionConicGradientBrushHooks: IServerAnimatedPropertyHost {
235 fn base_deserialize_changes_core(&self, reader: &mut BatchStreamReader<'_>, committed_at: Duration);
238
239 fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
240 fn on_fields_deserialized(&self, _changed: CompositionConicGradientBrushChangedFields) {}
241}
242
243pub struct ServerCompositionConicGradientBrushProps {
245 angle: Cell<f64>,
246 center: Cell<RelativePoint>,
247}
248
249impl Default for ServerCompositionConicGradientBrushProps {
250 fn default() -> Self {
251 Self::new()
252 }
253}
254
255impl ServerCompositionConicGradientBrushProps {
256 pub fn new() -> Self {
259 Self {
260 angle: Cell::new(Default::default()),
261 center: Cell::new(Default::default()),
262 }
263 }
264
265 pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
268 if type_id == TypeId::of::<Self>() {
269 return Some(self);
270 }
271 None
272 }
273
274 pub fn id_of_angle_property() -> &'static CompositionPropertyOf<f64> {
276 static PROPERTY: OnceLock<CompositionPropertyOf<f64>> = OnceLock::new();
277 PROPERTY.get_or_init(|| {
278 CompositionProperty::register::<ServerCompositionConicGradientBrushProps, f64>(
279 "Angle",
280 "ServerCompositionConicGradientBrush",
281 |obj| props_of::<ServerCompositionConicGradientBrushProps>(obj).angle.get(),
282 |obj, v| props_of::<ServerCompositionConicGradientBrushProps>(obj).angle.set(v),
283 Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionConicGradientBrushProps>(obj).angle.get())),
284 Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionConicGradientBrushProps>(obj).angle.set(v.cast_or_default::<f64>())),
285 )
286 })
287 }
288
289 pub fn angle(&self) -> f64 {
291 self.angle.get()
292 }
293
294 pub fn set_angle(&self, host: &dyn ServerCompositionConicGradientBrushHooks, value: f64) {
295 self.angle.set(value);
296 host.remove_animation_for_property(Self::id_of_angle_property().base());
297 }
298
299 pub fn id_of_center_property() -> &'static CompositionPropertyOf<RelativePoint> {
301 static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
302 PROPERTY.get_or_init(|| {
303 CompositionProperty::register::<ServerCompositionConicGradientBrushProps, RelativePoint>(
304 "Center",
305 "ServerCompositionConicGradientBrush",
306 |obj| props_of::<ServerCompositionConicGradientBrushProps>(obj).center.get(),
307 |obj, v| props_of::<ServerCompositionConicGradientBrushProps>(obj).center.set(v),
308 Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionConicGradientBrushProps>(obj).center.get())),
309 Some(|obj, v: ExpressionVariant| props_of::<ServerCompositionConicGradientBrushProps>(obj).center.set(v.cast_or_default::<RelativePoint>())),
310 )
311 })
312 }
313
314 pub fn center(&self) -> RelativePoint {
316 self.center.get()
317 }
318
319 pub fn set_center(&self, host: &dyn ServerCompositionConicGradientBrushHooks, value: RelativePoint) {
320 self.center.set(value);
321 host.remove_animation_for_property(Self::id_of_center_property().base());
322 }
323
324 pub fn deserialize_changes_core(
327 &self,
328 host: &dyn ServerCompositionConicGradientBrushHooks,
329 reader: &mut BatchStreamReader<'_>,
330 committed_at: Duration,
331 ) {
332 ServerCompositionConicGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
333 ServerCompositionConicGradientBrushHooks::deserialize_changes_extra(host, reader);
334 let changed = reader.read::<CompositionConicGradientBrushChangedFields>();
335 if changed.contains(CompositionConicGradientBrushChangedFields::ANGLE_ANIMATED) {
336 let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
337 panic!("a batch starts an animation of `Angle` without an animation instance");
338 };
339 host.set_animated_value(
340 Self::id_of_angle_property().base(),
341 ExpressionVariant::create(self.angle.get()),
342 committed_at,
343 animation,
344 );
345 } else if changed.contains(CompositionConicGradientBrushChangedFields::ANGLE) {
346 let value = reader.read::<f64>();
347 self.set_angle(host, value);
348 }
349 if changed.contains(CompositionConicGradientBrushChangedFields::CENTER_ANIMATED) {
350 let Some(animation) = reader.read_value::<AnimationInstanceFactory>().map(AnimationInstanceFactory::create) else {
351 panic!("a batch starts an animation of `Center` without an animation instance");
352 };
353 host.set_animated_value(
354 Self::id_of_center_property().base(),
355 ExpressionVariant::create(self.center.get()),
356 committed_at,
357 animation,
358 );
359 } else if changed.contains(CompositionConicGradientBrushChangedFields::CENTER) {
360 let value = reader.read::<RelativePoint>();
361 self.set_center(host, value);
362 }
363 ServerCompositionConicGradientBrushHooks::on_fields_deserialized(host, changed);
364 }
365
366 pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
369 if name == "Angle" {
370 return Some(Self::id_of_angle_property().base());
371 }
372 if name == "Center" {
373 return Some(Self::id_of_center_property().base());
374 }
375 None
376 }
377}