tessera_ui_basic_components/pipelines/checkmark/
command.rs

1use tessera_ui::{Color, DrawCommand};
2
3/// Command for drawing an animated checkmark
4#[derive(Debug, Clone)]
5pub struct CheckmarkCommand {
6    /// Color of the checkmark stroke
7    pub color: Color,
8    /// Width of the checkmark stroke in pixels
9    pub stroke_width: f32,
10    /// Animation progress from 0.0 (not drawn) to 1.0 (fully drawn)
11    pub progress: f32,
12    /// Padding around the checkmark within its bounds
13    pub padding: [f32; 2], // [horizontal, vertical]
14}
15
16impl CheckmarkCommand {
17    /// Create a new checkmark command with default values
18    pub fn new() -> Self {
19        Self {
20            color: Color::new(0.0, 0.6, 0.0, 1.0), // Green checkmark
21            stroke_width: 5.0,
22            progress: 1.0, // Fully drawn by default
23            padding: [2.0, 2.0],
24        }
25    }
26
27    /// Set the color of the checkmark
28    pub fn with_color(mut self, color: Color) -> Self {
29        self.color = color;
30        self
31    }
32
33    /// Set the stroke width of the checkmark
34    pub fn with_stroke_width(mut self, width: f32) -> Self {
35        self.stroke_width = width;
36        self
37    }
38
39    /// Set the animation progress (0.0 to 1.0)
40    pub fn with_progress(mut self, progress: f32) -> Self {
41        self.progress = progress.clamp(0.0, 1.0);
42        self
43    }
44
45    /// Set the padding around the checkmark
46    pub fn with_padding(mut self, horizontal: f32, vertical: f32) -> Self {
47        self.padding = [horizontal, vertical];
48        self
49    }
50}
51
52impl Default for CheckmarkCommand {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58impl DrawCommand for CheckmarkCommand {
59    fn barrier(&self) -> Option<tessera_ui::BarrierRequirement> {
60        // No specific barrier requirements for checkmark commands
61        None
62    }
63}