Skip to main content

ferroui_base/rendering/composition/generated/
composition_simple_linear_gradient_brush.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionSimpleLinearGradientBrush` (server only).
4//!
5//! Schema attributes: internal.
6
7use bitflags::bitflags;
8use crate::RelativePoint;
9use crate::rendering::composition::expressions::ExpressionVariant;
10use crate::rendering::composition::server::CompositionProperty;
11use crate::rendering::composition::server::CompositionPropertyOf;
12use crate::rendering::composition::server::IServerPropertyHost;
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::sync::OnceLock;
24use std::time::Duration;
25
26bitflags! {
27    /// The fields of `CompositionSimpleLinearGradientBrush` that changed since its last serialization.
28    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
29    pub struct CompositionSimpleLinearGradientBrushChangedFields: u8 {
30        const START_POINT = 1;
31        const END_POINT = 2;
32    }
33}
34
35impl BatchValue for CompositionSimpleLinearGradientBrushChangedFields {
36    #[inline]
37    fn write_to(&self, out: &mut Vec<u8>) {
38        self.bits().write_to(out);
39    }
40
41    #[inline]
42    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
43        CompositionSimpleLinearGradientBrushChangedFields::from_bits_retain(u8::read_from(input))
44    }
45}
46
47/// The partial methods of `ServerCompositionSimpleLinearGradientBrush`: implemented by the class that embeds
48/// [`ServerCompositionSimpleLinearGradientBrushProps`]. Every hook defaults to doing nothing.
49pub trait ServerCompositionSimpleLinearGradientBrushHooks: IServerPropertyHost {
50    /// `base.DeserializeChangesCore(reader, committedAt)`: reads the changes of
51    /// the hand-written base class `ServerCompositionSimpleGradientBrush`.
52    fn base_deserialize_changes_core(&self, reader: &mut BatchStreamReader<'_>, committed_at: Duration);
53
54    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
55    fn on_fields_deserialized(&self, _changed: CompositionSimpleLinearGradientBrushChangedFields) {}
56
57    fn on_start_point_changed(&self) {}
58    fn on_start_point_changing(&self) {}
59
60    fn on_end_point_changed(&self) {}
61    fn on_end_point_changing(&self) {}
62}
63
64/// The server-side properties of `ServerCompositionSimpleLinearGradientBrush`.
65pub struct ServerCompositionSimpleLinearGradientBrushProps {
66    start_point: Cell<RelativePoint>,
67    end_point: Cell<RelativePoint>,
68}
69
70impl Default for ServerCompositionSimpleLinearGradientBrushProps {
71    fn default() -> Self {
72        Self::new()
73    }
74}
75
76impl ServerCompositionSimpleLinearGradientBrushProps {
77    /// Creates the properties with every field at the default of its type; the
78    /// values of the UI thread arrive with the first batch.
79    pub fn new() -> Self {
80        Self {
81            start_point: Cell::new(Default::default()),
82            end_point: Cell::new(Default::default()),
83        }
84    }
85
86    /// This block or the block of a base class, by type: what
87    /// `IServerObject::get_props` of the embedding class returns.
88    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
89        if type_id == TypeId::of::<Self>() {
90            return Some(self);
91        }
92        None
93    }
94
95    /// The composition property of `StartPoint`.
96    pub fn id_of_start_point_property() -> &'static CompositionPropertyOf<RelativePoint> {
97        static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
98        PROPERTY.get_or_init(|| {
99            CompositionProperty::register::<ServerCompositionSimpleLinearGradientBrushProps, RelativePoint>(
100                "StartPoint",
101                "ServerCompositionSimpleLinearGradientBrush",
102                |obj| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.get(),
103                |obj, v| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.set(v),
104                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).start_point.get())),
105                None,
106            )
107        })
108    }
109
110    /// `StartPoint`.
111    pub fn start_point(&self) -> RelativePoint {
112        self.start_point.get()
113    }
114
115    pub fn set_start_point(&self, host: &dyn ServerCompositionSimpleLinearGradientBrushHooks, value: RelativePoint) {
116        let old_value = self.start_point.get();
117        let mut changed = false;
118        if old_value.differs(&value) {
119            ServerCompositionSimpleLinearGradientBrushHooks::on_start_point_changing(host);
120            changed = true;
121        }
122        host.set_value(
123            Self::id_of_start_point_property().base(),
124            ServerValueChange {
125                equal: old_value.default_equals(&value),
126                old_resource: None,
127                new_resource: None,
128                assign: &mut || self.start_point.set(value),
129            },
130        );
131        if changed {
132            ServerCompositionSimpleLinearGradientBrushHooks::on_start_point_changed(host);
133        }
134    }
135
136    /// The composition property of `EndPoint`.
137    pub fn id_of_end_point_property() -> &'static CompositionPropertyOf<RelativePoint> {
138        static PROPERTY: OnceLock<CompositionPropertyOf<RelativePoint>> = OnceLock::new();
139        PROPERTY.get_or_init(|| {
140            CompositionProperty::register::<ServerCompositionSimpleLinearGradientBrushProps, RelativePoint>(
141                "EndPoint",
142                "ServerCompositionSimpleLinearGradientBrush",
143                |obj| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).end_point.get(),
144                |obj, v| props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).end_point.set(v),
145                Some(|obj| ExpressionVariant::create(props_of::<ServerCompositionSimpleLinearGradientBrushProps>(obj).end_point.get())),
146                None,
147            )
148        })
149    }
150
151    /// `EndPoint`.
152    pub fn end_point(&self) -> RelativePoint {
153        self.end_point.get()
154    }
155
156    pub fn set_end_point(&self, host: &dyn ServerCompositionSimpleLinearGradientBrushHooks, value: RelativePoint) {
157        let old_value = self.end_point.get();
158        let mut changed = false;
159        if old_value.differs(&value) {
160            ServerCompositionSimpleLinearGradientBrushHooks::on_end_point_changing(host);
161            changed = true;
162        }
163        host.set_value(
164            Self::id_of_end_point_property().base(),
165            ServerValueChange {
166                equal: old_value.default_equals(&value),
167                old_resource: None,
168                new_resource: None,
169                assign: &mut || self.end_point.set(value),
170            },
171        );
172        if changed {
173            ServerCompositionSimpleLinearGradientBrushHooks::on_end_point_changed(host);
174        }
175    }
176
177    /// Reads 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 deserialize_changes_core(
180        &self,
181        host: &dyn ServerCompositionSimpleLinearGradientBrushHooks,
182        reader: &mut BatchStreamReader<'_>,
183        committed_at: Duration,
184    ) {
185        ServerCompositionSimpleLinearGradientBrushHooks::base_deserialize_changes_core(host, reader, committed_at);
186        ServerCompositionSimpleLinearGradientBrushHooks::deserialize_changes_extra(host, reader);
187        let changed = reader.read::<CompositionSimpleLinearGradientBrushChangedFields>();
188        if changed.contains(CompositionSimpleLinearGradientBrushChangedFields::START_POINT) {
189            let value = reader.read::<RelativePoint>();
190            self.set_start_point(host, value);
191        }
192        if changed.contains(CompositionSimpleLinearGradientBrushChangedFields::END_POINT) {
193            let value = reader.read::<RelativePoint>();
194            self.set_end_point(host, value);
195        }
196        ServerCompositionSimpleLinearGradientBrushHooks::on_fields_deserialized(host, changed);
197    }
198
199    /// Writes every property of the class, in the form
200    /// [`deserialize_changes_core`](Self::deserialize_changes_core) reads.
201    pub fn serialize_all_changes(
202        writer: &mut BatchStreamWriter<'_>,
203        start_point: RelativePoint,
204        end_point: RelativePoint,
205    ) {
206        writer.write(CompositionSimpleLinearGradientBrushChangedFields::START_POINT | CompositionSimpleLinearGradientBrushChangedFields::END_POINT);
207        writer.write(start_point);
208        writer.write(end_point);
209    }
210}