mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Added impl_enabled to more widgets (#448)
* Expanded on API for Checkbox and for Enabled. Added a `with_x` variant to both, for easier chaining. * Added enabled/disable macro support to everything with an enabled/disabled method. This also gives them `with_enabled`, but more importantly, keeps things tidy
This commit is contained in:
parent
f42fc382e6
commit
2750ac370b
@ -5,7 +5,7 @@ use crate::rect::Rect;
|
||||
use crate::theme::ColorStyle;
|
||||
use crate::view::View;
|
||||
use crate::Vec2;
|
||||
use crate::{Cursive, Printer, With};
|
||||
use crate::{Cursive, Printer};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
/// Simple text label with a callback when <Enter> is pressed.
|
||||
@ -29,6 +29,8 @@ pub struct Button {
|
||||
}
|
||||
|
||||
impl Button {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
/// Creates a new button with the given content and callback.
|
||||
pub fn new<F, S>(label: S, cb: F) -> Self
|
||||
where
|
||||
@ -71,35 +73,6 @@ impl Button {
|
||||
self.callback = Callback::from_fn(cb);
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// A disabled view cannot be selected.
|
||||
pub fn disable(&mut self) {
|
||||
self.enabled = false;
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn disabled(self) -> Self {
|
||||
self.with(Self::disable)
|
||||
}
|
||||
|
||||
/// Re-enables this view.
|
||||
pub fn enable(&mut self) {
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
/// Enable or disable this view.
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
|
||||
/// Returns `true` if this view is enabled.
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
/// Returns the label for this button.
|
||||
///
|
||||
/// Includes brackets.
|
||||
|
@ -111,6 +111,8 @@ pub struct EditView {
|
||||
new_default!(EditView);
|
||||
|
||||
impl EditView {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
/// Creates a new, empty edit view.
|
||||
pub fn new() -> Self {
|
||||
EditView {
|
||||
@ -181,25 +183,6 @@ impl EditView {
|
||||
self.with(|s| s.set_filler(filler))
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// A disabled view cannot be selected.
|
||||
pub fn disable(&mut self) {
|
||||
self.enabled = false;
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn disabled(self) -> Self {
|
||||
self.with(Self::disable)
|
||||
}
|
||||
|
||||
/// Re-enables this view.
|
||||
pub fn enable(&mut self) {
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
/// Sets the style used for this view.
|
||||
///
|
||||
/// When the view is enabled, the style will be reversed.
|
||||
@ -357,16 +340,6 @@ impl EditView {
|
||||
self.with(|v| v.set_on_submit(callback))
|
||||
}
|
||||
|
||||
/// Enable or disable this view.
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
|
||||
/// Returns `true` if this view is enabled.
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
/// Replace the entire content of the view with the given one.
|
||||
///
|
||||
/// Returns a callback in response to content change.
|
||||
|
@ -85,6 +85,8 @@ impl<T: 'static> Default for SelectView<T> {
|
||||
}
|
||||
|
||||
impl<T: 'static> SelectView<T> {
|
||||
impl_enabled!(self.enabled);
|
||||
|
||||
/// Creates a new empty SelectView.
|
||||
pub fn new() -> Self {
|
||||
SelectView {
|
||||
@ -131,35 +133,6 @@ impl<T: 'static> SelectView<T> {
|
||||
self.popup = popup;
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// A disabled view cannot be selected.
|
||||
pub fn disable(&mut self) {
|
||||
self.enabled = false;
|
||||
}
|
||||
|
||||
/// Disables this view.
|
||||
///
|
||||
/// Chainable variant.
|
||||
pub fn disabled(self) -> Self {
|
||||
self.with(Self::disable)
|
||||
}
|
||||
|
||||
/// Re-enables this view.
|
||||
pub fn enable(&mut self) {
|
||||
self.enabled = true;
|
||||
}
|
||||
|
||||
/// Enable or disable this view.
|
||||
pub fn set_enabled(&mut self, enabled: bool) {
|
||||
self.enabled = enabled;
|
||||
}
|
||||
|
||||
/// Returns `true` if this view is enabled.
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.enabled
|
||||
}
|
||||
|
||||
/// Sets a callback to be used when an item is selected.
|
||||
pub fn set_on_select<F>(&mut self, cb: F)
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user