pub struct Rgb {
pub r: u8,
pub g: u8,
pub b: u8,
}Expand description
A 24-bit sRGB colour.
Fields§
§r: u8Red channel.
g: u8Green channel.
b: u8Blue channel.
Implementations§
Source§impl Rgb
impl Rgb
Sourcepub fn mix(self, other: Self, t: f32) -> Self
pub fn mix(self, other: Self, t: f32) -> Self
Blends towards other: t = 0 gives self, t = 1 gives other.
t is clamped to 0..=1.
Sourcepub fn relative_luminance(self) -> f64
pub fn relative_luminance(self) -> f64
WCAG relative luminance, from 0 (black) to 1 (white).
Sourcepub fn contrast_ratio(self, other: Self) -> f64
pub fn contrast_ratio(self, other: Self) -> f64
WCAG contrast ratio between two colours, from 1 to 21.
Sourcepub fn perceptual_distance(self, other: Self) -> f64
pub fn perceptual_distance(self, other: Self) -> f64
Euclidean distance in OKLab. Around 0.02 is barely visible; 0.10 reads as a clearly different colour.
Sourcepub fn to_ansi256(self) -> u8
pub fn to_ansi256(self) -> u8
Nearest entry of the xterm 256-colour palette (indices 16..=255).
Sourcepub fn to_ansi256_text(self, bg: Self) -> u8
pub fn to_ansi256_text(self, bg: Self) -> u8
The entry of the xterm 256-colour palette this colour takes as text on bg.
Mostly the nearest entry, as Rgb::to_ansi256 gives it. Faint text, such as a page
dimmed behind a dialog, can land on an entry that no longer reads on its background’s —
under 1.6:1 in the WCAG ratio, where a glyph starts to disappear; it then takes the entry
closest to it in OKLab that still keeps 1.6:1, so faint text stays faint rather than
vanishing. Text drawn in the very colour of its background is left as it is, since that
is a fill rather than something to read.
Sourcepub fn to_ansi16(self) -> u8
pub fn to_ansi16(self) -> u8
Nearest of the 16 standard terminal colours (xterm defaults), by distance alone.
This is the plain reduction: on a dark screen every surface tone lands on black here.
What a sixteen-colour frame actually shows is Rgb::to_ansi16_on for backgrounds and
Rgb::to_ansi16_text for text, which keep lifted surfaces and faint text apart from the
ground.
Sourcepub fn from_ansi16(index: u8) -> Self
pub fn from_ansi16(index: u8) -> Self
The colour of entry index of the 16 standard terminal colours, as xterm shows them by
default; an index past 15 gives the last entry, white. A terminal may be themed
differently, so these are the colours a reduction can count on, not the ones a person
necessarily sees.
Sourcepub fn from_ansi256(index: u8) -> Self
pub fn from_ansi256(index: u8) -> Self
The colour of entry index of the xterm 256-colour palette as xterm shows it by default:
the 16 standard colours as Rgb::from_ansi16 gives them, then the 6×6×6 colour cube,
then the 24 greys from 8 to 238.
Sourcepub fn to_ansi16_on(self, ground: Self) -> u8
pub fn to_ansi16_on(self, ground: Self) -> u8
The entry of the 16 standard colours this colour takes as a background on a screen whose
ground is ground (the theme’s canvas).
Mostly the nearest entry, as Rgb::to_ansi16 gives it. The exception is a tone the eye
tells from the ground in full colour — at least 0.05 away in OKLab, the same distance
under which a floating surface melts into the ground — that would still land on the
ground’s own entry: it moves one step along the grey ladder black, bright black, white,
bright white, away from the ground. On a dark theme the ground stays black and raised
surfaces, tab strips and dialogs become bright black; on a light theme they step down
from bright white to white. Panels a shade off the ground stay on it, as in full colour
they barely differ.
Sourcepub fn to_ansi16_text(self, bg: Self, ground: Self) -> u8
pub fn to_ansi16_text(self, bg: Self, ground: Self) -> u8
The entry of the 16 standard colours this colour takes as text on bg, on a screen whose
ground is ground.
Both colours are reduced as Rgb::to_ansi16_on does. When the text would then no longer
read on its background — under 1.6:1 in the WCAG ratio, which is where a glyph starts to
disappear — it takes the quietest grey that still keeps 3:1 against it: faint text stays
faint rather than vanishing. On bright black that is white, on black bright black. Text
drawn in the very colour of its background is left as it is, since that is a fill rather
than something to read.
Trait Implementations§
impl Copy for Rgb
impl Eq for Rgb
impl StructuralPartialEq for Rgb
Auto Trait Implementations§
impl Freeze for Rgb
impl RefUnwindSafe for Rgb
impl Send for Rgb
impl Sync for Rgb
impl Unpin for Rgb
impl UnsafeUnpin for Rgb
impl UnwindSafe for Rgb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more