Skip to main content

DynamicScheme

Struct DynamicScheme 

Source
pub struct DynamicScheme {
    pub source: Hct,
    pub variant: Variant,
    pub contrast_level: f64,
    pub is_dark: bool,
    pub spec: SpecVersion,
    pub primary_palette: TonalPalette,
    pub secondary_palette: TonalPalette,
    pub tertiary_palette: TonalPalette,
    pub neutral_palette: TonalPalette,
    pub neutral_variant_palette: TonalPalette,
    pub error_palette: TonalPalette,
}
Expand description

The state a DynamicRole resolves against.

use gpui_kit_material_color::dynamic::{
    DynamicRole, DynamicScheme, Hct, SpecVersion, Variant,
};

let scheme = DynamicScheme::new(
    Hct::from_argb(0xff6750a4),
    Variant::TonalSpot,
    false,
    0.0,
    SpecVersion::Spec2021,
);
assert_eq!(scheme.argb(DynamicRole::Primary), 0xff65558f);

Fields§

§source: Hct

The seed.

§variant: Variant

The style.

§contrast_level: f64

-1 is minimum contrast, 0 the design as specified, 0.5 medium, 1 maximum.

§is_dark: bool

Dark mode.

§spec: SpecVersion

The spec actually in force, after Variant::has_2025_spec.

§primary_palette: TonalPalette

Usually colorful.

§secondary_palette: TonalPalette

Usually less colorful.

§tertiary_palette: TonalPalette

Usually a different hue from primary.

§neutral_palette: TonalPalette

Usually not colorful: surfaces.

§neutral_variant_palette: TonalPalette

Slightly more colorful than neutral: outlines and variants.

§error_palette: TonalPalette

Reddish.

Implementations§

Source§

impl DynamicScheme

Source

pub fn new( source: Hct, variant: Variant, is_dark: bool, contrast_level: f64, spec: SpecVersion, ) -> Self

Resolve the palettes of a seed. A non-finite contrast level counts as 0; others are limited to -1..=1.

Source

pub fn piecewise_hue(source: Hct, breakpoints: &[f64], hues: &[f64]) -> f64

The hue in hues at the range of breakpoints holding the source’s hue, or the source’s hue when no range does.

Source

pub fn rotated_hue(source: Hct, breakpoints: &[f64], rotations: &[f64]) -> f64

The source’s hue rotated by the entry of rotations at the range of breakpoints holding it.

Source

pub fn argb(&self, role: DynamicRole) -> u32

The ARGB color of a role.

Source

pub fn hct(&self, role: DynamicRole) -> Hct

The HCT color of a role.

Source

pub fn tone(&self, role: DynamicRole) -> f64

The tone of a role. This resolves contrast constraints; for the color use Self::hct.

Trait Implementations§

Source§

impl Clone for DynamicScheme

Source§

fn clone(&self) -> DynamicScheme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for DynamicScheme

Source§

impl Debug for DynamicScheme

Source§

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

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

impl PartialEq for DynamicScheme

Source§

fn eq(&self, other: &DynamicScheme) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DynamicScheme

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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.