EditView: Add a customizable filler character (#127)

* Add a customizable filler character
* Change filler character to string
This commit is contained in:
Afonso Bordado 2017-04-03 19:03:56 +01:00 committed by Alexandre Bury
parent 439f654811
commit b2bcf4138a

View File

@ -83,6 +83,9 @@ pub struct EditView {
/// When `true`, only print `*` instead of the true content. /// When `true`, only print `*` instead of the true content.
secret: bool, secret: bool,
/// Character to fill empty space
filler: String,
enabled: bool, enabled: bool,
style: ColorStyle, style: ColorStyle,
@ -101,6 +104,7 @@ impl EditView {
on_edit: None, on_edit: None,
on_submit: None, on_submit: None,
secret: false, secret: false,
filler: "_".to_string(),
enabled: true, enabled: true,
style: ColorStyle::Secondary, style: ColorStyle::Secondary,
} }
@ -120,6 +124,13 @@ impl EditView {
self.with(|s| s.set_secret(true)) self.with(|s| s.set_secret(true))
} }
/// Sets the character to fill in blank space
///
/// Defaults to "_"
pub fn set_filler(&mut self, filler: String) {
self.filler = filler;
}
/// Disables this view. /// Disables this view.
/// ///
/// A disabled view cannot be selected. /// A disabled view cannot be selected.
@ -405,7 +416,7 @@ impl View for EditView {
} }
printer.print_hline((width, 0), printer.print_hline((width, 0),
printer.size.x - width, printer.size.x - width,
"_"); self.filler.as_str());
} else { } else {
let content = &self.content[self.offset..]; let content = &self.content[self.offset..];
let display_bytes = content.graphemes(true) let display_bytes = content.graphemes(true)
@ -428,7 +439,7 @@ impl View for EditView {
if width < self.last_length { if width < self.last_length {
printer.print_hline((width, 0), printer.print_hline((width, 0),
self.last_length - width, self.last_length - width,
"_"); self.filler.as_str());
} }
} }
}); });