Skip to main content

ferroui_base/rendering/composition/generated/
composition_container_shape.rs

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