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
sourceimpl Palette
impl Palette
sourcepub fn custom(&'a self, key: &str) -> Option<&'a Color>
pub fn custom(&'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) -> Palette
pub fn merge(&self, namespace: &str) -> Palette
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
sourceimpl 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)
sourceimpl Extend<(PaletteColor, Color)> for Palette
impl Extend<(PaletteColor, Color)> for Palette
sourcefn 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
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl Index<PaletteColor> for Palette
impl Index<PaletteColor> for Palette
sourceimpl IndexMut<PaletteColor> for Palette
impl IndexMut<PaletteColor> for Palette
sourcefn index_mut(&mut self, palette_color: PaletteColor) -> &mut Color
fn index_mut(&mut self, palette_color: PaletteColor) -> &mut Color
Performs the mutable indexing (container[index]
) operation. Read more
sourceimpl PartialEq<Palette> for Palette
impl PartialEq<Palette> for Palette
impl Eq for Palette
impl StructuralEq for Palette
impl StructuralPartialEq for Palette
Auto Trait Implementations
impl RefUnwindSafe for Palette
impl Send for Palette
impl Sync for Palette
impl Unpin for Palette
impl UnwindSafe for Palette
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more