Skip to main content

ferroui_base/rendering/composition/generated/
composition_mask_brush.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionMaskBrush`.
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::CompositionBrushHooks;
31use super::CompositionBrushProps;
32use super::ServerCompositionBrushHooks;
33use super::ServerCompositionBrushProps;
34
35bitflags! {
36    /// The fields of `CompositionMaskBrush` that changed since its last serialization.
37    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
38    pub struct CompositionMaskBrushChangedFields: u8 {
39        const SOURCE = 1;
40        const MASK = 2;
41    }
42}
43
44impl BatchValue for CompositionMaskBrushChangedFields {
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        CompositionMaskBrushChangedFields::from_bits_retain(u8::read_from(input))
53    }
54}
55
56/// The partial methods of `CompositionMaskBrush`: implemented by the class that embeds
57/// [`CompositionMaskBrushProps`]. Every hook defaults to doing nothing.
58pub trait CompositionMaskBrushHooks: CompositionBrushHooks {
59    fn initialize_defaults_extra(&self) {}
60
61    fn validate_source_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
62    fn on_source_changed(&self) {}
63    fn on_source_changing(&self) {}
64
65    fn validate_mask_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
66    fn on_mask_changed(&self) {}
67    fn on_mask_changing(&self) {}
68}
69
70/// The UI-thread properties of `CompositionMaskBrush`.
71pub struct CompositionMaskBrushProps {
72    base: CompositionBrushProps,
73    changed_fields_of_composition_mask_brush: Cell<CompositionMaskBrushChangedFields>,
74    source: RefCell<Option<Rc<dyn ICompositionObject>>>,
75    mask: RefCell<Option<Rc<dyn ICompositionObject>>>,
76}
77
78impl Default for CompositionMaskBrushProps {
79    fn default() -> Self {
80        Self::new()
81    }
82}
83
84impl CompositionMaskBrushProps {
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: CompositionBrushProps::new(),
91            changed_fields_of_composition_mask_brush: Cell::new(CompositionMaskBrushChangedFields::empty()),
92            source: RefCell::new(None),
93            mask: RefCell::new(None),
94        }
95    }
96
97    /// The properties of the base class.
98    pub fn base(&self) -> &CompositionBrushProps {
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 CompositionMaskBrushHooks) {
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 CompositionMaskBrushHooks) {
111        CompositionMaskBrushHooks::initialize_defaults_extra(host);
112    }
113
114    /// `Source` (FerroUI overlay).
115    pub fn source(&self) -> Option<Rc<dyn ICompositionObject>> {
116        self.source.borrow().clone()
117    }
118
119    /// Sets `Source` (FerroUI overlay).
120    pub fn set_source(&self, host: &dyn CompositionMaskBrushHooks, value: Option<Rc<dyn ICompositionObject>>) {
121        let mut changed = false;
122        let old_value = self.source.borrow().clone();
123        if old_value.differs(&value) {
124            CompositionMaskBrushHooks::validate_source_change(host, &old_value, &value);
125            CompositionMaskBrushHooks::on_source_changing(host);
126            changed = true;
127            // Update the backing value
128            *self.source.borrow_mut() = value.clone();
129            // Register object for serialization in the next batch
130            self.changed_fields_of_composition_mask_brush.set(self.changed_fields_of_composition_mask_brush.get() | CompositionMaskBrushChangedFields::SOURCE);
131            host.register_for_serialization();
132        }
133        *self.source.borrow_mut() = value;
134        if changed {
135            CompositionMaskBrushHooks::on_source_changed(host);
136        }
137    }
138
139    /// `Mask` (FerroUI overlay).
140    pub fn mask(&self) -> Option<Rc<dyn ICompositionObject>> {
141        self.mask.borrow().clone()
142    }
143
144    /// Sets `Mask` (FerroUI overlay).
145    pub fn set_mask(&self, host: &dyn CompositionMaskBrushHooks, value: Option<Rc<dyn ICompositionObject>>) {
146        let mut changed = false;
147        let old_value = self.mask.borrow().clone();
148        if old_value.differs(&value) {
149            CompositionMaskBrushHooks::validate_mask_change(host, &old_value, &value);
150            CompositionMaskBrushHooks::on_mask_changing(host);
151            changed = true;
152            // Update the backing value
153            *self.mask.borrow_mut() = value.clone();
154            // Register object for serialization in the next batch
155            self.changed_fields_of_composition_mask_brush.set(self.changed_fields_of_composition_mask_brush.get() | CompositionMaskBrushChangedFields::MASK);
156            host.register_for_serialization();
157        }
158        *self.mask.borrow_mut() = value;
159        if changed {
160            CompositionMaskBrushHooks::on_mask_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 CompositionMaskBrushHooks,
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 CompositionMaskBrushHooks, writer: &mut BatchStreamWriter<'_>) {
180        self.base.serialize_changes_core(host, writer);
181        let changed = self.changed_fields_of_composition_mask_brush.get();
182        writer.write(changed);
183        if changed.contains(CompositionMaskBrushChangedFields::SOURCE) {
184            writer.write_server_object(self.source.borrow().clone().map(|o| o.server()));
185        }
186        if changed.contains(CompositionMaskBrushChangedFields::MASK) {
187            writer.write_server_object(self.mask.borrow().clone().map(|o| o.server()));
188        }
189        self.changed_fields_of_composition_mask_brush.set(CompositionMaskBrushChangedFields::empty());
190    }
191}
192
193/// The partial methods of `ServerCompositionMaskBrush`: implemented by the class that embeds
194/// [`ServerCompositionMaskBrushProps`]. Every hook defaults to doing nothing.
195pub trait ServerCompositionMaskBrushHooks: ServerCompositionBrushHooks {
196    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
197    fn on_fields_deserialized(&self, _changed: CompositionMaskBrushChangedFields) {}
198
199    fn on_source_changed(&self) {}
200    fn on_source_changing(&self) {}
201
202    fn on_mask_changed(&self) {}
203    fn on_mask_changing(&self) {}
204}
205
206/// The server-side properties of `ServerCompositionMaskBrush`.
207pub struct ServerCompositionMaskBrushProps {
208    base: ServerCompositionBrushProps,
209    source: RefCell<Option<Rc<dyn IServerObject>>>,
210    mask: RefCell<Option<Rc<dyn IServerObject>>>,
211}
212
213impl Default for ServerCompositionMaskBrushProps {
214    fn default() -> Self {
215        Self::new()
216    }
217}
218
219impl ServerCompositionMaskBrushProps {
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: ServerCompositionBrushProps::new(),
225            source: RefCell::new(None),
226            mask: RefCell::new(None),
227        }
228    }
229
230    /// The properties of the base class.
231    pub fn base(&self) -> &ServerCompositionBrushProps {
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 `Source`.
245    pub fn id_of_source_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::<ServerCompositionMaskBrushProps, Option<Rc<dyn IServerObject>>>(
249                "Source",
250                "ServerCompositionMaskBrush",
251                |obj| props_of::<ServerCompositionMaskBrushProps>(obj).source.borrow().clone(),
252                |obj, v| *props_of::<ServerCompositionMaskBrushProps>(obj).source.borrow_mut() = v,
253                None,
254                None,
255            )
256        })
257    }
258
259    /// `Source`.
260    pub fn source(&self) -> Option<Rc<dyn IServerObject>> {
261        self.source.borrow().clone()
262    }
263
264    pub fn set_source(&self, host: &dyn ServerCompositionMaskBrushHooks, value: Option<Rc<dyn IServerObject>>) {
265        let old_value = self.source.borrow().clone();
266        let mut changed = false;
267        if old_value.differs(&value) {
268            ServerCompositionMaskBrushHooks::on_source_changing(host);
269            changed = true;
270        }
271        host.set_value(
272            Self::id_of_source_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.source.borrow_mut() = value.clone(),
278            },
279        );
280        if changed {
281            ServerCompositionMaskBrushHooks::on_source_changed(host);
282        }
283    }
284
285    /// The composition property of `Mask`.
286    pub fn id_of_mask_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::<ServerCompositionMaskBrushProps, Option<Rc<dyn IServerObject>>>(
290                "Mask",
291                "ServerCompositionMaskBrush",
292                |obj| props_of::<ServerCompositionMaskBrushProps>(obj).mask.borrow().clone(),
293                |obj, v| *props_of::<ServerCompositionMaskBrushProps>(obj).mask.borrow_mut() = v,
294                None,
295                None,
296            )
297        })
298    }
299
300    /// `Mask`.
301    pub fn mask(&self) -> Option<Rc<dyn IServerObject>> {
302        self.mask.borrow().clone()
303    }
304
305    pub fn set_mask(&self, host: &dyn ServerCompositionMaskBrushHooks, value: Option<Rc<dyn IServerObject>>) {
306        let old_value = self.mask.borrow().clone();
307        let mut changed = false;
308        if old_value.differs(&value) {
309            ServerCompositionMaskBrushHooks::on_mask_changing(host);
310            changed = true;
311        }
312        host.set_value(
313            Self::id_of_mask_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.mask.borrow_mut() = value.clone(),
319            },
320        );
321        if changed {
322            ServerCompositionMaskBrushHooks::on_mask_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 ServerCompositionMaskBrushHooks,
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        ServerCompositionMaskBrushHooks::deserialize_changes_extra(host, reader);
337        let changed = reader.read::<CompositionMaskBrushChangedFields>();
338        if changed.contains(CompositionMaskBrushChangedFields::SOURCE) {
339            let value = read_server_object(reader, compositor.as_ref());
340            self.set_source(host, value);
341        }
342        if changed.contains(CompositionMaskBrushChangedFields::MASK) {
343            let value = read_server_object(reader, compositor.as_ref());
344            self.set_mask(host, value);
345        }
346        ServerCompositionMaskBrushHooks::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        ServerCompositionBrushProps::get_composition_property(name)
353    }
354}