Merge pull request #2758 from airstrike/mouse-transformation
Implement `Mul<Transformation>` for `mouse::Cursor` and `mouse::Click`
This commit is contained in:
commit
9b959d3e80
2 changed files with 32 additions and 2 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
//! Track mouse clicks.
|
//! Track mouse clicks.
|
||||||
use crate::mouse::Button;
|
use crate::mouse::Button;
|
||||||
use crate::time::Instant;
|
use crate::time::Instant;
|
||||||
use crate::Point;
|
use crate::{Point, Transformation};
|
||||||
|
|
||||||
|
use std::ops::Mul;
|
||||||
|
|
||||||
/// A mouse click.
|
/// A mouse click.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
|
@ -88,3 +90,16 @@ impl Click {
|
||||||
.unwrap_or(false)
|
.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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use crate::{Point, Rectangle, Vector};
|
use crate::{Point, Rectangle, Transformation, Vector};
|
||||||
|
|
||||||
|
use std::ops::Mul;
|
||||||
|
|
||||||
/// The mouse cursor state.
|
/// The mouse cursor state.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||||
|
|
@ -50,3 +52,16 @@ impl Cursor {
|
||||||
self.position_over(bounds).is_some()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue