Skip to main content

euv_core/render/command/
enum.rs

1use super::*;
2
3/// Backend-agnostic vector/UI drawing primitive emitted by `PaintPass` and consumed by all renderers.
4#[derive(Clone, Debug, PartialEq)]
5pub enum DrawCommand {
6    /// Clears the target surface to `Color`.
7    Clear(Color),
8    /// Draws a rounded or sharp filled rectangle with optional border stroke.
9    FillRoundedRect {
10        /// Bounds in logical pixels.
11        rect: Rect,
12        /// Fill color.
13        color: Color,
14        /// Corner radii.
15        radius: CornerRadius,
16        /// Optional border stroke.
17        border: Border,
18    },
19    /// Draws a two-stop linear gradient inside a rounded rectangle.
20    LinearGradientRect {
21        /// Bounds in logical pixels.
22        rect: Rect,
23        /// Gradient specification.
24        gradient: LinearGradient,
25        /// Corner radii.
26        radius: CornerRadius,
27    },
28    /// Draws a soft drop shadow under a rounded rectangle.
29    BoxShadow {
30        /// Casting box bounds.
31        rect: Rect,
32        /// Corner radii.
33        radius: CornerRadius,
34        /// Shadow parameters.
35        shadow: Shadow,
36    },
37    /// Applies a backdrop blur sampling the previously rendered pixels beneath `rect`.
38    BackdropBlur {
39        /// Output bounds in logical pixels.
40        rect: Rect,
41        /// Corner radii mask in logical pixels.
42        radius: CornerRadius,
43        /// Gaussian blur radius in logical pixels.
44        blur_radius: f32,
45    },
46    /// Draws a laid-out text run using the shared deterministic glyph atlas.
47    TextRun {
48        /// Bounding rectangle in logical pixels.
49        rect: Rect,
50        /// UTF-8 text string.
51        text: String,
52        /// Typography style.
53        style: TextStyle,
54    },
55    /// Draws a blinking text-input caret aligned to exact rasterized glyph advances.
56    TextCaret {
57        /// Text layout bounding rectangle in logical pixels.
58        text_rect: Rect,
59        /// Input inner content clip rectangle in logical pixels.
60        content_rect: Rect,
61        /// Active input text preceding the caret.
62        text: String,
63        /// Typography style matching the input's `TextRun`.
64        style: TextStyle,
65        /// Caret height in logical pixels.
66        caret_height: f32,
67        /// Caret fill color.
68        color: Color,
69        /// Whether the input wraps across multiple lines.
70        multiline: bool,
71    },
72    /// Blits a decoded RGBA8 image buffer into `rect`.
73    Image {
74        /// Destination bounds.
75        rect: Rect,
76        /// Image pixel buffer.
77        buffer: ImageBuffer,
78        /// Corner radii mask.
79        radius: CornerRadius,
80    },
81    /// Blits a reference-counted pooled RGBA8 pixel buffer into `rect` with zero per-frame copy.
82    SharedImage {
83        /// Destination bounds.
84        rect: Rect,
85        /// Image width in pixels.
86        width: u32,
87        /// Image height in pixels.
88        height: u32,
89        /// Shared RGBA8 pixel bytes (`width * height * 4`).
90        pixels: Arc<Vec<u8>>,
91        /// Corner radii mask.
92        radius: CornerRadius,
93    },
94    /// Draws a straight anti-aliased line segment (used by custom canvases and dividers).
95    Line {
96        /// Start point.
97        from: Point,
98        /// End point.
99        to: Point,
100        /// Line color.
101        color: Color,
102        /// Stroke width.
103        width: f32,
104    },
105    /// Draws a filled anti-aliased circle (used by badges, avatars, spinners, and custom canvases).
106    Circle {
107        /// Center point.
108        center: Point,
109        /// Circle radius.
110        radius: f32,
111        /// Fill color.
112        color: Color,
113    },
114    /// Draws a filled triangle primitive (used by 2D game meshes, spaceships, lasers, and polygons).
115    Triangle {
116        /// First vertex in logical pixels.
117        p0: Point,
118        /// Second vertex in logical pixels.
119        p1: Point,
120        /// Third vertex in logical pixels.
121        p2: Point,
122        /// Fill color.
123        color: Color,
124    },
125    /// Blits a cropped sub-region of an `ImageBuffer` sprite sheet with optional tint color.
126    SpriteRegion {
127        /// Destination bounds in logical pixels.
128        rect: Rect,
129        /// Source sprite-sheet RGBA8 buffer.
130        buffer: ImageBuffer,
131        /// Source pixel sub-rectangle `(x, y, w, h)`.
132        src_rect: Rect,
133        /// Multiplicative tint color (`COLOR_WHITE` for untinted).
134        tint: Color,
135    },
136    /// Pushes an axis-aligned clip rectangle onto the clip stack.
137    PushClip(Rect),
138    /// Pushes a rounded-rectangle clip mask onto the clip stack, balanced by `PopClip`.
139    PushRoundedClip {
140        /// Clip rectangle bounds in logical pixels.
141        rect: Rect,
142        /// Corner radii in logical pixels.
143        radius: CornerRadius,
144    },
145    /// Pops the top clip rectangle from the clip stack.
146    PopClip,
147}
148
149/// Slab-backed zero-String-allocation representation of `DrawCommand` stored inside `PaintFragmentCache`.
150#[derive(Clone, Debug)]
151pub(crate) enum CachedDrawCommand {
152    /// Clears the target surface to `Color`.
153    Clear(Color),
154    /// Draws a rounded or sharp filled rectangle with optional border stroke.
155    FillRoundedRect {
156        /// Bounds in logical pixels.
157        rect: Rect,
158        /// Fill color.
159        color: Color,
160        /// Corner radii.
161        radius: CornerRadius,
162        /// Optional border stroke.
163        border: Border,
164    },
165    /// Draws a two-stop linear gradient inside a rounded rectangle.
166    LinearGradientRect {
167        /// Bounds in logical pixels.
168        rect: Rect,
169        /// Gradient specification.
170        gradient: LinearGradient,
171        /// Corner radii.
172        radius: CornerRadius,
173    },
174    /// Draws a soft drop shadow under a rounded rectangle.
175    BoxShadow {
176        /// Casting box bounds.
177        rect: Rect,
178        /// Corner radii.
179        radius: CornerRadius,
180        /// Shadow parameters.
181        shadow: Shadow,
182    },
183    /// Applies a backdrop blur sampling the previously rendered pixels beneath `rect`.
184    BackdropBlur {
185        /// Output bounds in logical pixels.
186        rect: Rect,
187        /// Corner radii mask in logical pixels.
188        radius: CornerRadius,
189        /// Gaussian blur radius in logical pixels.
190        blur_radius: f32,
191    },
192    /// Draws a laid-out text run backed by byte slice `[text_start..text_start + text_len]` in `PaintFragmentCache::text_slab`.
193    TextRun {
194        /// Bounding rectangle in logical pixels.
195        rect: Rect,
196        /// Start UTF-8 byte offset inside `text_slab`.
197        text_start: u32,
198        /// UTF-8 byte length inside `text_slab`.
199        text_len: u32,
200        /// Typography style.
201        style: TextStyle,
202    },
203    /// Draws a blinking text-input caret backed by byte slice `[text_start..text_start + text_len]` in `PaintFragmentCache::text_slab`.
204    TextCaret {
205        /// Text layout bounding rectangle in logical pixels.
206        text_rect: Rect,
207        /// Input inner content clip rectangle in logical pixels.
208        content_rect: Rect,
209        /// Start UTF-8 byte offset inside `text_slab`.
210        text_start: u32,
211        /// UTF-8 byte length inside `text_slab`.
212        text_len: u32,
213        /// Typography style matching the input's `TextRun`.
214        style: TextStyle,
215        /// Caret height in logical pixels.
216        caret_height: f32,
217        /// Caret fill color.
218        color: Color,
219        /// Whether the input wraps across multiple lines.
220        multiline: bool,
221    },
222    /// Blits a decoded RGBA8 image buffer into `rect`.
223    Image {
224        /// Destination bounds.
225        rect: Rect,
226        /// Image pixel buffer.
227        buffer: ImageBuffer,
228        /// Corner radii mask.
229        radius: CornerRadius,
230    },
231    /// Blits a reference-counted pooled RGBA8 pixel buffer into `rect` with zero per-frame copy.
232    SharedImage {
233        /// Destination bounds.
234        rect: Rect,
235        /// Image width in pixels.
236        width: u32,
237        /// Image height in pixels.
238        height: u32,
239        /// Shared RGBA8 pixel bytes (`width * height * 4`).
240        pixels: Arc<Vec<u8>>,
241        /// Corner radii mask.
242        radius: CornerRadius,
243    },
244    /// Draws a straight anti-aliased line segment.
245    Line {
246        /// Start point.
247        from: Point,
248        /// End point.
249        to: Point,
250        /// Line color.
251        color: Color,
252        /// Stroke width.
253        width: f32,
254    },
255    /// Draws a filled anti-aliased circle.
256    Circle {
257        /// Center point.
258        center: Point,
259        /// Circle radius.
260        radius: f32,
261        /// Fill color.
262        color: Color,
263    },
264    /// Draws a filled triangle primitive.
265    Triangle {
266        /// First vertex in logical pixels.
267        p0: Point,
268        /// Second vertex in logical pixels.
269        p1: Point,
270        /// Third vertex in logical pixels.
271        p2: Point,
272        /// Fill color.
273        color: Color,
274    },
275    /// Blits a cropped sub-region of an `ImageBuffer` sprite sheet with optional tint color.
276    SpriteRegion {
277        /// Destination bounds in logical pixels.
278        rect: Rect,
279        /// Source sprite-sheet RGBA8 buffer.
280        buffer: ImageBuffer,
281        /// Source pixel sub-rectangle `(x, y, w, h)`.
282        src_rect: Rect,
283        /// Multiplicative tint color.
284        tint: Color,
285    },
286    /// Pushes an axis-aligned clip rectangle onto the clip stack.
287    PushClip(Rect),
288    /// Pushes a rounded-rectangle clip mask onto the clip stack, balanced by `PopClip`.
289    PushRoundedClip {
290        /// Clip rectangle bounds in logical pixels.
291        rect: Rect,
292        /// Corner radii in logical pixels.
293        radius: CornerRadius,
294    },
295    /// Pops the top clip rectangle from the clip stack.
296    PopClip,
297}