From 212edcb18c4bbe402d5cae82fa1e61ff560071ce Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sun, 24 Mar 2019 16:30:48 +0100 Subject: [PATCH] implement modal view wrapper this wrapper swallows all events that were not processed by the child view. it can be used for modal dialogs. --- src/ui/mod.rs | 1 + src/ui/modal.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/ui/modal.rs diff --git a/src/ui/mod.rs b/src/ui/mod.rs index eab8703..bf4a8dc 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,5 +1,6 @@ pub mod layout; pub mod listview; +pub mod modal; pub mod playlists; pub mod queue; pub mod search; diff --git a/src/ui/modal.rs b/src/ui/modal.rs new file mode 100644 index 0000000..515915d --- /dev/null +++ b/src/ui/modal.rs @@ -0,0 +1,22 @@ +use cursive::event::{Event, EventResult}; +use cursive::view::{View, ViewWrapper}; + +pub struct Modal { + inner: T, +} + +impl Modal { + pub fn new(inner: T) -> Self { + Modal { inner: inner } + } +} + +impl ViewWrapper for Modal { + 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), + } + } +}