mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add outset border functions to Printer
This commit is contained in:
parent
215e88ae3e
commit
921e4a451e
@ -133,35 +133,14 @@ impl Printer {
|
||||
}
|
||||
let size = size - (1, 1);
|
||||
|
||||
let borders = if let Some(borders) = self.theme.borders {
|
||||
borders
|
||||
} else {
|
||||
// No border, no box...
|
||||
// TODO: still allow other boxes?
|
||||
// For instance make the check in the view.
|
||||
return;
|
||||
};
|
||||
|
||||
self.with_color(match borders {
|
||||
BorderStyle::Outset if !invert => {
|
||||
ColorStyle::Tertiary
|
||||
}
|
||||
_ => ColorStyle::Primary,
|
||||
},
|
||||
|s| {
|
||||
self.with_high_border(invert, |s| {
|
||||
s.print(start, "┌");
|
||||
s.print(start + size.keep_y(), "└");
|
||||
s.print_hline(start + (1, 0), size.x - 1, "─");
|
||||
s.print_vline(start + (0, 1), size.y - 1, "│");
|
||||
});
|
||||
|
||||
self.with_color(match borders {
|
||||
BorderStyle::Outset if invert => {
|
||||
ColorStyle::Tertiary
|
||||
}
|
||||
_ => ColorStyle::Primary,
|
||||
},
|
||||
|s| {
|
||||
self.with_low_border(invert, |s| {
|
||||
s.print(start + size.keep_x(), "┐");
|
||||
s.print(start + size, "┘");
|
||||
s.print_hline(start + (1, 0) + size.keep_y(), size.x - 1, "─");
|
||||
@ -169,6 +148,42 @@ impl Printer {
|
||||
});
|
||||
}
|
||||
|
||||
/// Runs the given function using a color depending on the theme.
|
||||
///
|
||||
/// * If the theme's borders is `None`, return without calling `f`.
|
||||
/// * If the theme's borders is "outset" and `invert` is `false`,
|
||||
/// use `ColorStyle::Tertiary`.
|
||||
/// * Otherwise, use `ColorStyle::Primary`.
|
||||
pub fn with_high_border<F>(&self, invert: bool, f: F)
|
||||
where F: FnOnce(&Printer)
|
||||
{
|
||||
let color = match self.theme.borders {
|
||||
None => return,
|
||||
Some(BorderStyle::Outset) if !invert => ColorStyle::Tertiary,
|
||||
_ => ColorStyle::Primary,
|
||||
};
|
||||
|
||||
self.with_color(color, f);
|
||||
}
|
||||
|
||||
/// Runs the given function using a color depending on the theme.
|
||||
///
|
||||
/// * If the theme's borders is `None`, return without calling `f`.
|
||||
/// * If the theme's borders is "outset" and `invert` is `true`,
|
||||
/// use `ColorStyle::Tertiary`.
|
||||
/// * Otherwise, use `ColorStyle::Primary`.
|
||||
pub fn with_low_border<F>(&self, invert: bool, f: F)
|
||||
where F: FnOnce(&Printer)
|
||||
{
|
||||
let color = match self.theme.borders {
|
||||
None => return,
|
||||
Some(BorderStyle::Outset) if invert => ColorStyle::Secondary,
|
||||
_ => ColorStyle::Primary,
|
||||
};
|
||||
|
||||
self.with_color(color, f);
|
||||
}
|
||||
|
||||
/// Apply a selection style and call the given function.
|
||||
///
|
||||
/// * If `selection` is `false`, simply uses `ColorStyle::Primary`.
|
||||
|
@ -226,8 +226,10 @@ impl View for Dialog {
|
||||
return;
|
||||
}
|
||||
let x = (printer.size.x - len) / 2;
|
||||
printer.with_high_border(false, |printer| {
|
||||
printer.print((x - 2, 0), "┤ ");
|
||||
printer.print((x + len, 0), " ├");
|
||||
});
|
||||
|
||||
printer.with_color(ColorStyle::TitlePrimary,
|
||||
|p| p.print((x, 0), &self.title));
|
||||
|
Loading…
Reference in New Issue
Block a user