rat_theme

Struct Scheme

source
pub struct Scheme {
Show 17 fields pub white: [Color; 4], pub black: [Color; 4], pub gray: [Color; 4], pub red: [Color; 4], pub orange: [Color; 4], pub yellow: [Color; 4], pub limegreen: [Color; 4], pub green: [Color; 4], pub bluegreen: [Color; 4], pub cyan: [Color; 4], pub blue: [Color; 4], pub deepblue: [Color; 4], pub purple: [Color; 4], pub magenta: [Color; 4], pub redpink: [Color; 4], pub primary: [Color; 4], pub secondary: [Color; 4],
}
Expand description

Color scheme.

This provides the palette used for a theme.

The ideas packed in here are

  • provide two colors for highlighting and accents.
  • I always want some white, black and gray.
  • I don’t want to miss out anything, so go once round the hue in HSV. Take steps of 30° then we hit pretty much anything interesting.
  • Just one variant of each color is not enough, make it 4.

Fields§

§white: [Color; 4]§black: [Color; 4]§gray: [Color; 4]§red: [Color; 4]§orange: [Color; 4]§yellow: [Color; 4]§limegreen: [Color; 4]§green: [Color; 4]§bluegreen: [Color; 4]§cyan: [Color; 4]§blue: [Color; 4]§deepblue: [Color; 4]§purple: [Color; 4]§magenta: [Color; 4]§redpink: [Color; 4]§primary: [Color; 4]§secondary: [Color; 4]

Implementations§

source§

impl Scheme

source

pub fn style(&self, color: Color) -> Style

Create a style with the given background color. Foreground is calculated with text_color.

source

pub const fn linear4(c0: u32, c1: u32) -> [Color; 4]

Linear interpolation between the two colors.

source

pub fn text_color(&self, color: Color) -> Color

This gives back white[3] or black[0] for text foreground providing good contrast to the given background.

This converts RGB to grayscale and takes the grayscale value of VGA cyan as threshold, which is about 105 out of 255. This point is a bit arbitrary, just based on what I perceive as acceptable. But it produces a good reading contrast in my experience.

For the named colors it takes the VGA equivalent as a base. For indexed colors it splits the range in half as an estimate.

Trait Implementations§

source§

impl Clone for Scheme

source§

fn clone(&self) -> Scheme

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Scheme

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Scheme

source§

fn default() -> Scheme

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Scheme

§

impl RefUnwindSafe for Scheme

§

impl Send for Scheme

§

impl Sync for Scheme

§

impl Unpin for Scheme

§

impl UnwindSafe for Scheme

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.