diff options
author | 2025-01-28 18:47:28 +0100 | |
---|---|---|
committer | 2025-01-28 18:47:28 +0100 | |
commit | 9b959d3e8058a471ce59e42d97909e03845fad90 (patch) | |
tree | 02bc9e265bf38da575cb037f4ad5c215395bc3e1 /core | |
parent | 12c9277c7cdee702266ae4e11da9c7dd370b75d7 (diff) | |
parent | 6576184baed72218005ccd3e0ad008465ad5dbb8 (diff) | |
download | iced-9b959d3e8058a471ce59e42d97909e03845fad90.tar.gz iced-9b959d3e8058a471ce59e42d97909e03845fad90.tar.bz2 iced-9b959d3e8058a471ce59e42d97909e03845fad90.zip |
Merge pull request #2758 from airstrike/mouse-transformation
Implement `Mul<Transformation>` for `mouse::Cursor` and `mouse::Click`
Diffstat (limited to 'core')
-rw-r--r-- | core/src/mouse/click.rs | 17 | ||||
-rw-r--r-- | core/src/mouse/cursor.rs | 17 |
2 files changed, 32 insertions, 2 deletions
diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index dd1c84cd..12039d79 100644 --- a/core/src/mouse/click.rs +++ b/core/src/mouse/click.rs @@ -1,7 +1,9 @@ //! Track mouse clicks. use crate::mouse::Button; use crate::time::Instant; -use crate::Point; +use crate::{Point, Transformation}; + +use std::ops::Mul; /// A mouse click. #[derive(Debug, Clone, Copy)] @@ -88,3 +90,16 @@ impl Click { .unwrap_or(false) } } + +impl Mul<Transformation> for Click { + type Output = Click; + + fn mul(self, transformation: Transformation) -> Click { + Click { + kind: self.kind, + button: self.button, + position: self.position * transformation, + time: self.time, + } + } +} diff --git a/core/src/mouse/cursor.rs b/core/src/mouse/cursor.rs index 203526e9..616cd315 100644 --- a/core/src/mouse/cursor.rs +++ b/core/src/mouse/cursor.rs @@ -1,4 +1,6 @@ -use crate::{Point, Rectangle, Vector}; +use crate::{Point, Rectangle, Transformation, Vector}; + +use std::ops::Mul; /// The mouse cursor state. #[derive(Debug, Clone, Copy, PartialEq, Default)] @@ -50,3 +52,16 @@ impl Cursor { self.position_over(bounds).is_some() } } + +impl Mul<Transformation> for Cursor { + type Output = Self; + + fn mul(self, transformation: Transformation) -> Self { + match self { + Cursor::Unavailable => Cursor::Unavailable, + Cursor::Available(point) => { + Cursor::Available(point * transformation) + } + } + } +} |