Skip to content

Commit

Permalink
Add Mouse Button to Click struct
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Apr 30, 2024
1 parent 24501fd commit 750ecd9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions core/src/mouse/click.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Track mouse clicks.
use crate::mouse::Button;
use crate::time::Instant;
use crate::Point;

/// A mouse click.
#[derive(Debug, Clone, Copy)]
pub struct Click {
kind: Kind,
button: Button,
position: Point,
time: Instant,
}
Expand Down Expand Up @@ -36,11 +38,11 @@ impl Kind {
impl Click {
/// Creates a new [`Click`] with the given position and previous last
/// [`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 kind = if let Some(previous) = previous {
if previous.is_consecutive(position, time) {
if previous.is_consecutive(position, time) && button == previous.button {
previous.kind.next()
} else {
Kind::Single
Expand All @@ -51,6 +53,7 @@ impl Click {

Click {
kind,
button,
position,
time,
}
Expand Down
1 change: 1 addition & 0 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ impl Update {

let click = mouse::Click::new(
cursor_position,
mouse::Button::Left,
state.last_click,
);

Expand Down
2 changes: 1 addition & 1 deletion widget/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ where
let target = cursor_position.x - text_layout.bounds().x;

let click =
mouse::Click::new(cursor_position, state.last_click);
mouse::Click::new(cursor_position, mouse::Button::Left, state.last_click);

match click.kind() {
click::Kind::Single => {
Expand Down

0 comments on commit 750ecd9

Please sign in to comment.