ferroui_base/rendering/composition/generated/
composition_container_shape.rs1use 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 #[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
55pub 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
65pub 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 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 pub fn base(&self) -> &CompositionShapeProps {
92 &self.base
93 }
94
95 pub fn initialize_defaults(&self, host: &dyn CompositionContainerShapeHooks) {
98 self.base.initialize_defaults(host);
99 self.initialize_own_defaults(host);
100 }
101
102 pub fn initialize_own_defaults(&self, host: &dyn CompositionContainerShapeHooks) {
104 CompositionContainerShapeHooks::initialize_defaults_extra(host);
105 }
106
107 pub fn shapes(&self) -> Option<Rc<dyn ICompositionObject>> {
109 self.shapes.borrow().clone()
110 }
111
112 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 *self.shapes.borrow_mut() = value.clone();
122 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 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 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
158pub 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
168pub 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 pub fn new() -> Self {
184 Self {
185 base: ServerCompositionShapeProps::new(),
186 shapes: RefCell::new(None),
187 }
188 }
189
190 pub fn base(&self) -> &ServerCompositionShapeProps {
192 &self.base
193 }
194
195 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 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 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 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 pub fn get_composition_property(name: &str) -> Option<&'static CompositionProperty> {
267 ServerCompositionShapeProps::get_composition_property(name)
268 }
269}