implement modal view wrapper

this wrapper swallows all events that were not processed by the child view. it
can be used for modal dialogs.
This commit is contained in:
Henrik Friedrichsen
2019-03-24 16:30:48 +01:00
parent 43a1dc654f
commit 212edcb18c
2 changed files with 23 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
pub mod layout;
pub mod listview;
pub mod modal;
pub mod playlists;
pub mod queue;
pub mod search;

22
src/ui/modal.rs Normal file
View File

@@ -0,0 +1,22 @@
use cursive::event::{Event, EventResult};
use cursive::view::{View, ViewWrapper};
pub struct Modal<T: View> {
inner: T,
}
impl<T: View> Modal<T> {
pub fn new(inner: T) -> Self {
Modal { inner: 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),
_ => EventResult::Consumed(None),
}
}
}