Struct cursive_core::views::EnableableView
source · pub struct EnableableView<V> { /* private fields */ }
Expand description
Wrapper around another view that can be enabled/disabled at will.
When disabled, all child views will be disabled and will stop receiving events.
Examples
use cursive_core::Cursive;
use cursive_core::views::{Button, EnableableView, Checkbox, LinearLayout};
use cursive_core::traits::Nameable;
let mut siv = Cursive::new();
siv.add_layer(LinearLayout::vertical()
.child(EnableableView::new(Checkbox::new()).with_name("my_view"))
.child(Button::new("Toggle", |s| {
s.call_on_name("my_view", |v: &mut EnableableView<Checkbox>| {
// This will disable (or re-enable) the checkbox, preventing the user from
// interacting with it.
v.set_enabled(!v.is_enabled());
});
}))
);
Implementations§
source§impl<V> EnableableView<V>
impl<V> EnableableView<V>
sourcepub fn new(view: V) -> Self
pub fn new(view: V) -> Self
Creates a new EnableableView
around view
.
It will be enabled by default.
sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Enable or disable this view.
sourcepub fn with_enabled(self, is_enabled: bool) -> Self
pub fn with_enabled(self, is_enabled: bool) -> Self
Enable or disable this view.
Chainable variant.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true
if this view is enabled.
sourcepub fn get_inner_mut(&mut self) -> &mut V
pub fn get_inner_mut(&mut self) -> &mut V
Gets mutable access to the inner view.
Trait Implementations§
source§impl<V> Default for EnableableView<V>where
V: Default,
impl<V> Default for EnableableView<V>where
V: Default,
source§impl<V: View> ViewWrapper for EnableableView<V>
impl<V: View> ViewWrapper for EnableableView<V>
source§fn with_view<F, R>(&self, f: F) -> Option<R>where
F: FnOnce(&Self::V) -> R,
fn with_view<F, R>(&self, f: F) -> Option<R>where
F: FnOnce(&Self::V) -> R,
Runs a function on the inner view, returning the result. Read more
source§fn with_view_mut<F, R>(&mut self, f: F) -> Option<R>where
F: FnOnce(&mut Self::V) -> R,
fn with_view_mut<F, R>(&mut self, f: F) -> Option<R>where
F: FnOnce(&mut Self::V) -> R,
Runs a function on the inner view, returning the result. Read more
source§fn into_inner(self) -> Result<Self::V, Self>where
Self::V: Sized,
fn into_inner(self) -> Result<Self::V, Self>where
Self::V: Sized,
Attempts to retrieve the inner view.
source§fn wrap_on_event(&mut self, event: Event) -> EventResult
fn wrap_on_event(&mut self, event: Event) -> EventResult
Wraps the
on_event
method.source§fn wrap_required_size(&mut self, req: Vec2) -> Vec2
fn wrap_required_size(&mut self, req: Vec2) -> Vec2
Wraps the
required_size
method.source§fn wrap_layout(&mut self, size: Vec2)
fn wrap_layout(&mut self, size: Vec2)
Wraps the
layout
method.source§fn wrap_take_focus(
&mut self,
source: Direction
) -> Result<EventResult, CannotFocus>
fn wrap_take_focus(
&mut self,
source: Direction
) -> Result<EventResult, CannotFocus>
Wraps the
take_focus
method.source§fn wrap_call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
fn wrap_call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
Wraps the
find
method.source§fn wrap_focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
fn wrap_focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
Wraps the
focus_view
method.source§fn wrap_needs_relayout(&self) -> bool
fn wrap_needs_relayout(&self) -> bool
Wraps the
needs_relayout
method.source§fn wrap_important_area(&self, size: Vec2) -> Rect
fn wrap_important_area(&self, size: Vec2) -> Rect
Wraps the
important_area
method.