ferroui_base/media/
conic_gradient_brush.rs1use crate::media::immutable::ImmutableConicGradientBrush;
2use crate::media::{BrushImpl, BrushImplExt, GradientBrush, GradientBrushImpl, IImmutableBrush, ServerBrushFactory};
3use crate::rendering::composition::generated::ServerCompositionSimpleConicGradientBrushProps;
4use crate::rendering::composition::server::ServerCompositionSimpleConicGradientBrush;
5use crate::rendering::composition::transport::BatchStreamWriter;
6use crate::rendering::composition::Compositor;
7use crate::{
8 ferro_class, ferro_impl_classes, ferro_property, instantiate, FerroObjectImpl, FerroProperty, Ref, RelativePoint,
9 StyledProperty,
10};
11use std::rc::Rc;
12
13#[repr(C)]
15pub struct ConicGradientBrush {
16 base: GradientBrush,
17}
18
19ferro_class!(ConicGradientBrush: GradientBrush);
20crate::ferro_class_info!(ConicGradientBrush { new: ConicGradientBrush::new });
21ferro_impl_classes!(ConicGradientBrush: FerroObjectImpl);
22
23impl BrushImpl for ConicGradientBrush {
24 fn factory(_this: &Self) -> Option<ServerBrushFactory> {
25 Some(|c| ServerCompositionSimpleConicGradientBrush::new(c))
26 }
27
28 fn serialize_changes(this: &Self, c: &Compositor, writer: &mut BatchStreamWriter<'_>) {
29 Self::parent_serialize_changes(this, c, writer);
30 ServerCompositionSimpleConicGradientBrushProps::serialize_all_changes(writer, this.angle(), this.center());
31 }
32}
33
34impl GradientBrushImpl for ConicGradientBrush {
35 fn to_immutable(this: &Self) -> Rc<dyn IImmutableBrush> {
36 Rc::new(ImmutableConicGradientBrush::from_brush(this))
37 }
38}
39
40crate::ferro_properties! { impl ConicGradientBrush {
41 ferro_property!(pub fn center_property() -> StyledProperty<RelativePoint> {
42 FerroProperty::register::<ConicGradientBrush, _>("Center", RelativePoint::CENTER)
43 });
44
45 ferro_property!(pub fn angle_property() -> StyledProperty<f64> {
46 FerroProperty::register::<ConicGradientBrush, _>("Angle", 0.0)
47 });
48} }
49
50impl ConicGradientBrush {
51 pub fn construct() -> Self {
53 Self { base: GradientBrush::construct() }
54 }
55
56 pub fn new() -> Ref<Self> {
57 instantiate(Self::construct())
58 }
59
60 pub fn center(&self) -> RelativePoint {
62 self.get_value(Self::center_property())
63 }
64
65 pub fn set_center(&self, value: RelativePoint) {
66 self.set_value(Self::center_property(), value)
67 }
68
69 pub fn angle(&self) -> f64 {
71 self.get_value(Self::angle_property())
72 }
73
74 pub fn set_angle(&self, value: f64) {
75 self.set_value(Self::angle_property(), value)
76 }
77}