Merge pull request #2758 from airstrike/mouse-transformation

Implement `Mul<Transformation>` for `mouse::Cursor` and `mouse::Click`
This commit is contained in:
Héctor 2025-01-28 18:47:28 +01:00 committed by GitHub
commit 9b959d3e80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -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,
}
}
}

View file

@ -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)
}
}
}
}