iced_core/
pixels.rs
1#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
10pub struct Pixels(pub f32);
11
12impl Pixels {
13 pub const ZERO: Self = Self(0.0);
15}
16
17impl From<f32> for Pixels {
18 fn from(amount: f32) -> Self {
19 Self(amount)
20 }
21}
22
23impl From<u32> for Pixels {
24 fn from(amount: u32) -> Self {
25 Self(amount as f32)
26 }
27}
28
29impl From<Pixels> for f32 {
30 fn from(pixels: Pixels) -> Self {
31 pixels.0
32 }
33}
34
35impl std::ops::Add for Pixels {
36 type Output = Pixels;
37
38 fn add(self, rhs: Self) -> Self {
39 Pixels(self.0 + rhs.0)
40 }
41}
42
43impl std::ops::Add<f32> for Pixels {
44 type Output = Pixels;
45
46 fn add(self, rhs: f32) -> Self {
47 Pixels(self.0 + rhs)
48 }
49}
50
51impl std::ops::Mul for Pixels {
52 type Output = Pixels;
53
54 fn mul(self, rhs: Self) -> Self {
55 Pixels(self.0 * rhs.0)
56 }
57}
58
59impl std::ops::Mul<f32> for Pixels {
60 type Output = Pixels;
61
62 fn mul(self, rhs: f32) -> Self {
63 Pixels(self.0 * rhs)
64 }
65}
66
67impl std::ops::Div for Pixels {
68 type Output = Pixels;
69
70 fn div(self, rhs: Self) -> Self {
71 Pixels(self.0 / rhs.0)
72 }
73}
74
75impl std::ops::Div<f32> for Pixels {
76 type Output = Pixels;
77
78 fn div(self, rhs: f32) -> Self {
79 Pixels(self.0 / rhs)
80 }
81}
82
83impl std::ops::Div<u32> for Pixels {
84 type Output = Pixels;
85
86 fn div(self, rhs: u32) -> Self {
87 Pixels(self.0 / rhs as f32)
88 }
89}