summaryrefslogtreecommitdiffstats
path: root/core/src/pixels.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-07-12 21:40:46 +0200
committerLibravatar GitHub <noreply@github.com>2024-07-12 21:40:46 +0200
commit8cadd3b99485c344feb18b774c8e6fd6c1ea9dd7 (patch)
tree826fa9e0acdf3a4e003f882c94ff24a4ac9f50e4 /core/src/pixels.rs
parentbe06060117da061ad8cad94ab0830c06def6b147 (diff)
parent3f480d3d18c41188bf40ead0a3dc4497316f11ae (diff)
downloadiced-8cadd3b99485c344feb18b774c8e6fd6c1ea9dd7.tar.gz
iced-8cadd3b99485c344feb18b774c8e6fd6c1ea9dd7.tar.bz2
iced-8cadd3b99485c344feb18b774c8e6fd6c1ea9dd7.zip
Merge pull request #2504 from iced-rs/view-ergonomics
Improved `view` ergonomics
Diffstat (limited to 'core/src/pixels.rs')
-rw-r--r--core/src/pixels.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/core/src/pixels.rs b/core/src/pixels.rs
index 425c0028..f5550a10 100644
--- a/core/src/pixels.rs
+++ b/core/src/pixels.rs
@@ -6,7 +6,7 @@
/// (e.g. `impl Into<Pixels>`) and, since `Pixels` implements `From` both for
/// `f32` and `u16`, you should be able to provide both integers and float
/// literals as needed.
-#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
pub struct Pixels(pub f32);
impl From<f32> for Pixels {
@@ -27,6 +27,30 @@ impl From<Pixels> for f32 {
}
}
+impl std::ops::Add for Pixels {
+ type Output = Pixels;
+
+ fn add(self, rhs: Self) -> Self {
+ Pixels(self.0 + rhs.0)
+ }
+}
+
+impl std::ops::Add<f32> for Pixels {
+ type Output = Pixels;
+
+ fn add(self, rhs: f32) -> Self {
+ Pixels(self.0 + rhs)
+ }
+}
+
+impl std::ops::Mul for Pixels {
+ type Output = Pixels;
+
+ fn mul(self, rhs: Self) -> Self {
+ Pixels(self.0 * rhs.0)
+ }
+}
+
impl std::ops::Mul<f32> for Pixels {
type Output = Pixels;