Skip to content

Commit

Permalink
Add method to return character from char event. (#744)
Browse files Browse the repository at this point in the history
* Add method to return character from char event.

* return the char for AltChar and CtrlChar events also

---------

Co-authored-by: tidub <57918941+tidub@users.noreply.github.com>
  • Loading branch information
timdubbins and timdubbins committed Sep 10, 2023
1 parent c4babaa commit ac4ed1c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cursive-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,16 @@ pub enum Event {
}

impl Event {
/// Returns the character, if `self` is a char event.
pub fn char(&self) -> Option<char> {
match *self {
Event::Char(c) => Some(c),
Event::AltChar(c) => Some(c),
Event::CtrlChar(c) => Some(c),
_ => None,
}
}

/// Returns the position of the mouse, if `self` is a mouse event.
pub fn mouse_position(&self) -> Option<Vec2> {
if let Event::Mouse { position, .. } = *self {
Expand All @@ -542,7 +552,7 @@ impl Event {
}
}

/// Returns a mutable reference to the position of the mouse/
/// Returns a mutable reference to the position of the mouse.
///
/// Returns `None` if `self` is not a mouse event.
pub fn mouse_position_mut(&mut self) -> Option<&mut Vec2> {
Expand Down

0 comments on commit ac4ed1c

Please sign in to comment.