Add MouseEvent::Hold

This commit is contained in:
Alexandre Bury 2017-10-10 17:49:53 -07:00
parent a68fd3493b
commit c64e7dd7b3

View File

@ -17,7 +17,6 @@
use Cursive; use Cursive;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
use vec::Vec2; use vec::Vec2;
/// Callback is a function that can be triggered by an event. /// Callback is a function that can be triggered by an event.
@ -208,9 +207,13 @@ pub enum MouseButton {
/// The right button, for special actions. /// The right button, for special actions.
Right, Right,
/// Fourth button if the mouse supports it.
Button4,
/// Fifth button if the mouse supports it.
Button5,
// TODO: handle more buttons? // TODO: handle more buttons?
#[doc(hidden)] #[doc(hidden)] Other,
Other,
} }
/// Represents a possible event sent by the mouse. /// Represents a possible event sent by the mouse.
@ -220,12 +223,28 @@ pub enum MouseEvent {
Press(MouseButton), Press(MouseButton),
/// A button was released. /// A button was released.
Release(MouseButton), Release(MouseButton),
/// A button is being held.
Hold(MouseButton),
/// The wheel was moved up. /// The wheel was moved up.
WheelUp, WheelUp,
/// The wheel was moved down. /// The wheel was moved down.
WheelDown, WheelDown,
} }
impl MouseEvent {
/// Returns the button used by this event, if any.
///
/// Returns `None` if `self` is `WheelUp` or `WheelDown`.
pub fn button(&self) -> Option<MouseButton> {
match *self {
MouseEvent::Press(btn) |
MouseEvent::Release(btn) |
MouseEvent::Hold(btn) => Some(btn),
_ => None,
}
}
}
/// Represents an event as seen by the application. /// Represents an event as seen by the application.
#[derive(PartialEq, Eq, Clone, Hash, Debug)] #[derive(PartialEq, Eq, Clone, Hash, Debug)]
pub enum Event { pub enum Event {
@ -235,9 +254,7 @@ pub enum Event {
/// Event fired regularly when a auto-refresh is set. /// Event fired regularly when a auto-refresh is set.
Refresh, Refresh,
// TODO: have Char(modifier, char) and Key(modifier, key) enums? // TODO: have Char(modifier, char) and Key(modifier, key) enums?
/// A character was entered (includes numbers, punctuation, ...). /// A character was entered (includes numbers, punctuation, ...).
Char(char), Char(char),
/// A character was entered with the Ctrl key pressed. /// A character was entered with the Ctrl key pressed.