diff --git a/Cargo.toml b/Cargo.toml index 672ec70..59b96bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,31 +1,21 @@ [package] authors = ["Alexandre Bury "] -categories = [ - "command-line-interface", - "gui", -] +categories = ["command-line-interface", "gui"] description = "A TUI (Text User Interface) library focused on ease-of-use." documentation = "https://docs.rs/cursive" -exclude = [ - "doc/**", - "assets/**", - "examples/**", -] -keywords = [ - "ncurses", - "TUI", - "UI", -] +exclude = ["doc/**", "assets/**", "examples/**"] +keywords = ["ncurses", "TUI", "UI"] license = "MIT" name = "cursive" readme = "Readme.md" repository = "https://github.com/gyscos/Cursive" version = "0.7.6-alpha.0" - [badges.travis-ci] repository = "gyscos/Cursive" [dependencies] +enum-map = "0.2.24" +enumset = "0.3.3" log = "0.4" maplit = "1.0.0" num = "0.1" @@ -34,8 +24,6 @@ toml = "0.4" unicode-segmentation = "1.0" unicode-width = "0.1" xi-unicode = "0.1.0" -pulldown-cmark = { version = "0.1.0", optional = true, default-features = false } -enumset = "0.3.3" [dependencies.bear-lib-terminal] optional = true @@ -59,6 +47,11 @@ features = ["wide"] optional = true version = "0.13" +[dependencies.pulldown-cmark] +default-features = false +optional = true +version = "0.1.0" + [dependencies.termion] optional = true version = "1.5.0" @@ -69,14 +62,10 @@ rand = "0.4" [features] blt-backend = ["bear-lib-terminal"] default = ["ncurses-backend"] +markdown = ["pulldown-cmark"] ncurses-backend = ["ncurses"] pancurses-backend = ["pancurses"] -termion-backend = [ - "termion", - "chan", - "chan-signal", -] -markdown = ["pulldown-cmark"] +termion-backend = ["termion", "chan", "chan-signal"] [lib] name = "cursive" diff --git a/examples/colors.rs b/examples/colors.rs index 375c707..7188c36 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -34,10 +34,10 @@ fn draw(_: &(), p: &Printer) { for x in 0..x_max { for y in 0..y_max { // We'll use a different style for each cell - let style = ColorStyle::Custom { - front: front_color(x, y, x_max, y_max), - back: back_color(x, y, x_max, y_max), - }; + let style = ColorStyle::new( + front_color(x, y, x_max, y_max), + back_color(x, y, x_max, y_max), + ); p.with_color(style, |printer| { printer.print((x, y), "+"); diff --git a/examples/markup.rs b/examples/markup.rs index 7206317..ab2ee02 100644 --- a/examples/markup.rs +++ b/examples/markup.rs @@ -1,28 +1,28 @@ extern crate cursive; use cursive::Cursive; -#[cfg(feature = "markdown")] -use cursive::utils::markup::markdown; use cursive::views::{Dialog, TextView}; -// Make sure you compile with the `markdown` feature! -// -// cargo run --example markup --features markdown +use cursive::theme::Color; +use cursive::theme::BaseColor; +use cursive::theme::Style; +use cursive::theme::Effect; +use cursive::utils::markup::StyledString; fn main() { let mut siv = Cursive::new(); - // If markdown is enabled, parse a small text. - - #[cfg(feature = "markdown")] - let text = markdown::parse("Isn't *that* **cool**?"); - - #[cfg(not(feature = "markdown"))] - let text = "Rebuild with --features markdown ;)"; + let mut styled = StyledString::plain("Isn't "); + styled.append(StyledString::styled("that ", Color::Dark(BaseColor::Red))); + styled.append(StyledString::styled( + "cool?", + Style::from(Color::Light(BaseColor::Blue)).add(Effect::Bold), + )); // TextView can natively accept StyledString. siv.add_layer( - Dialog::around(TextView::new(text)).button("Hell yeah!", |s| s.quit()), + Dialog::around(TextView::new(styled)) + .button("Hell yeah!", |s| s.quit()), ); siv.run(); diff --git a/examples/mines/main.rs b/examples/mines/main.rs index b797495..7e261e4 100644 --- a/examples/mines/main.rs +++ b/examples/mines/main.rs @@ -208,10 +208,7 @@ impl cursive::view::View for BoardView { }; printer.with_color( - ColorStyle::Custom { - back: color, - front: Color::Dark(BaseColor::Black), - }, + ColorStyle::new(color, Color::Dark(BaseColor::Black)), |printer| printer.print((x, y), text), ); } diff --git a/examples/terminal_default.rs b/examples/terminal_default.rs index df11b99..2d9304a 100644 --- a/examples/terminal_default.rs +++ b/examples/terminal_default.rs @@ -1,7 +1,7 @@ extern crate cursive; use cursive::Cursive; -use cursive::theme::{Color, Theme}; +use cursive::theme::{Color, PaletteColor, Theme}; use cursive::views::TextView; // This example sets the background color to the terminal default. @@ -30,7 +30,7 @@ fn custom_theme_from_cursive(siv: &Cursive) -> Theme { // We'll return the current theme with a small modification. let mut theme = siv.current_theme().clone(); - theme.colors.background = Color::TerminalDefault; + theme.palette.colors[PaletteColor::Background] = Color::TerminalDefault; theme } diff --git a/examples/theme_manual.rs b/examples/theme_manual.rs index 1aa2239..1160833 100644 --- a/examples/theme_manual.rs +++ b/examples/theme_manual.rs @@ -10,10 +10,10 @@ fn main() { let layout = LinearLayout::vertical() .child(TextView::new("This is a dynamic theme example!")) .child(EditView::new().content("Woo! colors!").style( - ColorStyle::Custom { - front: Color::Rgb(200, 150, 150), - back: Color::Dark(BaseColor::Blue), - }, + ColorStyle::new( + Color::Rgb(200, 150, 150), + Color::Dark(BaseColor::Blue), + ), )); siv.add_layer( diff --git a/src/cursive.rs b/src/cursive.rs index 448763e..6ba61ea 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -167,14 +167,16 @@ impl Cursive { /// /// Users rarely have to call this directly. pub fn clear(&self) { - self.backend.clear(self.theme.colors.background); + self.backend + .clear(self.theme.palette.colors[theme::PaletteColor::Background]); } /// Loads a theme from the given file. /// /// `filename` must point to a valid toml file. pub fn load_theme_file>( - &mut self, filename: P + &mut self, + filename: P, ) -> Result<(), theme::Error> { self.set_theme(try!(theme::load_theme_file(filename))); Ok(()) @@ -279,7 +281,9 @@ impl Cursive { /// # } /// ``` pub fn call_on( - &mut self, sel: &view::Selector, callback: F + &mut self, + sel: &view::Selector, + callback: F, ) -> Option where V: View + Any, diff --git a/src/lib.rs b/src/lib.rs index 50be25f..c81c01c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,6 +65,9 @@ extern crate enumset; extern crate log; #[macro_use] extern crate maplit; +#[macro_use] +extern crate enum_map; + extern crate num; extern crate owning_ref; extern crate toml; diff --git a/src/printer.rs b/src/printer.rs index 65c1647..b7ffe44 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -5,7 +5,7 @@ use enumset::EnumSet; use std::cell::Cell; use std::cmp::min; use std::rc::Rc; -use theme::{BorderStyle, ColorStyle, Effect, Style, Theme}; +use theme::{BorderStyle, ColorStyle, Effect, Style, Theme, PaletteColor}; use unicode_segmentation::UnicodeSegmentation; use utils::lines::simple::prefix; use vec::Vec2; @@ -51,7 +51,7 @@ impl<'a> Printer<'a> { /// /// Users rarely need to call this directly. pub fn clear(&self) { - self.backend.clear(self.theme.colors.background); + self.backend.clear(self.theme.palette.colors[PaletteColor::Background]); } /// Returns `true` if nothing has been printed yet. @@ -123,7 +123,7 @@ impl<'a> Printer<'a> { /// # let b = backend::Concrete::init(); /// # let t = theme::load_default(); /// # let printer = Printer::new((6,4), &t, &b); - /// printer.with_color(theme::ColorStyle::Highlight, |printer| { + /// printer.with_color(theme::ColorStyle::highlight(), |printer| { /// printer.print((0,0), "This text is highlighted!"); /// }); /// ``` @@ -131,7 +131,7 @@ impl<'a> Printer<'a> { where F: FnOnce(&Printer), { - self.backend.with_color(c.resolve(self.theme), || f(self)); + self.backend.with_color(c.resolve(&self.theme.palette), || f(self)); } /// Call the given closure with a styled printer, @@ -239,8 +239,8 @@ impl<'a> Printer<'a> { { let color = match self.theme.borders { BorderStyle::None => return, - BorderStyle::Outset if !invert => ColorStyle::Tertiary, - _ => ColorStyle::Primary, + BorderStyle::Outset if !invert => ColorStyle::tertiary(), + _ => ColorStyle::primary(), }; self.with_color(color, f); @@ -250,16 +250,16 @@ impl<'a> Printer<'a> { /// /// * 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`. + /// use `ColorStyle::tertiary()`. + /// * Otherwise, use `ColorStyle::primary()`. pub fn with_low_border(&self, invert: bool, f: F) where F: FnOnce(&Printer), { let color = match self.theme.borders { BorderStyle::None => return, - BorderStyle::Outset if invert => ColorStyle::Tertiary, - _ => ColorStyle::Primary, + BorderStyle::Outset if invert => ColorStyle::tertiary(), + _ => ColorStyle::primary(), }; self.with_color(color, f); @@ -267,21 +267,21 @@ impl<'a> Printer<'a> { /// Apply a selection style and call the given function. /// - /// * If `selection` is `false`, simply uses `ColorStyle::Primary`. + /// * If `selection` is `false`, simply uses `ColorStyle::primary()`. /// * If `selection` is `true`: /// * If the printer currently has the focus, - /// uses `ColorStyle::Highlight`. - /// * Otherwise, uses `ColorStyle::HighlightInactive`. + /// uses `ColorStyle::highlight()`. + /// * Otherwise, uses `ColorStyle::highlight_inactive()`. pub fn with_selection(&self, selection: bool, f: F) { self.with_color( if selection { if self.focused { - ColorStyle::Highlight + ColorStyle::highlight() } else { - ColorStyle::HighlightInactive + ColorStyle::highlight_inactive() } } else { - ColorStyle::Primary + ColorStyle::primary() }, f, ); diff --git a/src/theme/color.rs b/src/theme/color.rs index 873c230..0c5b82a 100644 --- a/src/theme/color.rs +++ b/src/theme/color.rs @@ -56,12 +56,16 @@ impl From for BaseColor { pub enum Color { /// Represents a color, preset by terminal. TerminalDefault, + /// One of the 8 base colors. Dark(BaseColor), + /// Lighter version of a base color. Light(BaseColor), + /// True-color, 24-bit. Rgb(u8, u8, u8), + /// Low-resolution /// /// Each value should be `<= 5` (you'll get panics otherwise). diff --git a/src/theme/color_pair.rs b/src/theme/color_pair.rs index 58ea19f..ea1ccf7 100644 --- a/src/theme/color_pair.rs +++ b/src/theme/color_pair.rs @@ -5,6 +5,7 @@ use super::Color; pub struct ColorPair { /// Color used for the foreground. pub front: Color, + /// Color used for the background. pub back: Color, } diff --git a/src/theme/color_style.rs b/src/theme/color_style.rs index b0e3bc3..52e17a1 100644 --- a/src/theme/color_style.rs +++ b/src/theme/color_style.rs @@ -1,4 +1,4 @@ -use super::{Color, ColorPair, Theme}; +use super::{Color, ColorPair, Palette, PaletteColor}; /// Possible color style for a cell. /// @@ -6,57 +6,141 @@ use super::{Color, ColorPair, Theme}; /// /// The current theme will assign each role a foreground and background color. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum ColorStyle { - /// Style set by terminal before entering a Cursive program. - TerminalDefault, - /// Application background, where no view is present. - Background, - /// Color used by view shadows. Only background matters. - Shadow, - /// Main text with default background. - Primary, - /// Secondary text color, with default background. - Secondary, - /// Tertiary text color, with default background. - Tertiary, - /// Title text color with default background. - TitlePrimary, - /// Alternative color for a title. - TitleSecondary, - /// Alternate text with highlight background. - Highlight, - /// Highlight color for inactive views (not in focus). - HighlightInactive, - /// Directly specifies colors, independently of the theme. - Custom { - /// Foreground color - front: Color, - /// Background color - back: Color, - }, +pub struct ColorStyle { + /// Color used for the foreground (the text itself). + pub front: ColorType, + + /// Color used for the background. + pub back: ColorType, } impl ColorStyle { + /// Creates + pub fn new(front: F, back: B) -> Self + where + F: Into, + B: Into, + { + let front = front.into(); + let back = back.into(); + Self { front, back } + } + + /// Style set by terminal before entering a Cursive program. + pub fn terminal_default() -> Self { + Self::new(Color::TerminalDefault, Color::TerminalDefault) + } + + /// Application background, where no view is present. + pub fn background() -> Self { + Self::new(PaletteColor::Background, PaletteColor::Background) + } + + /// Color used by view shadows. Only background matters. + pub fn shadow() -> Self { + Self::new(PaletteColor::Shadow, PaletteColor::Shadow) + } + + /// Main text with default background. + pub fn primary() -> Self { + Self::new(PaletteColor::Primary, PaletteColor::View) + } + + /// Secondary text color, with default background. + pub fn secondary() -> Self { + Self::new(PaletteColor::Secondary, PaletteColor::View) + } + + /// Tertiary text color, with default background. + pub fn tertiary() -> Self { + Self::new(PaletteColor::Tertiary, PaletteColor::View) + } + + /// Title text color with default background. + pub fn title_primary() -> Self { + Self::new(PaletteColor::TitlePrimary, PaletteColor::View) + } + + /// Alternative color for a title. + pub fn title_secondary() -> Self { + Self::new(PaletteColor::TitleSecondary, PaletteColor::View) + } + + /// Alternate text with highlight background. + pub fn highlight() -> Self { + Self::new(PaletteColor::View, PaletteColor::Highlight) + } + + /// Highlight color for inactive views (not in focus). + pub fn highlight_inactive() -> Self { + Self::new(PaletteColor::View, PaletteColor::HighlightInactive) + } + /// Return the color pair that this style represents. - /// - /// Returns `(front, back)`. - pub fn resolve(&self, theme: &Theme) -> ColorPair { - let c = &theme.colors; - let (front, back) = match *self { - ColorStyle::TerminalDefault => { - (Color::TerminalDefault, Color::TerminalDefault) - } - ColorStyle::Background => (c.view, c.background), - ColorStyle::Shadow => (c.shadow, c.shadow), - ColorStyle::Primary => (c.primary, c.view), - ColorStyle::Secondary => (c.secondary, c.view), - ColorStyle::Tertiary => (c.tertiary, c.view), - ColorStyle::TitlePrimary => (c.title_primary, c.view), - ColorStyle::TitleSecondary => (c.title_secondary, c.view), - ColorStyle::Highlight => (c.view, c.highlight), - ColorStyle::HighlightInactive => (c.view, c.highlight_inactive), - ColorStyle::Custom { front, back } => (front, back), - }; - ColorPair { front, back } + pub fn resolve(&self, palette: &Palette) -> ColorPair { + ColorPair { + front: self.front.resolve(palette), + back: self.back.resolve(palette), + } + } +} + +impl From for ColorStyle { + fn from(color: Color) -> Self { + Self::new(color, PaletteColor::View) + } +} + +impl From for ColorStyle { + fn from(color: PaletteColor) -> Self { + Self::new(color, PaletteColor::View) + } +} + +impl From for ColorStyle { + fn from(color: ColorType) -> Self { + Self::new(color, PaletteColor::View) + } +} + +impl From<(F, B)> for ColorStyle +where + F: Into, + B: Into, +{ + fn from((front, back): (F, B)) -> Self { + Self::new(front, back) + } +} + +/// Either a color from the palette, or a direct color. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum ColorType { + /// Uses a color from the application palette. + Palette(PaletteColor), + + /// Uses a direct color, independent of the current palette. + Color(Color), +} + +impl ColorType { + /// Given a palette, resolve `self` to a concrete color. + pub fn resolve(self, palette: &Palette) -> Color { + match self { + ColorType::Color(color) => color, + ColorType::Palette(color) => color.resolve(palette), + } + } +} + +impl From for ColorType { + fn from(color: Color) -> Self { + ColorType::Color(color) + } +} + +impl From for ColorType { + fn from(color: PaletteColor) -> Self { + ColorType::Palette(color) } } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index e9f3d73..67bdf09 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -124,9 +124,9 @@ mod palette; pub use self::border_style::BorderStyle; pub use self::color::{BaseColor, Color}; pub use self::color_pair::ColorPair; -pub use self::color_style::ColorStyle; +pub use self::color_style::{ColorStyle, ColorType}; pub use self::effect::Effect; -pub use self::palette::Palette; +pub use self::palette::{Palette, PaletteColor}; pub use self::style::Style; use std::fs::File; use std::io; @@ -142,7 +142,7 @@ pub struct Theme { /// How view borders should be drawn. pub borders: BorderStyle, /// What colors should be used through the application? - pub colors: Palette, + pub palette: Palette, } impl Default for Theme { @@ -150,18 +150,7 @@ impl Default for Theme { Theme { shadow: true, borders: BorderStyle::Simple, - colors: Palette { - background: Color::Dark(BaseColor::Blue), - shadow: Color::Dark(BaseColor::Black), - view: Color::Dark(BaseColor::White), - primary: Color::Dark(BaseColor::Black), - secondary: Color::Dark(BaseColor::Blue), - tertiary: Color::Light(BaseColor::White), - title_primary: Color::Dark(BaseColor::Red), - title_secondary: Color::Dark(BaseColor::Yellow), - highlight: Color::Dark(BaseColor::Red), - highlight_inactive: Color::Dark(BaseColor::Blue), - }, + palette: Palette::default(), } } } @@ -177,7 +166,7 @@ impl Theme { } if let Some(&toml::Value::Table(ref table)) = table.get("colors") { - self.colors.load(table); + self.palette.load(table); } } } diff --git a/src/theme/palette.rs b/src/theme/palette.rs index 5dc4aaf..b9cbd23 100644 --- a/src/theme/palette.rs +++ b/src/theme/palette.rs @@ -1,52 +1,118 @@ use super::Color; use toml; +use enum_map::EnumMap; /// Color configuration for the application. /// /// Assign each color role an actual color. -#[derive(Copy, Clone, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Palette { - /// Color used for the application background. - pub background: Color, - /// Color used for View shadows. - pub shadow: Color, - /// Color used for View backgrounds. - pub view: Color, - /// Primary color used for the text. - pub primary: Color, - /// Secondary color used for the text. - pub secondary: Color, - /// Tertiary color used for the text. - pub tertiary: Color, - /// Primary color used for title text. - pub title_primary: Color, - /// Secondary color used for title text. - pub title_secondary: Color, - /// Color used for highlighting text. - pub highlight: Color, - /// Color used for highlighting inactive text. - pub highlight_inactive: Color, + /// Color map for this palette + pub colors: EnumMap, +} + +impl Default for Palette { + fn default() -> Self { + use self::PaletteColor::*; + use theme::Color::*; + use theme::BaseColor::*; + + Palette { + colors: enum_map!{ + Background => Dark(Blue), + Shadow => Dark(Black), + View => Dark(White), + Primary => Dark(Black), + Secondary => Dark(Blue), + Tertiary => Dark(White), + TitlePrimary => Dark(Red), + TitleSecondary => Dark(Yellow), + Highlight => Dark(Red), + HighlightInactive => Dark(Blue), + } + } + } } impl Palette { /// Fills `self` with the colors from the given `table`. pub(crate) fn load(&mut self, table: &toml::value::Table) { - load_color(&mut self.background, table.get("background")); - load_color(&mut self.shadow, table.get("shadow")); - load_color(&mut self.view, table.get("view")); - load_color(&mut self.primary, table.get("primary")); - load_color(&mut self.secondary, table.get("secondary")); - load_color(&mut self.tertiary, table.get("tertiary")); - load_color(&mut self.title_primary, table.get("title_primary")); - load_color(&mut self.title_secondary, table.get("title_secondary")); - load_color(&mut self.highlight, table.get("highlight")); + // TODO: use serde for that? + // Problem: toml-rs doesn't do well with Enums... load_color( - &mut self.highlight_inactive, + &mut self.colors[PaletteColor::Background], + table.get("background"), + ); + load_color( + &mut self.colors[PaletteColor::Shadow], + table.get("shadow"), + ); + load_color(&mut self.colors[PaletteColor::View], table.get("view")); + load_color( + &mut self.colors[PaletteColor::Primary], + table.get("primary"), + ); + load_color( + &mut self.colors[PaletteColor::Secondary], + table.get("secondary"), + ); + load_color( + &mut self.colors[PaletteColor::Tertiary], + table.get("tertiary"), + ); + load_color( + &mut self.colors[PaletteColor::TitlePrimary], + table.get("title_primary"), + ); + load_color( + &mut self.colors[PaletteColor::TitleSecondary], + table.get("title_secondary"), + ); + load_color( + &mut self.colors[PaletteColor::Highlight], + table.get("highlight"), + ); + load_color( + &mut self.colors[PaletteColor::HighlightInactive], table.get("highlight_inactive"), ); } } +/// Color entry in a palette. +/// +/// Each ColorRole is used for a specific role in a default application. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, EnumMap)] +pub enum PaletteColor { + /// Color used for the application background. + Background, + /// Color used for View shadows. + Shadow, + /// Color used for View backgrounds. + View, + /// Primary color used for the text. + Primary, + /// Secondary color used for the text. + Secondary, + /// Tertiary color used for the text. + Tertiary, + /// Primary color used for title text. + TitlePrimary, + /// Secondary color used for title text. + TitleSecondary, + /// Color used for highlighting text. + Highlight, + /// Color used for highlighting inactive text. + HighlightInactive, +} + +impl PaletteColor { + /// Given a palette, resolve `self` to a concrete color. + pub fn resolve(self, palette: &Palette) -> Color { + palette.colors[self] + } +} + /// Parses `value` and fills `target` if it's a valid color. fn load_color(target: &mut Color, value: Option<&toml::Value>) -> bool { if let Some(value) = value { diff --git a/src/theme/style.rs b/src/theme/style.rs index 203bd8a..644b1ce 100644 --- a/src/theme/style.rs +++ b/src/theme/style.rs @@ -1,4 +1,4 @@ -use super::{ColorStyle, Effect, Color}; +use super::{ColorStyle, Effect, Color, PaletteColor, ColorType}; use enumset::EnumSet; /// Combine a color and an effect. @@ -73,3 +73,21 @@ impl From for Style { } } } + +impl From for Style { + fn from(color: Color) -> Self { + ColorStyle::from(color).into() + } +} + +impl From for Style { + fn from(color: PaletteColor) -> Self { + ColorStyle::from(color).into() + } +} + +impl From for Style { + fn from(color: ColorType) -> Self { + ColorStyle::from(color).into() + } +} diff --git a/src/view/scroll.rs b/src/view/scroll.rs index 55c701c..daf833f 100644 --- a/src/view/scroll.rs +++ b/src/view/scroll.rs @@ -277,9 +277,9 @@ impl ScrollBase { let start = self.scrollbar_thumb_y(height); let color = if printer.focused { - ColorStyle::Highlight + ColorStyle::highlight() } else { - ColorStyle::HighlightInactive + ColorStyle::highlight_inactive() }; let scrollbar_x = self.scrollbar_x(printer.size.x); diff --git a/src/views/button.rs b/src/views/button.rs index ecd651c..a0ec0fc 100644 --- a/src/views/button.rs +++ b/src/views/button.rs @@ -132,11 +132,11 @@ impl View for Button { } let style = if !self.enabled { - ColorStyle::Secondary + ColorStyle::secondary() } else if !printer.focused { - ColorStyle::Primary + ColorStyle::primary() } else { - ColorStyle::Highlight + ColorStyle::highlight() }; let offset = diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 8f4a4d9..6f8aef4 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -119,7 +119,7 @@ impl View for Checkbox { self.draw_internal(printer) }); } else { - printer.with_color(ColorStyle::Secondary, |printer| { + printer.with_color(ColorStyle::secondary(), |printer| { self.draw_internal(printer) }); } diff --git a/src/views/dialog.rs b/src/views/dialog.rs index 14f2b75..3d7662d 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -379,7 +379,7 @@ impl Dialog { printer.print((x + len, 0), " ├"); }); - printer.with_color(ColorStyle::TitlePrimary, |p| { + printer.with_color(ColorStyle::title_primary(), |p| { p.print((x, 0), &self.title) }); } diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index d7e4355..4a2b775 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -119,7 +119,7 @@ impl EditView { secret: false, filler: "_".to_string(), enabled: true, - style: ColorStyle::Secondary, + style: ColorStyle::secondary(), } } diff --git a/src/views/menubar.rs b/src/views/menubar.rs index 25c9b0f..abb83fc 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -261,7 +261,7 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc) { impl View for Menubar { fn draw(&self, printer: &Printer) { // Draw the bar at the top - printer.with_color(ColorStyle::Primary, |printer| { + printer.with_color(ColorStyle::primary(), |printer| { printer.print_hline((0, 0), printer.size.x, " "); }); diff --git a/src/views/progress_bar.rs b/src/views/progress_bar.rs index 3ba06b5..44538e4 100644 --- a/src/views/progress_bar.rs +++ b/src/views/progress_bar.rs @@ -211,7 +211,7 @@ impl View for ProgressBar { let label = (self.label_maker)(value, (self.min, self.max)); let offset = HAlign::Center.get_offset(label.len(), printer.size.x); - printer.with_color(ColorStyle::Highlight, |printer| { + printer.with_color(ColorStyle::highlight(), |printer| { printer.with_effect(Effect::Reverse, |printer| { printer.print((offset, 0), &label); }); diff --git a/src/views/radio.rs b/src/views/radio.rs index dacd009..15cd4e3 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -168,7 +168,7 @@ impl View for RadioButton { self.draw_internal(printer) }); } else { - printer.with_color(ColorStyle::Secondary, |printer| { + printer.with_color(ColorStyle::secondary(), |printer| { self.draw_internal(printer) }); } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 942f4a7..4244e9f 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -575,11 +575,11 @@ impl View for SelectView { if self.popup { let style = if !self.enabled { - ColorStyle::Secondary + ColorStyle::secondary() } else if !printer.focused { - ColorStyle::Primary + ColorStyle::primary() } else { - ColorStyle::Highlight + ColorStyle::highlight() }; let x = match printer.size.x.checked_sub(1) { Some(x) => x, @@ -609,7 +609,7 @@ impl View for SelectView { self.scrollbase.draw(printer, |printer, i| { printer.with_selection(i == self.focus(), |printer| { if i != self.focus() && !self.enabled { - printer.with_color(ColorStyle::Secondary, |printer| { + printer.with_color(ColorStyle::secondary(), |printer| { self.draw_item(printer, i) }); } else { diff --git a/src/views/shadow_view.rs b/src/views/shadow_view.rs index 0e945e5..c6cab18 100644 --- a/src/views/shadow_view.rs +++ b/src/views/shadow_view.rs @@ -87,7 +87,7 @@ impl ViewWrapper for ShadowView { return; } - printer.with_color(ColorStyle::Shadow, |printer| { + printer.with_color(ColorStyle::shadow(), |printer| { printer.print_hline((1, h - 1), w - 1, " "); printer.print_vline((w - 1, 1), h - 1, " "); }); diff --git a/src/views/slider_view.rs b/src/views/slider_view.rs index b6f7875..01476ef 100644 --- a/src/views/slider_view.rs +++ b/src/views/slider_view.rs @@ -123,9 +123,9 @@ impl View for SliderView { } let color = if printer.focused { - ColorStyle::Highlight + ColorStyle::highlight() } else { - ColorStyle::HighlightInactive + ColorStyle::highlight_inactive() }; printer.with_color(color, |printer| { printer.print(self.orientation.make_vec(self.value, 0), " "); diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index 72adb2e..acf5b86 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -324,7 +324,7 @@ impl, I: Iterator> Iterator impl View for StackView { fn draw(&self, printer: &Printer) { let last = self.layers.len(); - printer.with_color(ColorStyle::Primary, |printer| { + printer.with_color(ColorStyle::primary(), |printer| { for (i, (v, offset)) in StackPositionIterator::new(self.layers.iter(), printer.size) .enumerate() diff --git a/src/views/text_area.rs b/src/views/text_area.rs index d746b4c..3e72e43 100644 --- a/src/views/text_area.rs +++ b/src/views/text_area.rs @@ -413,7 +413,7 @@ impl View for TextArea { } fn draw(&self, printer: &Printer) { - printer.with_color(ColorStyle::Secondary, |printer| { + printer.with_color(ColorStyle::secondary(), |printer| { let effect = if self.enabled { Effect::Reverse } else {