mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
EditView: Add a customizable filler character (#127)
* Add a customizable filler character * Change filler character to string
This commit is contained in:
parent
439f654811
commit
b2bcf4138a
@ -83,6 +83,9 @@ pub struct EditView {
|
||||
/// When `true`, only print `*` instead of the true content.
|
||||
secret: bool,
|
||||
|
||||
/// Character to fill empty space
|
||||
filler: String,
|
||||
|
||||
enabled: bool,
|
||||
|
||||
style: ColorStyle,
|
||||
@ -101,6 +104,7 @@ impl EditView {
|
||||
on_edit: None,
|
||||
on_submit: None,
|
||||
secret: false,
|
||||
filler: "_".to_string(),
|
||||
enabled: true,
|
||||
style: ColorStyle::Secondary,
|
||||
}
|
||||
@ -120,6 +124,13 @@ impl EditView {
|
||||
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.
|
||||
///
|
||||
/// A disabled view cannot be selected.
|
||||
@ -405,7 +416,7 @@ impl View for EditView {
|
||||
}
|
||||
printer.print_hline((width, 0),
|
||||
printer.size.x - width,
|
||||
"_");
|
||||
self.filler.as_str());
|
||||
} else {
|
||||
let content = &self.content[self.offset..];
|
||||
let display_bytes = content.graphemes(true)
|
||||
@ -428,7 +439,7 @@ impl View for EditView {
|
||||
if width < self.last_length {
|
||||
printer.print_hline((width, 0),
|
||||
self.last_length - width,
|
||||
"_");
|
||||
self.filler.as_str());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user