Skip to main content

ferroui_base/rendering/composition/generated/
composition_visual_collection.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionVisualCollection`.
4//!
5//! Schema attributes: custom constructor on the UI thread.
6
7use crate::rendering::composition::ICompositionObject;
8use crate::rendering::composition::ICompositionObjectHost;
9use crate::rendering::composition::server::IServerAnimatedPropertyHost;
10use crate::rendering::composition::server::ServerList;
11use crate::rendering::composition::transport::BatchStreamReader;
12use crate::rendering::composition::transport::BatchStreamWriter;
13use crate::rendering::composition::transport::ServerListProxyHelper;
14use std::any::Any;
15use std::any::TypeId;
16use std::rc::Rc;
17use std::time::Duration;
18
19/// The partial methods of `CompositionVisualCollection`: implemented by the class that embeds
20/// [`CompositionVisualCollectionProps`]. `TItem` is the UI-thread class of the items (`CompositionVisual`).
21/// Every hook defaults to doing nothing.
22pub trait CompositionVisualCollectionHooks<TItem: ICompositionObject + ?Sized>: ICompositionObjectHost {
23    fn initialize_defaults_extra(&self) {}
24    fn on_before_added(&self, _item: &Rc<TItem>) {}
25    fn on_added(&self, _item: &Rc<TItem>) {}
26    fn on_removed(&self, _item: &Rc<TItem>) {}
27    fn on_before_clear(&self) {}
28    fn on_before_replace(&self, _old_item: &Rc<TItem>, _new_item: &Rc<TItem>) {}
29    fn on_replace(&self, _old_item: &Rc<TItem>, _new_item: &Rc<TItem>) {}
30    fn on_clear(&self) {}
31}
32
33/// The UI-thread list of `CompositionVisualCollection`.
34pub struct CompositionVisualCollectionProps<TItem: ICompositionObject + ?Sized> {
35    list: ServerListProxyHelper<TItem>,
36}
37
38impl<TItem: ICompositionObject + ?Sized> Default for CompositionVisualCollectionProps<TItem> {
39    fn default() -> Self {
40        Self::new()
41    }
42}
43
44impl<TItem: ICompositionObject + ?Sized> CompositionVisualCollectionProps<TItem> {
45    pub fn new() -> Self {
46        Self { list: ServerListProxyHelper::new() }
47    }
48
49    /// The `InitializeDefaults` calls of the constructor chain.
50    pub fn initialize_defaults(&self, host: &dyn CompositionVisualCollectionHooks<TItem>) {
51        self.initialize_own_defaults(host);
52    }
53
54    /// `InitializeDefaults` of this class alone.
55    pub fn initialize_own_defaults(&self, host: &dyn CompositionVisualCollectionHooks<TItem>) {
56        CompositionVisualCollectionHooks::initialize_defaults_extra(host);
57    }
58
59    /// A snapshot of the items, for enumeration.
60    pub fn items(&self) -> Vec<Rc<TItem>> {
61        self.list.items()
62    }
63
64    pub fn add(&self, host: &dyn CompositionVisualCollectionHooks<TItem>, item: Rc<TItem>) {
65        CompositionVisualCollectionHooks::on_before_added(host, &item);
66        self.list.add(host, item.clone());
67        CompositionVisualCollectionHooks::on_added(host, &item);
68    }
69
70    pub fn clear(&self, host: &dyn CompositionVisualCollectionHooks<TItem>) {
71        CompositionVisualCollectionHooks::on_before_clear(host);
72        self.list.clear(host);
73        CompositionVisualCollectionHooks::on_clear(host);
74    }
75
76    pub fn contains(&self, item: &Rc<TItem>) -> bool {
77        self.list.contains(item)
78    }
79
80    pub fn copy_to(&self, array: &mut [Option<Rc<TItem>>], array_index: usize) {
81        self.list.copy_to(array, array_index)
82    }
83
84    pub fn remove(&self, host: &dyn CompositionVisualCollectionHooks<TItem>, item: &Rc<TItem>) -> bool {
85        let removed = self.list.remove(host, item);
86        if removed {
87            CompositionVisualCollectionHooks::on_removed(host, item);
88        }
89        removed
90    }
91
92    pub fn count(&self) -> usize {
93        self.list.count()
94    }
95
96    pub fn is_read_only(&self) -> bool {
97        self.list.is_read_only()
98    }
99
100    pub fn index_of(&self, item: &Rc<TItem>) -> Option<usize> {
101        self.list.index_of(item)
102    }
103
104    pub fn insert(&self, host: &dyn CompositionVisualCollectionHooks<TItem>, index: usize, item: Rc<TItem>) {
105        CompositionVisualCollectionHooks::on_before_added(host, &item);
106        self.list.insert(host, index, item.clone());
107        CompositionVisualCollectionHooks::on_added(host, &item);
108    }
109
110    pub fn remove_at(&self, host: &dyn CompositionVisualCollectionHooks<TItem>, index: usize) {
111        let item = self.list.get(index);
112        self.list.remove_at(host, index);
113        CompositionVisualCollectionHooks::on_removed(host, &item);
114    }
115
116    pub fn get(&self, index: usize) -> Rc<TItem> {
117        self.list.get(index)
118    }
119
120    pub fn set(&self, host: &dyn CompositionVisualCollectionHooks<TItem>, index: usize, value: Rc<TItem>) {
121        let old = self.list.get(index);
122        CompositionVisualCollectionHooks::on_before_replace(host, &old, &value);
123        self.list.set(host, index, value.clone());
124        CompositionVisualCollectionHooks::on_replace(host, &old, &value);
125    }
126
127    /// Writes the changes of the object: the list, then the base class.
128    pub fn serialize_changes_core(&self, _host: &dyn CompositionVisualCollectionHooks<TItem>, writer: &mut BatchStreamWriter<'_>) {
129        self.list.serialize(writer);
130    }
131}
132
133/// The partial methods of `ServerCompositionVisualCollection`: implemented by the class that embeds
134/// [`ServerCompositionVisualCollectionProps`]. Every hook defaults to doing nothing.
135pub trait ServerCompositionVisualCollectionHooks: IServerAnimatedPropertyHost {
136}
137
138/// The server-side properties of `ServerCompositionVisualCollection`.
139pub struct ServerCompositionVisualCollectionProps {
140    list: ServerList,
141}
142
143impl Default for ServerCompositionVisualCollectionProps {
144    fn default() -> Self {
145        Self::new()
146    }
147}
148
149impl ServerCompositionVisualCollectionProps {
150    /// Creates the properties with every field at the default of its type; the
151    /// values of the UI thread arrive with the first batch.
152    pub fn new() -> Self {
153        Self {
154            list: ServerList::new(),
155        }
156    }
157
158    /// The items: server objects of class `ServerCompositionVisual`.
159    pub fn list(&self) -> &ServerList {
160        &self.list
161    }
162
163    /// This block or the block of a base class, by type: what
164    /// `IServerObject::get_props` of the embedding class returns.
165    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
166        if type_id == TypeId::of::<Self>() {
167            return Some(self);
168        }
169        None
170    }
171
172    /// Reads the changes of the object: the base class first, then the
173    /// changed-fields mask and the changed members of this class.
174    pub fn deserialize_changes_core(
175        &self,
176        host: &dyn ServerCompositionVisualCollectionHooks,
177        reader: &mut BatchStreamReader<'_>,
178        _committed_at: Duration,
179    ) {
180        let compositor = host.server_compositor();
181        self.list.deserialize_changes_core(reader, compositor.as_ref());
182    }
183}