Files
ncspot/src/ui/modal.rs
Henrik Friedrichsen 1edf28a165 make contextmenu aware of commands
e.g. to process vim-like keybindings for navigation

fixes #108, fixes #157, fixes #178, fixes #199, fixes #250
2020-08-23 20:44:03 +02:00

36 lines
837 B
Rust

use cursive::event::{Event, EventResult};
use cursive::view::{View, ViewWrapper};
pub struct Modal<T: View> {
block_events: bool,
inner: T,
}
impl<T: View> Modal<T> {
pub fn new(inner: T) -> Self {
Modal {
block_events: true,
inner,
}
}
pub fn new_ext(inner: T) -> Self {
Modal {
block_events: false,
inner,
}
}
}
impl<T: View> ViewWrapper for Modal<T> {
wrap_impl!(self.inner: T);
fn wrap_on_event(&mut self, ch: Event) -> EventResult {
match self.inner.on_event(ch) {
EventResult::Consumed(cb) => EventResult::Consumed(cb),
_ => match self.block_events {
true => EventResult::Consumed(None),
false => EventResult::Ignored,
},
}
}
}