tessera_ui_basic_components/pipelines/image_vector/
command.rs1use std::{
2 hash::{Hash, Hasher},
3 sync::Arc,
4};
5
6use tessera_ui::{Color, DrawCommand};
7
8#[repr(C)]
10#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
11pub struct ImageVectorVertex {
12 pub position: [f32; 2],
14 pub color: Color,
16}
17
18#[derive(Debug, Clone)]
20pub struct ImageVectorData {
21 pub viewport_width: f32,
23 pub viewport_height: f32,
25 pub vertices: Arc<Vec<ImageVectorVertex>>,
27 pub indices: Arc<Vec<u32>>,
29}
30
31impl ImageVectorData {
32 pub fn new(
34 viewport_width: f32,
35 viewport_height: f32,
36 vertices: Arc<Vec<ImageVectorVertex>>,
37 indices: Arc<Vec<u32>>,
38 ) -> Self {
39 Self {
40 viewport_width,
41 viewport_height,
42 vertices,
43 indices,
44 }
45 }
46}
47
48impl PartialEq for ImageVectorData {
49 fn eq(&self, other: &Self) -> bool {
50 self.viewport_width.to_bits() == other.viewport_width.to_bits()
51 && self.viewport_height.to_bits() == other.viewport_height.to_bits()
52 && Arc::ptr_eq(&self.vertices, &other.vertices)
53 && Arc::ptr_eq(&self.indices, &other.indices)
54 }
55}
56
57impl Eq for ImageVectorData {}
58
59impl Hash for ImageVectorData {
60 fn hash<H: Hasher>(&self, state: &mut H) {
61 state.write_u32(self.viewport_width.to_bits());
62 state.write_u32(self.viewport_height.to_bits());
63 state.write_usize(Arc::as_ptr(&self.vertices) as usize);
64 state.write_usize(Arc::as_ptr(&self.indices) as usize);
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
70pub enum VectorTintMode {
71 #[default]
75 Multiply,
76 Solid,
79}
80
81#[derive(Debug, Clone, PartialEq)]
83pub struct ImageVectorCommand {
84 pub data: Arc<ImageVectorData>,
86 pub tint: Color,
88 pub tint_mode: VectorTintMode,
90 pub rotation: f32,
92}
93
94impl DrawCommand for ImageVectorCommand {}