Skip to main content

Theme

Struct Theme 

Source
#[non_exhaustive]
pub struct Theme {
Show 18 fields pub background: Rgba, pub surface: Rgba, pub surface_raised: Rgba, pub sunken: Rgba, pub text: Rgba, pub text_muted: Rgba, pub accent: Rgba, pub accent_text: Rgba, pub border: Rgba, pub selection: Rgba, pub hover: Rgba, pub danger: Rgba, pub warning: Rgba, pub success: Rgba, pub done: Rgba, pub link: Rgba, pub scrollbar: Rgba, pub focus: Rgba,
}
Expand description

The color tokens of one theme.

§Example

use crisol_core::theme::Theme;

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§background: Rgba

Window, editor, and panel background (visuals.panel_fill).

§surface: Rgba

Raised chrome: menus, dialogs, the sidebar, the tab strip (visuals.window_fill).

§surface_raised: Rgba

A second raised surface for cards.

§sunken: Rgba

Sunken surfaces: text fields, steppers, segmented controls (extreme_bg_color).

§text: Rgba

Primary text.

§text_muted: Rgba

Secondary text: hints, descriptions, inactive tabs.

§accent: Rgba

Brand accent.

§accent_text: Rgba

Text drawn on the accent.

§border: Rgba

Borders and separators.

§selection: Rgba

Selection background: selected rows, active segments, primary buttons.

§hover: Rgba

Hover background for rows and icon buttons.

§danger: Rgba

Errors and destructive actions.

§warning: Rgba

Warnings and conflict banners.

§success: Rgba

Success messages.

§done: Rgba

“Done” purple.

§link: Rgba

Hyperlinks.

§scrollbar: Rgba

Scrollbar handle.

§focus: Rgba

Keyboard focus ring, hovered borders, and the active-row marker.

Implementations§

Source§

impl Theme

Source

pub fn high_contrast(self) -> Self

A high-contrast variant of this theme: pure black or white surfaces, maximum text contrast, stronger borders, and a readable brand accent.

Source

pub fn ensure_aa(self) -> Self

Adjust text and accent pairs until they reach WCAG AA (4.5:1 for text, 3:1 for large text and controls), preserving the theme’s light/dark polarity.

Source

pub fn to_css_variables(&self) -> String

The theme as #rrggbb CSS custom properties.

Source

pub fn from_vscode_json(text: &str) -> Result<Self, ThemeImportError>

Available on crate feature serde only.

Import a VS Code color theme (colors object); syntax token colors are accepted but do not replace the workbench tokens.

§Errors

When the JSON is malformed or lacks editor.background and foreground.

Source

pub fn to_json(&self) -> Value

Available on crate feature serde only.

The theme as JSON tokens.

Source§

impl Theme

Source

pub fn light() -> Self

GitHub Light.

Source

pub fn dark() -> Self

GitHub Dark.

Source

pub fn for_id(id: ThemeId) -> Self

The tokens for a theme identifier.

Source

pub fn is_dark(&self) -> bool

Whether the surface is dark.

Source

pub fn with_accent(self, accent: Rgba) -> Self

The same tokens with a new brand color: accent, focus, link, selection, and accent_text are derived from it so they keep AA contrast on this base.

use crisol_core::color::Rgba;
use crisol_core::theme::{Theme, contrast_ratio};

let brand = Theme::dark().with_accent(Rgba::from_rgb(0xe0, 0x6c, 0x2b));
assert!(contrast_ratio(brand.link, brand.background) >= 4.5);
assert!(contrast_ratio(brand.accent_text, brand.accent) >= 4.5);
Source

pub fn accessibility_issues(&self) -> Vec<(&'static str, f32)>

The pairs that miss WCAG AA (4.5:1 for text, 3:1 for the focus ring), with their ratio. Empty for every built-in theme; check your own themes with it.

Source

pub fn tokens(&self) -> [(&'static str, Rgba); 18]

Every token, by its stable field name.

This is the table frozen in tests/fixtures/theme/golden-0.1.3.json.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

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 Theme

Source§

impl Debug for Theme

Source§

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

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

impl Default for Theme

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Theme

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Theme

Source§

impl PartialEq for Theme

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Theme

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Theme

Auto Trait Implementations§

§

impl Forget for Theme

§

impl Freeze for Theme

§

impl Move for Theme

§

impl RefUnwindSafe for Theme

§

impl Send for Theme

§

impl Sync for Theme

§

impl Unpin for Theme

§

impl UnsafeUnpin for Theme

§

impl UnwindSafe for Theme

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

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

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> 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> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.