mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Split style and color
Color is a color-pair Style is an attribute, like Bold or Reversed
This commit is contained in:
parent
5407c53545
commit
abb09cf4bb
@ -30,7 +30,6 @@ pub const HIGHLIGHT: ThemeColor = 8;
|
||||
/// Highlight color for inactive views (not in focus).
|
||||
pub const HIGHLIGHT_INACTIVE: ThemeColor = 9;
|
||||
|
||||
|
||||
fn load_hex(s: &str) -> i16 {
|
||||
let mut sum = 0;
|
||||
for c in s.chars() {
|
||||
|
@ -69,15 +69,23 @@ impl Printer {
|
||||
/// printer.print((0,0), "This text is highlighted!");
|
||||
/// });
|
||||
/// ```
|
||||
pub fn with_style<'a, F>(&'a self, style: color::ThemeColor, f: F)
|
||||
pub fn with_color<'a, F>(&'a self, c: color::ThemeColor, f: F)
|
||||
where F: Fn(&Printer)
|
||||
{
|
||||
ncurses::attron(ncurses::COLOR_PAIR(style));
|
||||
ncurses::attron(ncurses::COLOR_PAIR(c));
|
||||
f(self);
|
||||
ncurses::attroff(ncurses::COLOR_PAIR(style));
|
||||
ncurses::attroff(ncurses::COLOR_PAIR(c));
|
||||
ncurses::attron(ncurses::COLOR_PAIR(color::PRIMARY));
|
||||
}
|
||||
|
||||
pub fn with_style<'a, F>(&'a self, style: ncurses::attr_t, f: F)
|
||||
where F: Fn(&Printer)
|
||||
{
|
||||
ncurses::attron(style);
|
||||
f(self);
|
||||
ncurses::attroff(style);
|
||||
}
|
||||
|
||||
/// Prints a rectangular box.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -32,7 +32,7 @@ impl View for Button {
|
||||
let style = if !focused { color::PRIMARY } else { color::HIGHLIGHT };
|
||||
let x = printer.size.x - 1;
|
||||
|
||||
printer.with_style(style, |printer| {
|
||||
printer.with_color(style, |printer| {
|
||||
printer.print((1,0), &self.label);
|
||||
printer.print((0,0), "<");
|
||||
printer.print((x,0), ">");
|
||||
|
@ -114,7 +114,7 @@ impl View for Dialog {
|
||||
printer.print((x-2,0), "┤ ");
|
||||
printer.print((x+self.title.len(),0), " ├");
|
||||
|
||||
printer.with_style(color::TITLE_PRIMARY, |p| p.print((x,0), &self.title));
|
||||
printer.with_color(color::TITLE_PRIMARY, |p| p.print((x,0), &self.title));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,9 +59,12 @@ fn read_char(ch: i32) -> Option<char> {
|
||||
|
||||
impl View for EditView {
|
||||
fn draw(&mut self, printer: &Printer, focused: bool) {
|
||||
let style = if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE };
|
||||
printer.with_style(style, |printer| {
|
||||
printer.print((0,0), &self.content);
|
||||
// let style = if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE };
|
||||
printer.with_color(color::SECONDARY, |printer| {
|
||||
printer.with_style(ncurses::A_REVERSE(), |printer| {
|
||||
printer.print((0,0), &self.content);
|
||||
printer.print_hline((self.content.len(),0), printer.size.x-self.content.len(), '_' as u64);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ impl <T: View> ViewWrapper for ShadowView<T> {
|
||||
|
||||
fn wrap_draw(&mut self, printer: &Printer, focused: bool) {
|
||||
|
||||
printer.with_style(color::PRIMARY, |printer| {
|
||||
printer.with_color(color::PRIMARY, |printer| {
|
||||
// Draw the view background
|
||||
for y in 1..printer.size.y-1 {
|
||||
printer.print_hline((1,y), printer.size.x-2, ' ' as u64);
|
||||
@ -46,7 +46,7 @@ impl <T: View> ViewWrapper for ShadowView<T> {
|
||||
let h = printer.size.y-1;
|
||||
let w = printer.size.x-1;
|
||||
|
||||
printer.with_style(color::SHADOW, |printer| {
|
||||
printer.with_color(color::SHADOW, |printer| {
|
||||
printer.print_hline((2,h), w-1, ' ' as u64);
|
||||
printer.print_vline((w,2), h-1, ' ' as u64);
|
||||
});
|
||||
|
@ -186,7 +186,7 @@ impl View for TextView {
|
||||
// Where ratio is ({start or end} / content.height)
|
||||
let start = self.view_height * self.start_line / self.rows.len();
|
||||
let end = self.view_height * (self.start_line + self.view_height) / self.rows.len();
|
||||
printer.with_style(
|
||||
printer.with_color(
|
||||
if focused { color::HIGHLIGHT } else { color::HIGHLIGHT_INACTIVE },
|
||||
|printer| {
|
||||
printer.print_vline((printer.size.x-1, start), end-start, ' ' as u64);
|
||||
|
Loading…
Reference in New Issue
Block a user