1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
//! Structures for working with colors and text modifiers.
use tui::style::Style as TuiStyle;
pub use tui::style::{Color, Modifier};
/// Styles that can apply to anything drawn on the screen.
///
/// Styles are composed of foreground colors, background colors,
/// and text modifiers. These fields are optional (modifiers have `Modifier::NONE`),
/// and can be merged together when multiple styles are applied.
///
/// `Style` also conveniently implements `From<Color>`, which creates a style
/// with the provided color as the foreground color.
#[derive(Default, Clone, Copy, PartialEq, Eq)]
pub struct Style(TuiStyle);
impl Style {
pub fn new(fg: Option<Color>, bg: Option<Color>, modifier: Modifier) -> Self {
Self(TuiStyle {
fg,
bg,
add_modifier: modifier,
sub_modifier: Modifier::empty(),
})
}
}
/// `Convert` a color into a `Style` with a specific foreground color.
impl From<Color> for Style {
fn from(color: Color) -> Self {
Self::new(Some(color), None, Modifier::empty())
}
}
impl From<Style> for TuiStyle {
fn from(style: Style) -> Self {
style.0
}
}
impl<'a> From<&'a Style> for Style {
fn from(style: &'a Style) -> Self {
*style
}
}