Add mouse::Button to mouse::Click
This commit is contained in:
parent
630f3525dd
commit
9edd805c02
3 changed files with 17 additions and 4 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
//! Track mouse clicks.
|
//! Track mouse clicks.
|
||||||
|
use crate::mouse::Button;
|
||||||
use crate::time::Instant;
|
use crate::time::Instant;
|
||||||
use crate::Point;
|
use crate::Point;
|
||||||
|
|
||||||
|
|
@ -6,6 +7,7 @@ use crate::Point;
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Click {
|
pub struct Click {
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
|
button: Button,
|
||||||
position: Point,
|
position: Point,
|
||||||
time: Instant,
|
time: Instant,
|
||||||
}
|
}
|
||||||
|
|
@ -36,11 +38,17 @@ impl Kind {
|
||||||
impl Click {
|
impl Click {
|
||||||
/// Creates a new [`Click`] with the given position and previous last
|
/// Creates a new [`Click`] with the given position and previous last
|
||||||
/// [`Click`].
|
/// [`Click`].
|
||||||
pub fn new(position: Point, previous: Option<Click>) -> Click {
|
pub fn new(
|
||||||
|
position: Point,
|
||||||
|
button: Button,
|
||||||
|
previous: Option<Click>,
|
||||||
|
) -> Click {
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
|
|
||||||
let kind = if let Some(previous) = previous {
|
let kind = if let Some(previous) = previous {
|
||||||
if previous.is_consecutive(position, time) {
|
if previous.is_consecutive(position, time)
|
||||||
|
&& button == previous.button
|
||||||
|
{
|
||||||
previous.kind.next()
|
previous.kind.next()
|
||||||
} else {
|
} else {
|
||||||
Kind::Single
|
Kind::Single
|
||||||
|
|
@ -51,6 +59,7 @@ impl Click {
|
||||||
|
|
||||||
Click {
|
Click {
|
||||||
kind,
|
kind,
|
||||||
|
button,
|
||||||
position,
|
position,
|
||||||
time,
|
time,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1056,6 +1056,7 @@ impl<Message> Update<Message> {
|
||||||
|
|
||||||
let click = mouse::Click::new(
|
let click = mouse::Click::new(
|
||||||
cursor_position,
|
cursor_position,
|
||||||
|
mouse::Button::Left,
|
||||||
state.last_click,
|
state.last_click,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -656,8 +656,11 @@ where
|
||||||
cursor_position.x - text_bounds.x - alignment_offset
|
cursor_position.x - text_bounds.x - alignment_offset
|
||||||
};
|
};
|
||||||
|
|
||||||
let click =
|
let click = mouse::Click::new(
|
||||||
mouse::Click::new(cursor_position, state.last_click);
|
cursor_position,
|
||||||
|
mouse::Button::Left,
|
||||||
|
state.last_click,
|
||||||
|
);
|
||||||
|
|
||||||
match click.kind() {
|
match click.kind() {
|
||||||
click::Kind::Single => {
|
click::Kind::Single => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue