Skip to main content

wgpu_shapes/shape/
rect.rs

1use crate::render::instance::Instance;
2use wgpu::Color;
3
4use crate::shape::shapes::{BasicShape, BasicShapeData};
5
6/// Shape which can be render and created which though the [rect](shape_renderer::ShapeRenderer::rect)
7#[derive(Default)]
8pub struct Rect {
9    pub(crate) data: BasicShapeData,
10}
11
12impl BasicShape for Rect {
13    fn scale(&mut self, width: f32, height: f32) -> &mut Self {
14        self.data.scale = (width, height);
15        self
16    }
17
18    fn pos(&mut self, x: f32, y: f32) -> &mut Self {
19        self.data.pos = (x, y);
20        self
21    }
22
23    fn rotation(&mut self, rotation: f32) -> &mut Self {
24        self.data.rotation = rotation;
25        self
26    }
27
28    fn color(&mut self, red: f32, green: f32, blue: f32) -> &mut Self {
29        self.data.color = (red, green, blue);
30        self
31    }
32
33    fn color_from_color(&mut self, color: Color) -> &mut Self {
34        self.data.color = (color.r as f32, color.g as f32, color.b as f32);
35        self
36    }
37
38    fn layer(&mut self, layer: u16) -> &mut Self {
39        self.data.layer = layer;
40        self
41    }
42
43    fn to_instance(&self) -> Instance {
44        (&self.data).into()
45    }
46}