diff --git a/cursive-core/src/views/checkbox.rs b/cursive-core/src/views/checkbox.rs index 5b1ebb8..d56ef31 100644 --- a/cursive-core/src/views/checkbox.rs +++ b/cursive-core/src/views/checkbox.rs @@ -119,6 +119,15 @@ impl Checkbox { } } + /// Set the checkbox state. + /// + /// Chainable variant. + pub fn with_checked(self, is_checked: bool) -> Self { + self.with(|s| { + s.set_checked(is_checked); + }) + } + fn draw_internal(&self, printer: &Printer<'_, '_>) { printer.print((0, 0), "[ ]"); if self.checked { diff --git a/cursive-core/src/views/mod.rs b/cursive-core/src/views/mod.rs index 4a8e42f..4a3bb27 100644 --- a/cursive-core/src/views/mod.rs +++ b/cursive-core/src/views/mod.rs @@ -44,6 +44,14 @@ macro_rules! impl_enabled { self.$x = enabled; } + /// Enable or disable this view. + /// + /// Chainable variant. + pub fn with_enabled(mut self, is_enabled: bool) -> Self { + self.set_enabled(is_enabled); + self + } + /// Returns `true` if this view is enabled. pub fn is_enabled(&self) -> bool { self.$x