mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add EnableableView
This commit is contained in:
parent
193f098ee0
commit
edeb7a8c13
41
src/views/enableable_view.rs
Normal file
41
src/views/enableable_view.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use event::{Event, EventResult};
|
||||
use view::{View, ViewWrapper};
|
||||
use {Printer, With};
|
||||
|
||||
/// Wrapper around another view that can be enabled/disabled at will.
|
||||
///
|
||||
/// When disabled, all child views will be disabled and will stop receiving events.
|
||||
pub struct EnableableView<V> {
|
||||
view: V,
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
impl<V> EnableableView<V> {
|
||||
/// Creates a new `EnableableView` around `view`.
|
||||
///
|
||||
/// It will be enabled by default.
|
||||
pub fn new(view: V) -> Self {
|
||||
EnableableView {
|
||||
view,
|
||||
enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
impl_enabled!(self.enabled);
|
||||
}
|
||||
|
||||
impl<V: View> ViewWrapper for EnableableView<V> {
|
||||
wrap_impl!(self.view: V);
|
||||
|
||||
fn wrap_on_event(&mut self, event: Event) -> EventResult {
|
||||
if self.enabled {
|
||||
self.view.on_event(event)
|
||||
} else {
|
||||
EventResult::Ignored
|
||||
}
|
||||
}
|
||||
|
||||
fn wrap_draw(&self, printer: &Printer) {
|
||||
self.view.draw(&printer.enabled(self.enabled));
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@ mod checkbox;
|
||||
mod dialog;
|
||||
mod dummy;
|
||||
mod edit_view;
|
||||
mod enableable_view;
|
||||
mod hideable_view;
|
||||
mod id_view;
|
||||
mod layer;
|
||||
@ -71,6 +72,7 @@ pub use self::checkbox::Checkbox;
|
||||
pub use self::dialog::{Dialog, DialogFocus};
|
||||
pub use self::dummy::DummyView;
|
||||
pub use self::edit_view::EditView;
|
||||
pub use self::enableable_view::EnableableView;
|
||||
pub use self::hideable_view::HideableView;
|
||||
pub use self::id_view::{IdView, ViewRef};
|
||||
pub use self::layer::Layer;
|
||||
|
Loading…
Reference in New Issue
Block a user