ferroui_base/rendering/composition/generated/
composition_path_geometry.rs1use bitflags::bitflags;
8use crate::rendering::composition::CompositionPath;
9use crate::rendering::composition::animations::ICompositionAnimation;
10use crate::rendering::composition::expressions::ExpressionVariant;
11use crate::rendering::composition::server::CompositionProperty;
12use crate::rendering::composition::server::CompositionPropertyOf;
13use crate::rendering::composition::server::ServerPropertyValue;
14use crate::rendering::composition::server::ServerValueChange;
15use crate::rendering::composition::server::props_of;
16use crate::rendering::composition::transport::BatchStreamReader;
17use crate::rendering::composition::transport::BatchStreamWriter;
18use crate::rendering::composition::transport::BatchValue;
19use crate::rendering::composition::transport::BatchValueReader;
20use std::any::Any;
21use std::any::TypeId;
22use std::cell::Cell;
23use std::cell::RefCell;
24use std::sync::Arc;
25use std::sync::OnceLock;
26use std::time::Duration;
27use super::CompositionGeometryHooks;
28use super::CompositionGeometryProps;
29use super::ServerCompositionGeometryHooks;
30use super::ServerCompositionGeometryProps;
31
32bitflags! {
33 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
35 pub struct CompositionPathGeometryChangedFields: u8 {
36 const PATH = 1;
37 }
38}
39
40impl BatchValue for CompositionPathGeometryChangedFields {
41 #[inline]
42 fn write_to(&self, out: &mut Vec<u8>) {
43 self.bits().write_to(out);
44 }
45
46 #[inline]
47 fn read_from(input: &mut BatchValueReader<'_>) -> Self {
48 CompositionPathGeometryChangedFields::from_bits_retain(u8::read_from(input))
49 }
50}
51
52pub trait CompositionPathGeometryHooks: CompositionGeometryHooks {
55 fn initialize_defaults_extra(&self) {}
56
57 fn validate_path_change(&self, _old_value: &Option<Arc<CompositionPath>>, _new_value: &Option<Arc<CompositionPath>>) {}
58 fn on_path_changed(&self) {}
59 fn on_path_changing(&self) {}
60}
61
62pub struct CompositionPathGeometryProps {
64 base: CompositionGeometryProps,
65 changed_fields_of_composition_path_geometry: Cell<CompositionPathGeometryChangedFields>,
66 path: RefCell<Option<Arc<CompositionPath>>>,
67}
68
69impl Default for CompositionPathGeometryProps {
70 fn default() -> Self {
71 Self::new()
72 }
73}
74
75impl CompositionPathGeometryProps {
76 pub fn new() -> Self {
80 Self {
81 base: CompositionGeometryProps::new(),
82 changed_fields_of_composition_path_geometry: Cell::new(CompositionPathGeometryChangedFields::empty()),
83 path: RefCell::new(None),
84 }
85 }
86
87 pub fn base(&self) -> &CompositionGeometryProps {
89 &self.base
90 }
91
92 pub fn initialize_defaults(&self, host: &dyn CompositionPathGeometryHooks) {
95 self.base.initialize_defaults(host);
96 self.initialize_own_defaults(host);
97 }
98
99 pub fn initialize_own_defaults(&self, host: &dyn CompositionPathGeometryHooks) {
101 CompositionPathGeometryHooks::initialize_defaults_extra(host);
102 }
103
104 pub fn path(&self) -> Option<Arc<CompositionPath>> {
106 self.path.borrow().clone()
107 }
108
109 pub fn set_path(&self, host: &dyn CompositionPathGeometryHooks, value: Option<Arc<CompositionPath>>) {
111 let mut changed = false;
112 let old_value = self.path.borrow().clone();
113 if old_value.differs(&value) {
114 CompositionPathGeometryHooks::validate_path_change(host, &old_value, &value);
115 CompositionPathGeometryHooks::on_path_changing(host);
116 changed = true;
117 *self.path.borrow_mut() = value.clone();
119 self.changed_fields_of_composition_path_geometry.set(self.changed_fields_of_composition_path_geometry.get() | CompositionPathGeometryChangedFields::PATH);
121 host.register_for_serialization();
122 }
123 *self.path.borrow_mut() = value;
124 if changed {
125 CompositionPathGeometryHooks::on_path_changed(host);
126 }
127 }
128
129 pub fn start_animation(
133 &self,
134 host: &dyn CompositionPathGeometryHooks,
135 property_name: &str,
136 animation: &dyn ICompositionAnimation,
137 final_value: Option<ExpressionVariant>,
138 ) -> bool {
139 self.base.start_animation(host, property_name, animation, final_value)
140 }
141
142 pub fn serialize_changes_core(&self, host: &dyn CompositionPathGeometryHooks, writer: &mut BatchStreamWriter<'_>) {
145 self.base.serialize_changes_core(host, writer);
146 let changed = self.changed_fields_of_composition_path_geometry.get();
147 writer.write(changed);
148 if changed.contains(CompositionPathGeometryChangedFields::PATH) {
149 writer.write_value(self.path.borrow().clone());
150 }
151 self.changed_fields_of_composition_path_geometry.set(CompositionPathGeometryChangedFields::empty());
152 }
153}
154
155pub trait ServerCompositionPathGeometryHooks: ServerCompositionGeometryHooks {
158 fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
159 fn on_fields_deserialized(&self, _changed: CompositionPathGeometryChangedFields) {}
160
161 fn on_path_changed(&self) {}
162 fn on_path_changing(&self) {}
163}
164
165pub struct ServerCompositionPathGeometryProps {
167 base: ServerCompositionGeometryProps,
168 path: RefCell<Option<Arc<CompositionPath>>>,
169}
170
171impl Default for ServerCompositionPathGeometryProps {
172 fn default() -> Self {
173 Self::new()
174 }
175}
176
177impl ServerCompositionPathGeometryProps {
178 pub fn new() -> Self {
181 Self {
182 base: ServerCompositionGeometryProps::new(),
183 path: RefCell::new(None),
184 }
185 }
186
187 pub fn base(&self) -> &ServerCompositionGeometryProps {
189 &self.base
190 }
191
192 pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
195 if type_id == TypeId::of::<Self>() {
196 return Some(self);
197 }
198 self.base.find_props(type_id)
199 }
200
201 pub fn id_of_path_property() -> &'static CompositionPropertyOf<Option<Arc<CompositionPath>>> {
203 static PROPERTY: OnceLock<CompositionPropertyOf<Option<Arc<CompositionPath>>>> = OnceLock::new();
204 PROPERTY.get_or_init(|| {
205 CompositionProperty::register::<ServerCompositionPathGeometryProps, Option<Arc<CompositionPath>>>(
206 "Path",
207 "ServerCompositionPathGeometry",
208 |obj| props_of::<ServerCompositionPathGeometryProps>(obj).path.borrow().clone(),
209 |obj, v| *props_of::<ServerCompositionPathGeometryProps>(obj).path.borrow_mut() = v,
210 None,
211 None,
212 )
213 })
214 }
215
216 pub fn path(&self) -> Option<Arc<CompositionPath>> {
218 self.path.borrow().clone()
219 }
220
221 pub fn set_path(&self, host: &dyn ServerCompositionPathGeometryHooks, value: Option<Arc<CompositionPath>>) {
222 let old_value = self.path.borrow().clone();
223 let mut changed = false;
224 if old_value.differs(&value) {
225 ServerCompositionPathGeometryHooks::on_path_changing(host);
226 changed = true;
227 }
228 host.set_value(
229 Self::id_of_path_property().base(),
230 ServerValueChange {
231 equal: old_value.default_equals(&value),
232 old_resource: None,
233 new_resource: None,
234 assign: &mut || *self.path.borrow_mut() = value.clone(),
235 },
236 );
237 if changed {
238 ServerCompositionPathGeometryHooks::on_path_changed(host);
239 }
240 }
241
242 pub fn deserialize_changes_core(
245 &self,
246 host: &dyn ServerCompositionPathGeometryHooks,
247 reader: &mut BatchStreamReader<'_>,
248 committed_at: Duration,
249 ) {
250 self.base.deserialize_changes_core(host, reader, committed_at);
251 ServerCompositionPathGeometryHooks::deserialize_changes_extra(host, reader);
252 let changed = reader.read::<CompositionPathGeometryChangedFields>();
253 if changed.contains(CompositionPathGeometryChangedFields::PATH) {
254 let value = reader.read_value::<Arc<CompositionPath>>();
255 self.set_path(host, value);
256 }
257 ServerCompositionPathGeometryHooks::on_fields_deserialized(host, changed);
258 }
259
260 pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
263 ServerCompositionGeometryProps::get_composition_property(name)
264 }
265}