Skip to main content

ferroui_base/rendering/composition/generated/
composition_conic_gradient_brush.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionConicGradientBrush`.
4
5use 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    /// The fields of `CompositionConicGradientBrush` that changed since its last serialization.
28    #[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
49/// The partial methods of `CompositionConicGradientBrush`: implemented by the class that embeds
50/// [`CompositionConicGradientBrushProps`]. Every hook defaults to doing nothing.
51pub trait CompositionConicGradientBrushHooks: ICompositionObjectHost {
52    /// `base.SerializeChangesCore(writer)`: serializes the changes of the
53    /// hand-written base class `CompositionGradientBrush`.
54    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
67/// The UI-thread properties of `CompositionConicGradientBrush`.
68pub 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    /// Creates the properties with every field at the default of its type.
82    /// The defaults of the schema are applied by
83    /// [`initialize_defaults`](Self::initialize_defaults).
84    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    /// The `InitializeDefaults` calls of the constructor chain: the base
93    /// classes first, then this class.
94    pub fn initialize_defaults(&self, host: &dyn CompositionConicGradientBrushHooks) {
95        self.initialize_own_defaults(host);
96    }
97
98    /// `InitializeDefaults` of this class alone.
99    pub fn initialize_own_defaults(&self, host: &dyn CompositionConicGradientBrushHooks) {
100        CompositionConicGradientBrushHooks::initialize_defaults_extra(host);
101    }
102
103    /// `Angle` (animated).
104    pub fn angle(&self) -> f64 {
105        self.angle.get()
106    }
107
108    /// Sets `Angle` (animated).
109    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            // Update the backing value
117            self.angle.set(value);
118            // Register object for serialization in the next batch
119            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            // Reset previous animation if any
122            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            // Check for implicit animations
125            if let Some(animation) = host.implicit_animation("Angle") {
126                // Animation affects only current property
127                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                // Animation is triggered by the current field, but does not necessary affects it
135                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    /// `Center` (animated).
145    pub fn center(&self) -> RelativePoint {
146        self.center.get()
147    }
148
149    /// Sets `Center` (animated).
150    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            // Update the backing value
158            self.center.set(value);
159            // Register object for serialization in the next batch
160            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            // Reset previous animation if any
163            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            // Check for implicit animations
166            if let Some(animation) = host.implicit_animation("Center") {
167                // Animation affects only current property
168                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                // Animation is triggered by the current field, but does not necessary affects it
176                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    /// Connects an animation with the named property. Returns `false` when
186    /// neither this class nor its generated bases have an animated property
187    /// of that name: the caller continues with its hand-written base.
188    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    /// Writes the changes of the object: the base class first, then the
213    /// changed-fields mask and the changed members of this class.
214    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
232/// The partial methods of `ServerCompositionConicGradientBrush`: implemented by the class that embeds
233/// [`ServerCompositionConicGradientBrushProps`]. Every hook defaults to doing nothing.
234pub trait ServerCompositionConicGradientBrushHooks: IServerAnimatedPropertyHost {
235    /// `base.DeserializeChangesCore(reader, committedAt)`: reads the changes of
236    /// the hand-written base class `ServerCompositionGradientBrush`.
237    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
243/// The server-side properties of `ServerCompositionConicGradientBrush`.
244pub 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    /// Creates the properties with every field at the default of its type; the
257    /// values of the UI thread arrive with the first batch.
258    pub fn new() -> Self {
259        Self {
260            angle: Cell::new(Default::default()),
261            center: Cell::new(Default::default()),
262        }
263    }
264
265    /// This block or the block of a base class, by type: what
266    /// `IServerObject::get_props` of the embedding class returns.
267    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    /// The composition property of `Angle`.
275    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    /// `Angle` (animated).
290    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    /// The composition property of `Center`.
300    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    /// `Center` (animated).
315    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    /// Reads the changes of the object: the base class first, then the
325    /// changed-fields mask and the changed members of this class.
326    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    /// The composition property with the given name, among the properties
367    /// of this class and of its generated bases that have a variant form.
368    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}