Skip to main content

wgpu_shapes/shape/
oval.rs

1use wgpu::Color;
2
3use crate::render::instance::Instance;
4use crate::shape::shapes::{BasicShape, BasicShapeData};
5
6/// Shape which can be render and created which though the [oval](shape_renderer::ShapeRenderer::oval)
7pub struct Oval {
8    pub(crate) data: BasicShapeData,
9    pub(crate) detail: u32,
10}
11
12impl BasicShape for Oval {
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}
47
48impl Oval {
49    ///segment count of the oval
50    ///
51    /// higher -> smoother circle
52    pub fn segment_count(&mut self, segment_count: u32) -> &mut Self {
53        self.detail = segment_count;
54        self
55    }
56}
57
58impl Default for Oval {
59    fn default() -> Self {
60        Oval {
61            data: Default::default(),
62            detail: 128,
63        }
64    }
65}