Skip to main content

ferroui_base/rendering/composition/generated/
geometric_clip.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `GeometricClip`.
4//!
5//! Defined by the FerroUI overlay (scripts/composition-schema-winui.xml).
6
7use bitflags::bitflags;
8use crate::rendering::composition::ICompositionObject;
9use crate::rendering::composition::animations::ICompositionAnimation;
10use crate::rendering::composition::expressions::ExpressionVariant;
11use crate::rendering::composition::server::AsServerRenderResource;
12use crate::rendering::composition::server::CompositionProperty;
13use crate::rendering::composition::server::CompositionPropertyOf;
14use crate::rendering::composition::server::IServerObject;
15use crate::rendering::composition::server::ServerPropertyValue;
16use crate::rendering::composition::server::ServerValueChange;
17use crate::rendering::composition::server::props_of;
18use crate::rendering::composition::server::read_server_object;
19use crate::rendering::composition::transport::BatchStreamReader;
20use crate::rendering::composition::transport::BatchStreamWriter;
21use crate::rendering::composition::transport::BatchValue;
22use crate::rendering::composition::transport::BatchValueReader;
23use std::any::Any;
24use std::any::TypeId;
25use std::cell::Cell;
26use std::cell::RefCell;
27use std::rc::Rc;
28use std::sync::OnceLock;
29use std::time::Duration;
30use super::CompositionClipHooks;
31use super::CompositionClipProps;
32use super::ServerCompositionClipHooks;
33use super::ServerCompositionClipProps;
34
35bitflags! {
36    /// The fields of `GeometricClip` that changed since its last serialization.
37    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
38    pub struct GeometricClipChangedFields: u8 {
39        const GEOMETRY = 1;
40        const VIEW_BOX = 2;
41    }
42}
43
44impl BatchValue for GeometricClipChangedFields {
45    #[inline]
46    fn write_to(&self, out: &mut Vec<u8>) {
47        self.bits().write_to(out);
48    }
49
50    #[inline]
51    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
52        GeometricClipChangedFields::from_bits_retain(u8::read_from(input))
53    }
54}
55
56/// The partial methods of `GeometricClip`: implemented by the class that embeds
57/// [`GeometricClipProps`]. Every hook defaults to doing nothing.
58pub trait GeometricClipHooks: CompositionClipHooks {
59    fn initialize_defaults_extra(&self) {}
60
61    fn validate_geometry_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
62    fn on_geometry_changed(&self) {}
63    fn on_geometry_changing(&self) {}
64
65    fn validate_view_box_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
66    fn on_view_box_changed(&self) {}
67    fn on_view_box_changing(&self) {}
68}
69
70/// The UI-thread properties of `GeometricClip`.
71pub struct GeometricClipProps {
72    base: CompositionClipProps,
73    changed_fields_of_geometric_clip: Cell<GeometricClipChangedFields>,
74    geometry: RefCell<Option<Rc<dyn ICompositionObject>>>,
75    view_box: RefCell<Option<Rc<dyn ICompositionObject>>>,
76}
77
78impl Default for GeometricClipProps {
79    fn default() -> Self {
80        Self::new()
81    }
82}
83
84impl GeometricClipProps {
85    /// Creates the properties with every field at the default of its type.
86    /// The defaults of the schema are applied by
87    /// [`initialize_defaults`](Self::initialize_defaults).
88    pub fn new() -> Self {
89        Self {
90            base: CompositionClipProps::new(),
91            changed_fields_of_geometric_clip: Cell::new(GeometricClipChangedFields::empty()),
92            geometry: RefCell::new(None),
93            view_box: RefCell::new(None),
94        }
95    }
96
97    /// The properties of the base class.
98    pub fn base(&self) -> &CompositionClipProps {
99        &self.base
100    }
101
102    /// The `InitializeDefaults` calls of the constructor chain: the base
103    /// classes first, then this class.
104    pub fn initialize_defaults(&self, host: &dyn GeometricClipHooks) {
105        self.base.initialize_defaults(host);
106        self.initialize_own_defaults(host);
107    }
108
109    /// `InitializeDefaults` of this class alone.
110    pub fn initialize_own_defaults(&self, host: &dyn GeometricClipHooks) {
111        GeometricClipHooks::initialize_defaults_extra(host);
112    }
113
114    /// `Geometry` (FerroUI overlay).
115    pub fn geometry(&self) -> Option<Rc<dyn ICompositionObject>> {
116        self.geometry.borrow().clone()
117    }
118
119    /// Sets `Geometry` (FerroUI overlay).
120    pub fn set_geometry(&self, host: &dyn GeometricClipHooks, value: Option<Rc<dyn ICompositionObject>>) {
121        let mut changed = false;
122        let old_value = self.geometry.borrow().clone();
123        if old_value.differs(&value) {
124            GeometricClipHooks::validate_geometry_change(host, &old_value, &value);
125            GeometricClipHooks::on_geometry_changing(host);
126            changed = true;
127            // Update the backing value
128            *self.geometry.borrow_mut() = value.clone();
129            // Register object for serialization in the next batch
130            self.changed_fields_of_geometric_clip.set(self.changed_fields_of_geometric_clip.get() | GeometricClipChangedFields::GEOMETRY);
131            host.register_for_serialization();
132        }
133        *self.geometry.borrow_mut() = value;
134        if changed {
135            GeometricClipHooks::on_geometry_changed(host);
136        }
137    }
138
139    /// `ViewBox` (FerroUI overlay).
140    pub fn view_box(&self) -> Option<Rc<dyn ICompositionObject>> {
141        self.view_box.borrow().clone()
142    }
143
144    /// Sets `ViewBox` (FerroUI overlay).
145    pub fn set_view_box(&self, host: &dyn GeometricClipHooks, value: Option<Rc<dyn ICompositionObject>>) {
146        let mut changed = false;
147        let old_value = self.view_box.borrow().clone();
148        if old_value.differs(&value) {
149            GeometricClipHooks::validate_view_box_change(host, &old_value, &value);
150            GeometricClipHooks::on_view_box_changing(host);
151            changed = true;
152            // Update the backing value
153            *self.view_box.borrow_mut() = value.clone();
154            // Register object for serialization in the next batch
155            self.changed_fields_of_geometric_clip.set(self.changed_fields_of_geometric_clip.get() | GeometricClipChangedFields::VIEW_BOX);
156            host.register_for_serialization();
157        }
158        *self.view_box.borrow_mut() = value;
159        if changed {
160            GeometricClipHooks::on_view_box_changed(host);
161        }
162    }
163
164    /// Connects an animation with the named property. Returns `false` when
165    /// neither this class nor its generated bases have an animated property
166    /// of that name: the caller continues with its hand-written base.
167    pub fn start_animation(
168        &self,
169        host: &dyn GeometricClipHooks,
170        property_name: &str,
171        animation: &dyn ICompositionAnimation,
172        final_value: Option<ExpressionVariant>,
173    ) -> bool {
174        self.base.start_animation(host, property_name, animation, final_value)
175    }
176
177    /// Writes the changes of the object: the base class first, then the
178    /// changed-fields mask and the changed members of this class.
179    pub fn serialize_changes_core(&self, host: &dyn GeometricClipHooks, writer: &mut BatchStreamWriter<'_>) {
180        self.base.serialize_changes_core(host, writer);
181        let changed = self.changed_fields_of_geometric_clip.get();
182        writer.write(changed);
183        if changed.contains(GeometricClipChangedFields::GEOMETRY) {
184            writer.write_server_object(self.geometry.borrow().clone().map(|o| o.server()));
185        }
186        if changed.contains(GeometricClipChangedFields::VIEW_BOX) {
187            writer.write_server_object(self.view_box.borrow().clone().map(|o| o.server()));
188        }
189        self.changed_fields_of_geometric_clip.set(GeometricClipChangedFields::empty());
190    }
191}
192
193/// The partial methods of `ServerGeometricClip`: implemented by the class that embeds
194/// [`ServerGeometricClipProps`]. Every hook defaults to doing nothing.
195pub trait ServerGeometricClipHooks: ServerCompositionClipHooks {
196    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
197    fn on_fields_deserialized(&self, _changed: GeometricClipChangedFields) {}
198
199    fn on_geometry_changed(&self) {}
200    fn on_geometry_changing(&self) {}
201
202    fn on_view_box_changed(&self) {}
203    fn on_view_box_changing(&self) {}
204}
205
206/// The server-side properties of `ServerGeometricClip`.
207pub struct ServerGeometricClipProps {
208    base: ServerCompositionClipProps,
209    geometry: RefCell<Option<Rc<dyn IServerObject>>>,
210    view_box: RefCell<Option<Rc<dyn IServerObject>>>,
211}
212
213impl Default for ServerGeometricClipProps {
214    fn default() -> Self {
215        Self::new()
216    }
217}
218
219impl ServerGeometricClipProps {
220    /// Creates the properties with every field at the default of its type; the
221    /// values of the UI thread arrive with the first batch.
222    pub fn new() -> Self {
223        Self {
224            base: ServerCompositionClipProps::new(),
225            geometry: RefCell::new(None),
226            view_box: RefCell::new(None),
227        }
228    }
229
230    /// The properties of the base class.
231    pub fn base(&self) -> &ServerCompositionClipProps {
232        &self.base
233    }
234
235    /// This block or the block of a base class, by type: what
236    /// `IServerObject::get_props` of the embedding class returns.
237    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
238        if type_id == TypeId::of::<Self>() {
239            return Some(self);
240        }
241        self.base.find_props(type_id)
242    }
243
244    /// The composition property of `Geometry`.
245    pub fn id_of_geometry_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
246        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
247        PROPERTY.get_or_init(|| {
248            CompositionProperty::register::<ServerGeometricClipProps, Option<Rc<dyn IServerObject>>>(
249                "Geometry",
250                "ServerGeometricClip",
251                |obj| props_of::<ServerGeometricClipProps>(obj).geometry.borrow().clone(),
252                |obj, v| *props_of::<ServerGeometricClipProps>(obj).geometry.borrow_mut() = v,
253                None,
254                None,
255            )
256        })
257    }
258
259    /// `Geometry`.
260    pub fn geometry(&self) -> Option<Rc<dyn IServerObject>> {
261        self.geometry.borrow().clone()
262    }
263
264    pub fn set_geometry(&self, host: &dyn ServerGeometricClipHooks, value: Option<Rc<dyn IServerObject>>) {
265        let old_value = self.geometry.borrow().clone();
266        let mut changed = false;
267        if old_value.differs(&value) {
268            ServerGeometricClipHooks::on_geometry_changing(host);
269            changed = true;
270        }
271        host.set_value(
272            Self::id_of_geometry_property().base(),
273            ServerValueChange {
274                equal: old_value.default_equals(&value),
275                old_resource: old_value.as_server_render_resource(),
276                new_resource: value.as_server_render_resource(),
277                assign: &mut || *self.geometry.borrow_mut() = value.clone(),
278            },
279        );
280        if changed {
281            ServerGeometricClipHooks::on_geometry_changed(host);
282        }
283    }
284
285    /// The composition property of `ViewBox`.
286    pub fn id_of_view_box_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
287        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
288        PROPERTY.get_or_init(|| {
289            CompositionProperty::register::<ServerGeometricClipProps, Option<Rc<dyn IServerObject>>>(
290                "ViewBox",
291                "ServerGeometricClip",
292                |obj| props_of::<ServerGeometricClipProps>(obj).view_box.borrow().clone(),
293                |obj, v| *props_of::<ServerGeometricClipProps>(obj).view_box.borrow_mut() = v,
294                None,
295                None,
296            )
297        })
298    }
299
300    /// `ViewBox`.
301    pub fn view_box(&self) -> Option<Rc<dyn IServerObject>> {
302        self.view_box.borrow().clone()
303    }
304
305    pub fn set_view_box(&self, host: &dyn ServerGeometricClipHooks, value: Option<Rc<dyn IServerObject>>) {
306        let old_value = self.view_box.borrow().clone();
307        let mut changed = false;
308        if old_value.differs(&value) {
309            ServerGeometricClipHooks::on_view_box_changing(host);
310            changed = true;
311        }
312        host.set_value(
313            Self::id_of_view_box_property().base(),
314            ServerValueChange {
315                equal: old_value.default_equals(&value),
316                old_resource: old_value.as_server_render_resource(),
317                new_resource: value.as_server_render_resource(),
318                assign: &mut || *self.view_box.borrow_mut() = value.clone(),
319            },
320        );
321        if changed {
322            ServerGeometricClipHooks::on_view_box_changed(host);
323        }
324    }
325
326    /// Reads the changes of the object: the base class first, then the
327    /// changed-fields mask and the changed members of this class.
328    pub fn deserialize_changes_core(
329        &self,
330        host: &dyn ServerGeometricClipHooks,
331        reader: &mut BatchStreamReader<'_>,
332        committed_at: Duration,
333    ) {
334        let compositor = host.server_compositor();
335        self.base.deserialize_changes_core(host, reader, committed_at);
336        ServerGeometricClipHooks::deserialize_changes_extra(host, reader);
337        let changed = reader.read::<GeometricClipChangedFields>();
338        if changed.contains(GeometricClipChangedFields::GEOMETRY) {
339            let value = read_server_object(reader, compositor.as_ref());
340            self.set_geometry(host, value);
341        }
342        if changed.contains(GeometricClipChangedFields::VIEW_BOX) {
343            let value = read_server_object(reader, compositor.as_ref());
344            self.set_view_box(host, value);
345        }
346        ServerGeometricClipHooks::on_fields_deserialized(host, changed);
347    }
348
349    /// The composition property with the given name, among the properties
350    /// of this class and of its generated bases that have a variant form.
351    pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
352        ServerCompositionClipProps::get_composition_property(name)
353    }
354}