cursive/src/event.rs

33 lines
973 B
Rust
Raw Normal View History

2015-05-15 19:16:58 +00:00
//! User-input events and their effects.
use std::rc::Rc;
use ::Cursive;
use view::ViewPath;
/// Callback is a function that can be triggered by an event.
/// It has a mutable access to the cursive root.
pub type Callback = Box<Fn(&mut Cursive, &ViewPath)>;
/// Answer to an event notification.
/// The event can be consumed or ignored.
pub enum EventResult {
/// The event was ignored. The parent can keep handling it.
Ignored,
/// The event was consumed. An optionnal callback to run is attached.
Consumed(Option<Rc<Callback>>, ViewPath),
}
2015-05-19 02:41:35 +00:00
impl EventResult {
2015-05-20 18:11:55 +00:00
/// Convenient method to create EventResult::Consumed
/// from the given callback and empty ViewPath.
2015-05-19 02:41:35 +00:00
pub fn callback(cb: Rc<Callback>) -> Self {
EventResult::Consumed(Some(cb), ViewPath::new())
}
2015-05-20 18:11:55 +00:00
/// Convenient method to create EventResult::Consumed with no callback.
2015-05-19 02:41:35 +00:00
pub fn consume() -> Self {
EventResult::Consumed(None, ViewPath::new())
}
}