Expanded on API for Checkbox and for Enabled. (#447)

Added a `with_x` variant to both, for easier chaining.
This commit is contained in:
Jonathan Spira 2020-04-25 14:13:04 -04:00 committed by GitHub
parent 57d5b21518
commit f42fc382e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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 {

View File

@ -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