pub struct Button { /* private fields */ }Expand description
Simple text label with a callback when <Enter> is pressed.
A button shows its content in a single line and has a fixed size.
§Examples
use cursive_core::views::Button;
let quit_button = Button::new("Quit", |s| s.quit());Implementations§
Source§impl Button
impl Button
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) -> Button
pub fn with_enabled(self, is_enabled: bool) -> Button
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 new<F, S>(label: S, cb: F) -> Button
pub fn new<F, S>(label: S, cb: F) -> Button
Creates a new button with the given content and callback.
Sourcepub fn new_cb<F>(cb: F) -> Arc<dyn Fn(&mut Cursive) + Sync + Send> ⓘ
pub fn new_cb<F>(cb: F) -> Arc<dyn Fn(&mut Cursive) + Sync + Send> ⓘ
Helper method to store a callback of the correct type for Self::new.
This is mostly useful when using this view in a template.
Sourcepub fn new_with_cb<S>(
label: S,
cb: Arc<dyn Fn(&mut Cursive) + Sync + Send>,
) -> Button
pub fn new_with_cb<S>( label: S, cb: Arc<dyn Fn(&mut Cursive) + Sync + Send>, ) -> Button
Helper method to call Self::new with a variable from a config.
This is mostly useful when writing a cursive blueprint for this view.
Sourcepub fn new_raw<F, S>(label: S, cb: F) -> Button
pub fn new_raw<F, S>(label: S, cb: F) -> Button
Creates a new button without angle brackets.
§Examples
use cursive_core::views::Button;
let button = Button::new_raw("[ Quit ]", |s| s.quit());Sourcepub fn set_callback<F>(&mut self, cb: F)
pub fn set_callback<F>(&mut self, cb: F)
Sets the function to be called when the button is pressed.
Replaces the previous callback.
Sourcepub fn label(&self) -> &str
pub fn label(&self) -> &str
Returns the label for this button.
Includes brackets.
§Examples
let button = Button::new("Quit", |s| s.quit());
assert_eq!(button.label(), "<Quit>");Sourcepub fn set_label<S>(&mut self, label: S)
pub fn set_label<S>(&mut self, label: S)
Sets the label to the given value.
This will include brackets.
§Examples
use cursive_core::views::Button;
let mut button = Button::new("Quit", |s| s.quit());
button.set_label("Escape");Sourcepub fn set_label_raw<S>(&mut self, label: S)
pub fn set_label_raw<S>(&mut self, label: S)
Sets the label exactly to the given value.
This will not include brackets.
Trait Implementations§
Source§impl View for Button
impl View for Button
Source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Source§fn layout(&mut self, size: XY<usize>)
fn layout(&mut self, size: XY<usize>)
Source§fn required_size(&mut self, _: XY<usize>) -> XY<usize>
fn required_size(&mut self, _: XY<usize>) -> XY<usize>
Source§fn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Source§fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, _: Direction) -> Result<EventResult, CannotFocus>
Source§fn important_area(&self, view_size: XY<usize>) -> Rect
fn important_area(&self, view_size: XY<usize>) -> Rect
Source§fn needs_relayout(&self) -> bool
fn needs_relayout(&self) -> bool
Source§fn call_on_any(
&mut self,
_: &Selector<'_>,
_: &mut dyn FnMut(&mut (dyn View + 'static)),
)
fn call_on_any( &mut self, _: &Selector<'_>, _: &mut dyn FnMut(&mut (dyn View + 'static)), )
Source§fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
fn focus_view(&mut self, _: &Selector<'_>) -> Result<EventResult, ViewNotFound>
Auto Trait Implementations§
impl !RefUnwindSafe for Button
impl !UnwindSafe for Button
impl Freeze for Button
impl Send for Button
impl Sync for Button
impl Unpin for Button
impl UnsafeUnpin for Button
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Finder for Twhere
T: View,
impl<T> Finder for Twhere
T: View,
Source§fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
fn call_on_all<V, F>(&mut self, sel: &Selector<'_>, callback: F)
sel. Read moreSource§fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
sel. Read moreSource§fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
call_on with a view::Selector::Name.Source§impl<T> IntoBoxedView for Twhere
T: View,
impl<T> IntoBoxedView for Twhere
T: View,
Source§fn into_boxed_view(self) -> Box<dyn View>
fn into_boxed_view(self) -> Box<dyn View>
Box<View>.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Resizable for Twhere
T: View,
impl<T> Resizable for Twhere
T: View,
Source§fn resized(
self,
width: SizeConstraint,
height: SizeConstraint,
) -> ResizedView<Self>
fn resized( self, width: SizeConstraint, height: SizeConstraint, ) -> ResizedView<Self>
self in a ResizedView with the given size constraints.Source§fn fixed_size<S>(self, size: S) -> ResizedView<Self>
fn fixed_size<S>(self, size: S) -> ResizedView<Self>
self into a fixed-size ResizedView.Source§fn fixed_width(self, width: usize) -> ResizedView<Self>
fn fixed_width(self, width: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.Source§fn fixed_height(self, height: usize) -> ResizedView<Self>
fn fixed_height(self, height: usize) -> ResizedView<Self>
self into a fixed-width ResizedView.Source§fn full_screen(self) -> ResizedView<Self>
fn full_screen(self) -> ResizedView<Self>
self into a full-screen ResizedView.Source§fn full_width(self) -> ResizedView<Self>
fn full_width(self) -> ResizedView<Self>
self into a full-width ResizedView.Source§fn full_height(self) -> ResizedView<Self>
fn full_height(self) -> ResizedView<Self>
self into a full-height ResizedView.Source§fn max_size<S>(self, size: S) -> ResizedView<Self>
fn max_size<S>(self, size: S) -> ResizedView<Self>
self into a limited-size ResizedView.Source§fn max_width(self, max_width: usize) -> ResizedView<Self>
fn max_width(self, max_width: usize) -> ResizedView<Self>
self into a limited-width ResizedView.Source§fn max_height(self, max_height: usize) -> ResizedView<Self>
fn max_height(self, max_height: usize) -> ResizedView<Self>
self into a limited-height ResizedView.Source§fn min_size<S>(self, size: S) -> ResizedView<Self>
fn min_size<S>(self, size: S) -> ResizedView<Self>
self into a ResizedView at least sized size.Source§fn min_width(self, min_width: usize) -> ResizedView<Self>
fn min_width(self, min_width: usize) -> ResizedView<Self>
self in a ResizedView at least min_width wide.Source§fn min_height(self, min_height: usize) -> ResizedView<Self>
fn min_height(self, min_height: usize) -> ResizedView<Self>
self in a ResizedView at least min_height tall.Source§impl<T> Scrollable for Twhere
T: View,
impl<T> Scrollable for Twhere
T: View,
Source§fn scrollable(self) -> ScrollView<Self>
fn scrollable(self) -> ScrollView<Self>
self in a ScrollView.