ferroui_base/media/
tile_brush.rs1use crate::media::{AlignmentX, AlignmentY, Brush, BrushImpl, BrushImplExt, Stretch, TileMode};
2use crate::rendering::composition::generated::ServerCompositionSimpleTileBrushProps;
3use crate::rendering::composition::transport::BatchStreamWriter;
4use crate::rendering::composition::Compositor;
5use crate::{ferro_class, ferro_impl_classes, ferro_property, FerroObjectImpl, FerroProperty, RelativeRect, StyledProperty};
6
7#[repr(C)]
9pub struct TileBrush {
10 base: Brush,
11}
12
13ferro_class!(TileBrush: Brush);
14ferro_impl_classes!(TileBrush: FerroObjectImpl);
15
16impl BrushImpl for TileBrush {
17 fn serialize_changes(this: &Self, c: &Compositor, writer: &mut BatchStreamWriter<'_>) {
18 Self::parent_serialize_changes(this, c, writer);
19 ServerCompositionSimpleTileBrushProps::serialize_all_changes(
20 writer,
21 this.alignment_x(),
22 this.alignment_y(),
23 this.destination_rect(),
24 this.source_rect(),
25 this.stretch(),
26 this.tile_mode(),
27 );
28 }
29}
30
31crate::ferro_properties! { impl TileBrush {
32 ferro_property!(pub fn alignment_x_property() -> StyledProperty<AlignmentX> {
33 FerroProperty::register::<TileBrush, _>("AlignmentX", AlignmentX::Center)
34 });
35
36 ferro_property!(pub fn alignment_y_property() -> StyledProperty<AlignmentY> {
37 FerroProperty::register::<TileBrush, _>("AlignmentY", AlignmentY::Center)
38 });
39
40 ferro_property!(pub fn destination_rect_property() -> StyledProperty<RelativeRect> {
41 FerroProperty::register::<TileBrush, _>("DestinationRect", RelativeRect::FILL)
42 });
43
44 ferro_property!(pub fn source_rect_property() -> StyledProperty<RelativeRect> {
45 FerroProperty::register::<TileBrush, _>("SourceRect", RelativeRect::FILL)
46 });
47
48 ferro_property!(pub fn stretch_property() -> StyledProperty<Stretch> {
49 FerroProperty::register::<TileBrush, _>("Stretch", Stretch::Uniform)
50 });
51
52 ferro_property!(pub fn tile_mode_property() -> StyledProperty<TileMode> {
53 FerroProperty::register::<TileBrush, _>("TileMode", TileMode::None)
54 });
55} }
56
57impl TileBrush {
58 pub fn construct() -> Self {
60 Self { base: Brush::construct() }
61 }
62
63 pub fn alignment_x(&self) -> AlignmentX {
65 self.get_value(Self::alignment_x_property())
66 }
67
68 pub fn set_alignment_x(&self, value: AlignmentX) {
69 self.set_value(Self::alignment_x_property(), value)
70 }
71
72 pub fn alignment_y(&self) -> AlignmentY {
74 self.get_value(Self::alignment_y_property())
75 }
76
77 pub fn set_alignment_y(&self, value: AlignmentY) {
78 self.set_value(Self::alignment_y_property(), value)
79 }
80
81 pub fn destination_rect(&self) -> RelativeRect {
83 self.get_value(Self::destination_rect_property())
84 }
85
86 pub fn set_destination_rect(&self, value: RelativeRect) {
87 self.set_value(Self::destination_rect_property(), value)
88 }
89
90 pub fn source_rect(&self) -> RelativeRect {
92 self.get_value(Self::source_rect_property())
93 }
94
95 pub fn set_source_rect(&self, value: RelativeRect) {
96 self.set_value(Self::source_rect_property(), value)
97 }
98
99 pub fn stretch(&self) -> Stretch {
102 self.get_value(Self::stretch_property())
103 }
104
105 pub fn set_stretch(&self, value: Stretch) {
106 self.set_value(Self::stretch_property(), value)
107 }
108
109 pub fn tile_mode(&self) -> TileMode {
111 self.get_value(Self::tile_mode_property())
112 }
113
114 pub fn set_tile_mode(&self, value: TileMode) {
115 self.set_value(Self::tile_mode_property(), value)
116 }
117}