Skip to main content

ferroui_base/rendering/composition/generated/
composition_simple_geometry.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionSimpleGeometry` (server only).
4//!
5//! Schema attributes: internal.
6
7use bitflags::bitflags;
8use crate::platform::IGeometryImpl;
9use crate::rendering::composition::server::CompositionProperty;
10use crate::rendering::composition::server::CompositionPropertyOf;
11use crate::rendering::composition::server::IServerPropertyHost;
12use crate::rendering::composition::server::ServerPropertyValue;
13use crate::rendering::composition::server::ServerValueChange;
14use crate::rendering::composition::server::props_of;
15use crate::rendering::composition::transport::BatchStreamReader;
16use crate::rendering::composition::transport::BatchStreamWriter;
17use crate::rendering::composition::transport::BatchValue;
18use crate::rendering::composition::transport::BatchValueReader;
19use std::any::Any;
20use std::any::TypeId;
21use std::cell::RefCell;
22use std::sync::Arc;
23use std::sync::OnceLock;
24use std::time::Duration;
25
26bitflags! {
27    /// The fields of `CompositionSimpleGeometry` that changed since its last serialization.
28    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
29    pub struct CompositionSimpleGeometryChangedFields: u8 {
30        const GEOMETRY_IMPL = 1;
31    }
32}
33
34impl BatchValue for CompositionSimpleGeometryChangedFields {
35    #[inline]
36    fn write_to(&self, out: &mut Vec<u8>) {
37        self.bits().write_to(out);
38    }
39
40    #[inline]
41    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
42        CompositionSimpleGeometryChangedFields::from_bits_retain(u8::read_from(input))
43    }
44}
45
46/// The partial methods of `ServerCompositionSimpleGeometry`: implemented by the class that embeds
47/// [`ServerCompositionSimpleGeometryProps`]. Every hook defaults to doing nothing.
48pub trait ServerCompositionSimpleGeometryHooks: IServerPropertyHost {
49    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
50    fn on_fields_deserialized(&self, _changed: CompositionSimpleGeometryChangedFields) {}
51
52    fn on_geometry_impl_changed(&self) {}
53    fn on_geometry_impl_changing(&self) {}
54}
55
56/// The server-side properties of `ServerCompositionSimpleGeometry`.
57pub struct ServerCompositionSimpleGeometryProps {
58    geometry_impl: RefCell<Option<Arc<dyn IGeometryImpl>>>,
59}
60
61impl Default for ServerCompositionSimpleGeometryProps {
62    fn default() -> Self {
63        Self::new()
64    }
65}
66
67impl ServerCompositionSimpleGeometryProps {
68    /// Creates the properties with every field at the default of its type; the
69    /// values of the UI thread arrive with the first batch.
70    pub fn new() -> Self {
71        Self {
72            geometry_impl: RefCell::new(None),
73        }
74    }
75
76    /// This block or the block of a base class, by type: what
77    /// `IServerObject::get_props` of the embedding class returns.
78    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
79        if type_id == TypeId::of::<Self>() {
80            return Some(self);
81        }
82        None
83    }
84
85    /// The composition property of `GeometryImpl`.
86    pub fn id_of_geometry_impl_property() -> &'static CompositionPropertyOf<Option<Arc<dyn IGeometryImpl>>> {
87        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Arc<dyn IGeometryImpl>>>> = OnceLock::new();
88        PROPERTY.get_or_init(|| {
89            CompositionProperty::register::<ServerCompositionSimpleGeometryProps, Option<Arc<dyn IGeometryImpl>>>(
90                "GeometryImpl",
91                "ServerCompositionSimpleGeometry",
92                |obj| props_of::<ServerCompositionSimpleGeometryProps>(obj).geometry_impl.borrow().clone(),
93                |obj, v| *props_of::<ServerCompositionSimpleGeometryProps>(obj).geometry_impl.borrow_mut() = v,
94                None,
95                None,
96            )
97        })
98    }
99
100    /// `GeometryImpl`.
101    pub fn geometry_impl(&self) -> Option<Arc<dyn IGeometryImpl>> {
102        self.geometry_impl.borrow().clone()
103    }
104
105    pub fn set_geometry_impl(&self, host: &dyn ServerCompositionSimpleGeometryHooks, value: Option<Arc<dyn IGeometryImpl>>) {
106        let old_value = self.geometry_impl.borrow().clone();
107        let mut changed = false;
108        if old_value.differs(&value) {
109            ServerCompositionSimpleGeometryHooks::on_geometry_impl_changing(host);
110            changed = true;
111        }
112        host.set_value(
113            Self::id_of_geometry_impl_property().base(),
114            ServerValueChange {
115                equal: old_value.default_equals(&value),
116                old_resource: None,
117                new_resource: None,
118                assign: &mut || *self.geometry_impl.borrow_mut() = value.clone(),
119            },
120        );
121        if changed {
122            ServerCompositionSimpleGeometryHooks::on_geometry_impl_changed(host);
123        }
124    }
125
126    /// Reads the changes of the object: the base class first, then the
127    /// changed-fields mask and the changed members of this class.
128    pub fn deserialize_changes_core(
129        &self,
130        host: &dyn ServerCompositionSimpleGeometryHooks,
131        reader: &mut BatchStreamReader<'_>,
132        _committed_at: Duration,
133    ) {
134        ServerCompositionSimpleGeometryHooks::deserialize_changes_extra(host, reader);
135        let changed = reader.read::<CompositionSimpleGeometryChangedFields>();
136        if changed.contains(CompositionSimpleGeometryChangedFields::GEOMETRY_IMPL) {
137            let value = reader.read_value::<Arc<dyn IGeometryImpl>>();
138            self.set_geometry_impl(host, value);
139        }
140        ServerCompositionSimpleGeometryHooks::on_fields_deserialized(host, changed);
141    }
142
143    /// Writes every property of the class, in the form
144    /// [`deserialize_changes_core`](Self::deserialize_changes_core) reads.
145    pub fn serialize_all_changes(
146        writer: &mut BatchStreamWriter<'_>,
147        geometry_impl: Option<Arc<dyn IGeometryImpl>>,
148    ) {
149        writer.write(CompositionSimpleGeometryChangedFields::GEOMETRY_IMPL);
150        writer.write_value(geometry_impl);
151    }
152}