2015-05-15 19:16:58 +00:00
|
|
|
//! User-input events and their effects.
|
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2015-05-16 00:56:38 +00:00
|
|
|
use ::Cursive;
|
|
|
|
use view::ViewPath;
|
|
|
|
|
2015-05-15 00:41:17 +00:00
|
|
|
/// Callback is a function that can be triggered by an event.
|
|
|
|
/// It has a mutable access to the cursive root.
|
2015-05-16 00:56:38 +00:00
|
|
|
pub type Callback = Box<Fn(&mut Cursive, &ViewPath)>;
|
2015-05-15 00:41:17 +00:00
|
|
|
|
|
|
|
/// 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.
|
2015-05-16 00:56:38 +00:00
|
|
|
Consumed(Option<Rc<Callback>>, ViewPath),
|
2015-05-15 00:41:17 +00:00
|
|
|
}
|
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())
|
|
|
|
}
|
|
|
|
}
|