Struct cursive_core::theme::Palette
source · pub struct Palette { /* private fields */ }
Expand description
Color configuration for the application.
Assign each color role an actual color.
It implements Index
and IndexMut
to access and modify this mapping:
It also implements Extend
to update a batch of colors at
once.
Example
use cursive_core::theme::{BaseColor::*, Color::*, PaletteColor::*};
let mut palette = Palette::default();
assert_eq!(palette[Background], Dark(Blue));
palette[Shadow] = Light(Red);
assert_eq!(palette[Shadow], Light(Red));
let colors = vec![(Shadow, Dark(Green)), (Primary, Light(Blue))];
palette.extend(colors);
assert_eq!(palette[Shadow], Dark(Green));
assert_eq!(palette[Primary], Light(Blue));
Implementations§
source§impl Palette
impl Palette
sourcepub fn custom<'a>(&'a self, key: &str) -> Option<&'a Color>
pub fn custom<'a>(&'a self, key: &str) -> Option<&'a Color>
Returns a custom color from this palette.
Returns None
if the given key was not found.
sourcepub fn merge(&self, namespace: &str) -> Self
pub fn merge(&self, namespace: &str) -> Self
Returns a new palette where the given namespace has been merged.
All values in the namespace will override previous values.
sourcepub fn set_color(&mut self, key: &str, color: Color)
pub fn set_color(&mut self, key: &str, color: Color)
Sets the color for the given key.
This will update either the basic palette or the custom values.
sourcepub fn set_basic_color(
&mut self,
key: &str,
color: Color
) -> Result<(), NoSuchColor>
pub fn set_basic_color(
&mut self,
key: &str,
color: Color
) -> Result<(), NoSuchColor>
Sets a basic color from its name.
Returns Err(())
if key
is not a known PaletteColor
.
sourcepub fn add_namespace(
&mut self,
key: &str,
namespace: HashMap<String, PaletteNode, RandomState>
)
pub fn add_namespace(
&mut self,
key: &str,
namespace: HashMap<String, PaletteNode, RandomState>
)
Adds a color namespace to this palette.
Trait Implementations§
source§impl Default for Palette
impl Default for Palette
Returns the default palette for a cursive application.
Background
=>Dark(Blue)
Shadow
=>Dark(Black)
View
=>Dark(White)
Primary
=>Dark(Black)
Secondary
=>Dark(Blue)
Tertiary
=>Light(White)
TitlePrimary
=>Dark(Red)
TitleSecondary
=>Dark(Yellow)
Highlight
=>Dark(Red)
HighlightInactive
=>Dark(Blue)
HighlightText
=>Dark(White)
source§impl Extend<(PaletteColor, Color)> for Palette
impl Extend<(PaletteColor, Color)> for Palette
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (PaletteColor, Color)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (PaletteColor, Color)>,
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more