Skip to main content

ferroui_base/rendering/composition/generated/
composition_path_geometry.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionPathGeometry`.
4//!
5//! Defined by the FerroUI overlay (scripts/composition-schema-winui.xml).
6
7use bitflags::bitflags;
8use crate::rendering::composition::CompositionPath;
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::ServerPropertyValue;
14use crate::rendering::composition::server::ServerValueChange;
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::cell::RefCell;
24use std::sync::Arc;
25use std::sync::OnceLock;
26use std::time::Duration;
27use super::CompositionGeometryHooks;
28use super::CompositionGeometryProps;
29use super::ServerCompositionGeometryHooks;
30use super::ServerCompositionGeometryProps;
31
32bitflags! {
33    /// The fields of `CompositionPathGeometry` that changed since its last serialization.
34    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
35    pub struct CompositionPathGeometryChangedFields: u8 {
36        const PATH = 1;
37    }
38}
39
40impl BatchValue for CompositionPathGeometryChangedFields {
41    #[inline]
42    fn write_to(&self, out: &mut Vec<u8>) {
43        self.bits().write_to(out);
44    }
45
46    #[inline]
47    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
48        CompositionPathGeometryChangedFields::from_bits_retain(u8::read_from(input))
49    }
50}
51
52/// The partial methods of `CompositionPathGeometry`: implemented by the class that embeds
53/// [`CompositionPathGeometryProps`]. Every hook defaults to doing nothing.
54pub trait CompositionPathGeometryHooks: CompositionGeometryHooks {
55    fn initialize_defaults_extra(&self) {}
56
57    fn validate_path_change(&self, _old_value: &Option<Arc<CompositionPath>>, _new_value: &Option<Arc<CompositionPath>>) {}
58    fn on_path_changed(&self) {}
59    fn on_path_changing(&self) {}
60}
61
62/// The UI-thread properties of `CompositionPathGeometry`.
63pub struct CompositionPathGeometryProps {
64    base: CompositionGeometryProps,
65    changed_fields_of_composition_path_geometry: Cell<CompositionPathGeometryChangedFields>,
66    path: RefCell<Option<Arc<CompositionPath>>>,
67}
68
69impl Default for CompositionPathGeometryProps {
70    fn default() -> Self {
71        Self::new()
72    }
73}
74
75impl CompositionPathGeometryProps {
76    /// Creates the properties with every field at the default of its type.
77    /// The defaults of the schema are applied by
78    /// [`initialize_defaults`](Self::initialize_defaults).
79    pub fn new() -> Self {
80        Self {
81            base: CompositionGeometryProps::new(),
82            changed_fields_of_composition_path_geometry: Cell::new(CompositionPathGeometryChangedFields::empty()),
83            path: RefCell::new(None),
84        }
85    }
86
87    /// The properties of the base class.
88    pub fn base(&self) -> &CompositionGeometryProps {
89        &self.base
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 CompositionPathGeometryHooks) {
95        self.base.initialize_defaults(host);
96        self.initialize_own_defaults(host);
97    }
98
99    /// `InitializeDefaults` of this class alone.
100    pub fn initialize_own_defaults(&self, host: &dyn CompositionPathGeometryHooks) {
101        CompositionPathGeometryHooks::initialize_defaults_extra(host);
102    }
103
104    /// `Path` (FerroUI overlay).
105    pub fn path(&self) -> Option<Arc<CompositionPath>> {
106        self.path.borrow().clone()
107    }
108
109    /// Sets `Path` (FerroUI overlay).
110    pub fn set_path(&self, host: &dyn CompositionPathGeometryHooks, value: Option<Arc<CompositionPath>>) {
111        let mut changed = false;
112        let old_value = self.path.borrow().clone();
113        if old_value.differs(&value) {
114            CompositionPathGeometryHooks::validate_path_change(host, &old_value, &value);
115            CompositionPathGeometryHooks::on_path_changing(host);
116            changed = true;
117            // Update the backing value
118            *self.path.borrow_mut() = value.clone();
119            // Register object for serialization in the next batch
120            self.changed_fields_of_composition_path_geometry.set(self.changed_fields_of_composition_path_geometry.get() | CompositionPathGeometryChangedFields::PATH);
121            host.register_for_serialization();
122        }
123        *self.path.borrow_mut() = value;
124        if changed {
125            CompositionPathGeometryHooks::on_path_changed(host);
126        }
127    }
128
129    /// Connects an animation with the named property. Returns `false` when
130    /// neither this class nor its generated bases have an animated property
131    /// of that name: the caller continues with its hand-written base.
132    pub fn start_animation(
133        &self,
134        host: &dyn CompositionPathGeometryHooks,
135        property_name: &str,
136        animation: &dyn ICompositionAnimation,
137        final_value: Option<ExpressionVariant>,
138    ) -> bool {
139        self.base.start_animation(host, property_name, animation, final_value)
140    }
141
142    /// Writes the changes of the object: the base class first, then the
143    /// changed-fields mask and the changed members of this class.
144    pub fn serialize_changes_core(&self, host: &dyn CompositionPathGeometryHooks, writer: &mut BatchStreamWriter<'_>) {
145        self.base.serialize_changes_core(host, writer);
146        let changed = self.changed_fields_of_composition_path_geometry.get();
147        writer.write(changed);
148        if changed.contains(CompositionPathGeometryChangedFields::PATH) {
149            writer.write_value(self.path.borrow().clone());
150        }
151        self.changed_fields_of_composition_path_geometry.set(CompositionPathGeometryChangedFields::empty());
152    }
153}
154
155/// The partial methods of `ServerCompositionPathGeometry`: implemented by the class that embeds
156/// [`ServerCompositionPathGeometryProps`]. Every hook defaults to doing nothing.
157pub trait ServerCompositionPathGeometryHooks: ServerCompositionGeometryHooks {
158    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
159    fn on_fields_deserialized(&self, _changed: CompositionPathGeometryChangedFields) {}
160
161    fn on_path_changed(&self) {}
162    fn on_path_changing(&self) {}
163}
164
165/// The server-side properties of `ServerCompositionPathGeometry`.
166pub struct ServerCompositionPathGeometryProps {
167    base: ServerCompositionGeometryProps,
168    path: RefCell<Option<Arc<CompositionPath>>>,
169}
170
171impl Default for ServerCompositionPathGeometryProps {
172    fn default() -> Self {
173        Self::new()
174    }
175}
176
177impl ServerCompositionPathGeometryProps {
178    /// Creates the properties with every field at the default of its type; the
179    /// values of the UI thread arrive with the first batch.
180    pub fn new() -> Self {
181        Self {
182            base: ServerCompositionGeometryProps::new(),
183            path: RefCell::new(None),
184        }
185    }
186
187    /// The properties of the base class.
188    pub fn base(&self) -> &ServerCompositionGeometryProps {
189        &self.base
190    }
191
192    /// This block or the block of a base class, by type: what
193    /// `IServerObject::get_props` of the embedding class returns.
194    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
195        if type_id == TypeId::of::<Self>() {
196            return Some(self);
197        }
198        self.base.find_props(type_id)
199    }
200
201    /// The composition property of `Path`.
202    pub fn id_of_path_property() -> &'static CompositionPropertyOf<Option<Arc<CompositionPath>>> {
203        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Arc<CompositionPath>>>> = OnceLock::new();
204        PROPERTY.get_or_init(|| {
205            CompositionProperty::register::<ServerCompositionPathGeometryProps, Option<Arc<CompositionPath>>>(
206                "Path",
207                "ServerCompositionPathGeometry",
208                |obj| props_of::<ServerCompositionPathGeometryProps>(obj).path.borrow().clone(),
209                |obj, v| *props_of::<ServerCompositionPathGeometryProps>(obj).path.borrow_mut() = v,
210                None,
211                None,
212            )
213        })
214    }
215
216    /// `Path`.
217    pub fn path(&self) -> Option<Arc<CompositionPath>> {
218        self.path.borrow().clone()
219    }
220
221    pub fn set_path(&self, host: &dyn ServerCompositionPathGeometryHooks, value: Option<Arc<CompositionPath>>) {
222        let old_value = self.path.borrow().clone();
223        let mut changed = false;
224        if old_value.differs(&value) {
225            ServerCompositionPathGeometryHooks::on_path_changing(host);
226            changed = true;
227        }
228        host.set_value(
229            Self::id_of_path_property().base(),
230            ServerValueChange {
231                equal: old_value.default_equals(&value),
232                old_resource: None,
233                new_resource: None,
234                assign: &mut || *self.path.borrow_mut() = value.clone(),
235            },
236        );
237        if changed {
238            ServerCompositionPathGeometryHooks::on_path_changed(host);
239        }
240    }
241
242    /// Reads the changes of the object: the base class first, then the
243    /// changed-fields mask and the changed members of this class.
244    pub fn deserialize_changes_core(
245        &self,
246        host: &dyn ServerCompositionPathGeometryHooks,
247        reader: &mut BatchStreamReader<'_>,
248        committed_at: Duration,
249    ) {
250        self.base.deserialize_changes_core(host, reader, committed_at);
251        ServerCompositionPathGeometryHooks::deserialize_changes_extra(host, reader);
252        let changed = reader.read::<CompositionPathGeometryChangedFields>();
253        if changed.contains(CompositionPathGeometryChangedFields::PATH) {
254            let value = reader.read_value::<Arc<CompositionPath>>();
255            self.set_path(host, value);
256        }
257        ServerCompositionPathGeometryHooks::on_fields_deserialized(host, changed);
258    }
259
260    /// The composition property with the given name, among the properties
261    /// of this class and of its generated bases that have a variant form.
262    pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
263        ServerCompositionGeometryProps::get_composition_property(name)
264    }
265}