Skip to main content

simple_render/ui/types/
commands.rs

1use super::*;
2
3#[derive(Clone, Debug, PartialEq)]
4pub enum DrawCommand {
5    Rect {
6        rect: Bounds,
7        clip: Clip,
8        opacity: f32,
9        paint: Paint,
10        gradient: GradientDirection,
11        radii: CornerRadius,
12        anti_alias: AntiAlias,
13    },
14    Border {
15        rect: Bounds,
16        clip: Clip,
17        opacity: f32,
18        paint: Paint,
19        gradient: GradientDirection,
20        widths: BorderWidth,
21        radii: CornerRadius,
22        anti_alias: AntiAlias,
23    },
24    Text {
25        rect: Bounds,
26        clip: Clip,
27        opacity: f32,
28        scale: f32,
29        text: Text,
30    },
31    RichText {
32        rect: Bounds,
33        clip: Clip,
34        opacity: f32,
35        scale: f32,
36        text: RichText,
37    },
38    Image {
39        rect: Bounds,
40        clip: Clip,
41        opacity: f32,
42        image: Image,
43    },
44}
45
46pub(in crate::ui) enum PaintCommand<'a> {
47    Rect {
48        rect: Bounds,
49        clip: Clip,
50        opacity: f32,
51        paint: &'a Paint,
52        gradient: GradientDirection,
53        radii: CornerRadius,
54        anti_alias: AntiAlias,
55    },
56    Border {
57        rect: Bounds,
58        clip: Clip,
59        opacity: f32,
60        paint: &'a Paint,
61        gradient: GradientDirection,
62        widths: BorderWidth,
63        radii: CornerRadius,
64        anti_alias: AntiAlias,
65    },
66    Text {
67        rect: Bounds,
68        clip: Clip,
69        opacity: f32,
70        scale: f32,
71        text: &'a Text,
72    },
73    RichText {
74        rect: Bounds,
75        clip: Clip,
76        opacity: f32,
77        scale: f32,
78        text: &'a RichText,
79    },
80    Image {
81        rect: Bounds,
82        clip: Clip,
83        opacity: f32,
84        image: &'a Image,
85    },
86}
87
88impl PaintCommand<'_> {
89    pub(in crate::ui) fn rect(&self) -> Bounds {
90        match self {
91            Self::Rect { rect, .. }
92            | Self::Border { rect, .. }
93            | Self::Text { rect, .. }
94            | Self::RichText { rect, .. }
95            | Self::Image { rect, .. } => *rect,
96        }
97    }
98
99    pub(in crate::ui) fn to_owned(&self) -> DrawCommand {
100        match self {
101            Self::Rect {
102                rect,
103                clip,
104                opacity,
105                paint,
106                gradient,
107                radii,
108                anti_alias,
109            } => DrawCommand::Rect {
110                rect: *rect,
111                clip: *clip,
112                opacity: *opacity,
113                paint: (*paint).clone(),
114                gradient: *gradient,
115                radii: *radii,
116                anti_alias: *anti_alias,
117            },
118            Self::Border {
119                rect,
120                clip,
121                opacity,
122                paint,
123                gradient,
124                widths,
125                radii,
126                anti_alias,
127            } => DrawCommand::Border {
128                rect: *rect,
129                clip: *clip,
130                opacity: *opacity,
131                paint: (*paint).clone(),
132                gradient: *gradient,
133                widths: *widths,
134                radii: *radii,
135                anti_alias: *anti_alias,
136            },
137            Self::Text {
138                rect,
139                clip,
140                opacity,
141                scale,
142                text,
143            } => DrawCommand::Text {
144                rect: *rect,
145                clip: *clip,
146                opacity: *opacity,
147                scale: *scale,
148                text: (*text).clone(),
149            },
150            Self::RichText {
151                rect,
152                clip,
153                opacity,
154                scale,
155                text,
156            } => DrawCommand::RichText {
157                rect: *rect,
158                clip: *clip,
159                opacity: *opacity,
160                scale: *scale,
161                text: (*text).clone(),
162            },
163            Self::Image {
164                rect,
165                clip,
166                opacity,
167                image,
168            } => DrawCommand::Image {
169                rect: *rect,
170                clip: *clip,
171                opacity: *opacity,
172                image: (*image).clone(),
173            },
174        }
175    }
176}