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)]
9#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
10pub struct ImageVectorVertex {
11 pub position: [f32; 2],
12 pub color: Color,
13}
14
15#[derive(Debug, Clone)]
16pub struct ImageVectorData {
17 pub viewport_width: f32,
18 pub viewport_height: f32,
19 pub vertices: Arc<Vec<ImageVectorVertex>>,
20 pub indices: Arc<Vec<u32>>,
21}
22
23impl ImageVectorData {
24 pub fn new(
25 viewport_width: f32,
26 viewport_height: f32,
27 vertices: Arc<Vec<ImageVectorVertex>>,
28 indices: Arc<Vec<u32>>,
29 ) -> Self {
30 Self {
31 viewport_width,
32 viewport_height,
33 vertices,
34 indices,
35 }
36 }
37}
38
39impl PartialEq for ImageVectorData {
40 fn eq(&self, other: &Self) -> bool {
41 self.viewport_width.to_bits() == other.viewport_width.to_bits()
42 && self.viewport_height.to_bits() == other.viewport_height.to_bits()
43 && Arc::ptr_eq(&self.vertices, &other.vertices)
44 && Arc::ptr_eq(&self.indices, &other.indices)
45 }
46}
47
48impl Eq for ImageVectorData {}
49
50impl Hash for ImageVectorData {
51 fn hash<H: Hasher>(&self, state: &mut H) {
52 state.write_u32(self.viewport_width.to_bits());
53 state.write_u32(self.viewport_height.to_bits());
54 state.write_usize(Arc::as_ptr(&self.vertices) as usize);
55 state.write_usize(Arc::as_ptr(&self.indices) as usize);
56 }
57}
58
59#[derive(Debug, Clone, PartialEq)]
60pub struct ImageVectorCommand {
61 pub data: Arc<ImageVectorData>,
62 pub tint: Color,
63}
64
65impl DrawCommand for ImageVectorCommand {}