From bdbf6d759e5a5ddfa3353d8313dcbc5d52f801cc Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 2 Apr 2017 15:38:00 -0700 Subject: [PATCH] Add `EditView::set_style` --- src/views/edit_view.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 82eb47f..b8331b1 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -84,6 +84,8 @@ pub struct EditView { secret: bool, enabled: bool, + + style: ColorStyle, } new_default!(EditView); @@ -100,6 +102,7 @@ impl EditView { on_submit: None, secret: false, enabled: true, + style: ColorStyle::Secondary, } } @@ -136,6 +139,25 @@ impl EditView { self.enabled = true; } + /// Sets the style used for this view. + /// + /// When the view is enabled, the style will be reversed. + /// + /// Defaults to `ColorStyle::Secondary`. + pub fn set_style(&mut self, style: ColorStyle) { + self.style = style; + } + + + /// Sets the style used for this view. + /// + /// When the view is enabled, the style will be reversed. + /// + /// Chainable variant. + pub fn style(self, style: ColorStyle) -> Self { + self.with(|s| s.set_style(style)) + } + /// Sets a mutable callback to be called whenever the content is modified. /// /// `callback` will be called with the view @@ -367,7 +389,7 @@ impl View for EditView { printer.size.x); let width = self.content.width(); - printer.with_color(ColorStyle::Secondary, |printer| { + printer.with_color(self.style, |printer| { let effect = if self.enabled { Effect::Reverse } else {