Skip to main content

ferroui_base/rendering/composition/generated/
composition_light.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionLight`.
4//!
5//! Defined by the FerroUI overlay (scripts/composition-schema-winui.xml).
6//!
7//! Schema attributes: abstract.
8
9use bitflags::bitflags;
10use crate::rendering::composition::ICompositionObject;
11use crate::rendering::composition::ICompositionObjectHost;
12use crate::rendering::composition::expressions::ExpressionVariant;
13use crate::rendering::composition::server::AsServerRenderResource;
14use crate::rendering::composition::server::CompositionProperty;
15use crate::rendering::composition::server::CompositionPropertyOf;
16use crate::rendering::composition::server::IServerAnimatedPropertyHost;
17use crate::rendering::composition::server::IServerObject;
18use crate::rendering::composition::server::ServerPropertyValue;
19use crate::rendering::composition::server::ServerValueChange;
20use crate::rendering::composition::server::props_of;
21use crate::rendering::composition::server::read_server_object;
22use crate::rendering::composition::transport::BatchStreamReader;
23use crate::rendering::composition::transport::BatchStreamWriter;
24use crate::rendering::composition::transport::BatchValue;
25use crate::rendering::composition::transport::BatchValueReader;
26use std::any::Any;
27use std::any::TypeId;
28use std::cell::Cell;
29use std::cell::RefCell;
30use std::rc::Rc;
31use std::sync::OnceLock;
32use std::time::Duration;
33
34bitflags! {
35    /// The fields of `CompositionLight` that changed since its last serialization.
36    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
37    pub struct CompositionLightChangedFields: u8 {
38        const TARGETS = 1;
39        const EXCLUSIONS_FROM_TARGETS = 2;
40        const IS_ENABLED = 4;
41    }
42}
43
44impl BatchValue for CompositionLightChangedFields {
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        CompositionLightChangedFields::from_bits_retain(u8::read_from(input))
53    }
54}
55
56/// The partial methods of `CompositionLight`: implemented by the class that embeds
57/// [`CompositionLightProps`]. Every hook defaults to doing nothing.
58pub trait CompositionLightHooks: ICompositionObjectHost {
59    fn initialize_defaults_extra(&self) {}
60
61    fn validate_targets_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
62    fn on_targets_changed(&self) {}
63    fn on_targets_changing(&self) {}
64
65    fn validate_exclusions_from_targets_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
66    fn on_exclusions_from_targets_changed(&self) {}
67    fn on_exclusions_from_targets_changing(&self) {}
68
69    fn validate_is_enabled_change(&self, _old_value: bool, _new_value: bool) {}
70    fn on_is_enabled_changed(&self) {}
71    fn on_is_enabled_changing(&self) {}
72}
73
74/// The UI-thread properties of `CompositionLight`.
75pub struct CompositionLightProps {
76    changed_fields_of_composition_light: Cell<CompositionLightChangedFields>,
77    targets: RefCell<Option<Rc<dyn ICompositionObject>>>,
78    exclusions_from_targets: RefCell<Option<Rc<dyn ICompositionObject>>>,
79    is_enabled: Cell<bool>,
80}
81
82impl Default for CompositionLightProps {
83    fn default() -> Self {
84        Self::new()
85    }
86}
87
88impl CompositionLightProps {
89    /// Creates the properties with every field at the default of its type.
90    /// The defaults of the schema are applied by
91    /// [`initialize_defaults`](Self::initialize_defaults).
92    pub fn new() -> Self {
93        Self {
94            changed_fields_of_composition_light: Cell::new(CompositionLightChangedFields::empty()),
95            targets: RefCell::new(None),
96            exclusions_from_targets: RefCell::new(None),
97            is_enabled: Cell::new(Default::default()),
98        }
99    }
100
101    /// The `InitializeDefaults` calls of the constructor chain: the base
102    /// classes first, then this class.
103    pub fn initialize_defaults(&self, host: &dyn CompositionLightHooks) {
104        self.initialize_own_defaults(host);
105    }
106
107    /// `InitializeDefaults` of this class alone.
108    pub fn initialize_own_defaults(&self, host: &dyn CompositionLightHooks) {
109        CompositionLightHooks::initialize_defaults_extra(host);
110        self.set_is_enabled(host, true);
111    }
112
113    /// `Targets` (internal, FerroUI overlay).
114    pub fn targets(&self) -> Option<Rc<dyn ICompositionObject>> {
115        self.targets.borrow().clone()
116    }
117
118    /// Sets `Targets` (internal, FerroUI overlay).
119    pub fn set_targets(&self, host: &dyn CompositionLightHooks, value: Option<Rc<dyn ICompositionObject>>) {
120        let mut changed = false;
121        let old_value = self.targets.borrow().clone();
122        if old_value.differs(&value) {
123            CompositionLightHooks::validate_targets_change(host, &old_value, &value);
124            CompositionLightHooks::on_targets_changing(host);
125            changed = true;
126            // Update the backing value
127            *self.targets.borrow_mut() = value.clone();
128            // Register object for serialization in the next batch
129            self.changed_fields_of_composition_light.set(self.changed_fields_of_composition_light.get() | CompositionLightChangedFields::TARGETS);
130            host.register_for_serialization();
131        }
132        *self.targets.borrow_mut() = value;
133        if changed {
134            CompositionLightHooks::on_targets_changed(host);
135        }
136    }
137
138    /// `ExclusionsFromTargets` (internal, FerroUI overlay).
139    pub fn exclusions_from_targets(&self) -> Option<Rc<dyn ICompositionObject>> {
140        self.exclusions_from_targets.borrow().clone()
141    }
142
143    /// Sets `ExclusionsFromTargets` (internal, FerroUI overlay).
144    pub fn set_exclusions_from_targets(&self, host: &dyn CompositionLightHooks, value: Option<Rc<dyn ICompositionObject>>) {
145        let mut changed = false;
146        let old_value = self.exclusions_from_targets.borrow().clone();
147        if old_value.differs(&value) {
148            CompositionLightHooks::validate_exclusions_from_targets_change(host, &old_value, &value);
149            CompositionLightHooks::on_exclusions_from_targets_changing(host);
150            changed = true;
151            // Update the backing value
152            *self.exclusions_from_targets.borrow_mut() = value.clone();
153            // Register object for serialization in the next batch
154            self.changed_fields_of_composition_light.set(self.changed_fields_of_composition_light.get() | CompositionLightChangedFields::EXCLUSIONS_FROM_TARGETS);
155            host.register_for_serialization();
156        }
157        *self.exclusions_from_targets.borrow_mut() = value;
158        if changed {
159            CompositionLightHooks::on_exclusions_from_targets_changed(host);
160        }
161    }
162
163    /// `IsEnabled` (default `true`, FerroUI overlay).
164    pub fn is_enabled(&self) -> bool {
165        self.is_enabled.get()
166    }
167
168    /// Sets `IsEnabled` (default `true`, FerroUI overlay).
169    pub fn set_is_enabled(&self, host: &dyn CompositionLightHooks, value: bool) {
170        let mut changed = false;
171        let old_value = self.is_enabled.get();
172        if old_value.differs(&value) {
173            CompositionLightHooks::validate_is_enabled_change(host, old_value, value);
174            CompositionLightHooks::on_is_enabled_changing(host);
175            changed = true;
176            // Update the backing value
177            self.is_enabled.set(value);
178            // Register object for serialization in the next batch
179            self.changed_fields_of_composition_light.set(self.changed_fields_of_composition_light.get() | CompositionLightChangedFields::IS_ENABLED);
180            host.register_for_serialization();
181        }
182        self.is_enabled.set(value);
183        if changed {
184            CompositionLightHooks::on_is_enabled_changed(host);
185        }
186    }
187
188    /// Writes the changes of the object: the base class first, then the
189    /// changed-fields mask and the changed members of this class.
190    pub fn serialize_changes_core(&self, _host: &dyn CompositionLightHooks, writer: &mut BatchStreamWriter<'_>) {
191        let changed = self.changed_fields_of_composition_light.get();
192        writer.write(changed);
193        if changed.contains(CompositionLightChangedFields::TARGETS) {
194            writer.write_server_object(self.targets.borrow().clone().map(|o| o.server()));
195        }
196        if changed.contains(CompositionLightChangedFields::EXCLUSIONS_FROM_TARGETS) {
197            writer.write_server_object(self.exclusions_from_targets.borrow().clone().map(|o| o.server()));
198        }
199        if changed.contains(CompositionLightChangedFields::IS_ENABLED) {
200            writer.write(self.is_enabled.get());
201        }
202        self.changed_fields_of_composition_light.set(CompositionLightChangedFields::empty());
203    }
204}
205
206/// The partial methods of `ServerCompositionLight`: implemented by the class that embeds
207/// [`ServerCompositionLightProps`]. Every hook defaults to doing nothing.
208pub trait ServerCompositionLightHooks: IServerAnimatedPropertyHost {
209    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
210    fn on_fields_deserialized(&self, _changed: CompositionLightChangedFields) {}
211
212    fn on_targets_changed(&self) {}
213    fn on_targets_changing(&self) {}
214
215    fn on_exclusions_from_targets_changed(&self) {}
216    fn on_exclusions_from_targets_changing(&self) {}
217
218    fn on_is_enabled_changed(&self) {}
219    fn on_is_enabled_changing(&self) {}
220}
221
222/// The server-side properties of `ServerCompositionLight`.
223pub struct ServerCompositionLightProps {
224    targets: RefCell<Option<Rc<dyn IServerObject>>>,
225    exclusions_from_targets: RefCell<Option<Rc<dyn IServerObject>>>,
226    is_enabled: Cell<bool>,
227}
228
229impl Default for ServerCompositionLightProps {
230    fn default() -> Self {
231        Self::new()
232    }
233}
234
235impl ServerCompositionLightProps {
236    /// Creates the properties with every field at the default of its type; the
237    /// values of the UI thread arrive with the first batch.
238    pub fn new() -> Self {
239        Self {
240            targets: RefCell::new(None),
241            exclusions_from_targets: RefCell::new(None),
242            is_enabled: Cell::new(Default::default()),
243        }
244    }
245
246    /// This block or the block of a base class, by type: what
247    /// `IServerObject::get_props` of the embedding class returns.
248    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
249        if type_id == TypeId::of::<Self>() {
250            return Some(self);
251        }
252        None
253    }
254
255    /// The composition property of `Targets`.
256    pub fn id_of_targets_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
257        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
258        PROPERTY.get_or_init(|| {
259            CompositionProperty::register::<ServerCompositionLightProps, Option<Rc<dyn IServerObject>>>(
260                "Targets",
261                "ServerCompositionLight",
262                |obj| props_of::<ServerCompositionLightProps>(obj).targets.borrow().clone(),
263                |obj, v| *props_of::<ServerCompositionLightProps>(obj).targets.borrow_mut() = v,
264                None,
265                None,
266            )
267        })
268    }
269
270    /// `Targets`.
271    pub fn targets(&self) -> Option<Rc<dyn IServerObject>> {
272        self.targets.borrow().clone()
273    }
274
275    pub fn set_targets(&self, host: &dyn ServerCompositionLightHooks, value: Option<Rc<dyn IServerObject>>) {
276        let old_value = self.targets.borrow().clone();
277        let mut changed = false;
278        if old_value.differs(&value) {
279            ServerCompositionLightHooks::on_targets_changing(host);
280            changed = true;
281        }
282        host.set_value(
283            Self::id_of_targets_property().base(),
284            ServerValueChange {
285                equal: old_value.default_equals(&value),
286                old_resource: old_value.as_server_render_resource(),
287                new_resource: value.as_server_render_resource(),
288                assign: &mut || *self.targets.borrow_mut() = value.clone(),
289            },
290        );
291        if changed {
292            ServerCompositionLightHooks::on_targets_changed(host);
293        }
294    }
295
296    /// The composition property of `ExclusionsFromTargets`.
297    pub fn id_of_exclusions_from_targets_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
298        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
299        PROPERTY.get_or_init(|| {
300            CompositionProperty::register::<ServerCompositionLightProps, Option<Rc<dyn IServerObject>>>(
301                "ExclusionsFromTargets",
302                "ServerCompositionLight",
303                |obj| props_of::<ServerCompositionLightProps>(obj).exclusions_from_targets.borrow().clone(),
304                |obj, v| *props_of::<ServerCompositionLightProps>(obj).exclusions_from_targets.borrow_mut() = v,
305                None,
306                None,
307            )
308        })
309    }
310
311    /// `ExclusionsFromTargets`.
312    pub fn exclusions_from_targets(&self) -> Option<Rc<dyn IServerObject>> {
313        self.exclusions_from_targets.borrow().clone()
314    }
315
316    pub fn set_exclusions_from_targets(&self, host: &dyn ServerCompositionLightHooks, value: Option<Rc<dyn IServerObject>>) {
317        let old_value = self.exclusions_from_targets.borrow().clone();
318        let mut changed = false;
319        if old_value.differs(&value) {
320            ServerCompositionLightHooks::on_exclusions_from_targets_changing(host);
321            changed = true;
322        }
323        host.set_value(
324            Self::id_of_exclusions_from_targets_property().base(),
325            ServerValueChange {
326                equal: old_value.default_equals(&value),
327                old_resource: old_value.as_server_render_resource(),
328                new_resource: value.as_server_render_resource(),
329                assign: &mut || *self.exclusions_from_targets.borrow_mut() = value.clone(),
330            },
331        );
332        if changed {
333            ServerCompositionLightHooks::on_exclusions_from_targets_changed(host);
334        }
335    }
336
337    /// The composition property of `IsEnabled`.
338    pub fn id_of_is_enabled_property() -> &'static CompositionPropertyOf<bool> {
339        static PROPERTY: OnceLock<CompositionPropertyOf<bool>> = OnceLock::new();
340        PROPERTY.get_or_init(|| {
341            CompositionProperty::register::<ServerCompositionLightProps, bool>(
342                "IsEnabled",
343                "ServerCompositionLight",
344                |obj| props_of::<ServerCompositionLightProps>(obj).is_enabled.get(),
345                |obj, v| props_of::<ServerCompositionLightProps>(obj).is_enabled.set(v),
346                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionLightProps>(obj).is_enabled.get())),
347                None,
348            )
349        })
350    }
351
352    /// `IsEnabled`.
353    pub fn is_enabled(&self) -> bool {
354        self.is_enabled.get()
355    }
356
357    pub fn set_is_enabled(&self, host: &dyn ServerCompositionLightHooks, value: bool) {
358        let old_value = self.is_enabled.get();
359        let mut changed = false;
360        if old_value.differs(&value) {
361            ServerCompositionLightHooks::on_is_enabled_changing(host);
362            changed = true;
363        }
364        host.set_value(
365            Self::id_of_is_enabled_property().base(),
366            ServerValueChange {
367                equal: old_value.default_equals(&value),
368                old_resource: None,
369                new_resource: None,
370                assign: &mut || self.is_enabled.set(value),
371            },
372        );
373        if changed {
374            ServerCompositionLightHooks::on_is_enabled_changed(host);
375        }
376    }
377
378    /// Reads the changes of the object: the base class first, then the
379    /// changed-fields mask and the changed members of this class.
380    pub fn deserialize_changes_core(
381        &self,
382        host: &dyn ServerCompositionLightHooks,
383        reader: &mut BatchStreamReader<'_>,
384        _committed_at: Duration,
385    ) {
386        let compositor = host.server_compositor();
387        ServerCompositionLightHooks::deserialize_changes_extra(host, reader);
388        let changed = reader.read::<CompositionLightChangedFields>();
389        if changed.contains(CompositionLightChangedFields::TARGETS) {
390            let value = read_server_object(reader, compositor.as_ref());
391            self.set_targets(host, value);
392        }
393        if changed.contains(CompositionLightChangedFields::EXCLUSIONS_FROM_TARGETS) {
394            let value = read_server_object(reader, compositor.as_ref());
395            self.set_exclusions_from_targets(host, value);
396        }
397        if changed.contains(CompositionLightChangedFields::IS_ENABLED) {
398            let value = reader.read::<bool>();
399            self.set_is_enabled(host, value);
400        }
401        ServerCompositionLightHooks::on_fields_deserialized(host, changed);
402    }
403
404    /// The composition property with the given name, among the properties
405    /// of this class and of its generated bases that have a variant form.
406    pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
407        if name == "IsEnabled" {
408            return Some(Self::id_of_is_enabled_property().base());
409        }
410        None
411    }
412}