simplify theme crate to builtin-only registry
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use gpui::Hsla;
|
||||
|
||||
use crate::model::{AccentRoles, ThemeColors, ThemeVariant};
|
||||
use crate::model::{AccentRoles, Color, ThemeColors, ThemeVariant};
|
||||
|
||||
fn hsla(color: crate::model::Color) -> Hsla {
|
||||
fn hsla(color: Color) -> Hsla {
|
||||
let packed = ((color.r as u32) << 24)
|
||||
| ((color.g as u32) << 16)
|
||||
| ((color.b as u32) << 8)
|
||||
@@ -10,23 +10,17 @@ fn hsla(color: crate::model::Color) -> Hsla {
|
||||
Hsla::from(gpui::rgba(packed))
|
||||
}
|
||||
|
||||
/// The accent roles a component can consume, pre-resolved to `Hsla` together
|
||||
/// with the derived states (hover/active, contrast-safe text) that several
|
||||
/// components need; computing them here keeps call sites free of color math.
|
||||
/// Accent roles resolved to [`Hsla`], with derived interaction states precomputed.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ResolvedAccentRoles {
|
||||
pub primary: Hsla,
|
||||
pub strong: Hsla,
|
||||
pub wash: Hsla,
|
||||
pub on: Hsla,
|
||||
pub selection: Hsla,
|
||||
pub caret: Hsla,
|
||||
pub activity: Hsla,
|
||||
pub glyph: [Hsla; 3],
|
||||
pub hover: Hsla,
|
||||
pub active: Hsla,
|
||||
pub selected: Hsla,
|
||||
/// Accent text guaranteed readable on `wash`.
|
||||
/// Text guaranteed 4.5:1 readable on `wash`.
|
||||
pub text_on_wash: Hsla,
|
||||
/// Text guaranteed readable on the flat `danger` color.
|
||||
pub on_danger: Hsla,
|
||||
@@ -38,17 +32,9 @@ impl ResolvedAccentRoles {
|
||||
let wash_background = accent.wash.blend_over(background);
|
||||
Self {
|
||||
primary: hsla(accent.primary),
|
||||
strong: hsla(accent.strong),
|
||||
wash: hsla(accent.wash),
|
||||
on: hsla(accent.on),
|
||||
selection: hsla(accent.selection),
|
||||
caret: hsla(accent.caret),
|
||||
activity: hsla(accent.activity),
|
||||
glyph: [
|
||||
hsla(accent.glyph[0]),
|
||||
hsla(accent.glyph[1]),
|
||||
hsla(accent.glyph[2]),
|
||||
],
|
||||
hover: hsla(accent.primary.mix(background, 0.12)),
|
||||
active: hsla(accent.primary.mix(background, 0.2)),
|
||||
selected: hsla(accent.primary.mix(background, 0.28)),
|
||||
@@ -58,8 +44,7 @@ impl ResolvedAccentRoles {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `Hsla` snapshot components render from, rebuilt whenever the active
|
||||
/// variant, accent, or appearance changes.
|
||||
/// The `Hsla` snapshot components render from, rebuilt on every theme change.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ResolvedColors {
|
||||
pub background: Hsla,
|
||||
@@ -92,63 +77,34 @@ pub struct ResolvedColors {
|
||||
|
||||
impl ResolvedColors {
|
||||
pub fn resolve(variant: &ThemeVariant) -> Self {
|
||||
let colors = variant.colors.clone();
|
||||
let ThemeColors {
|
||||
background,
|
||||
shell,
|
||||
raised,
|
||||
card,
|
||||
dialog,
|
||||
overlay,
|
||||
hover,
|
||||
active,
|
||||
border,
|
||||
border_strong,
|
||||
text,
|
||||
text_muted,
|
||||
text_faint,
|
||||
solid,
|
||||
on_solid,
|
||||
danger,
|
||||
danger_muted,
|
||||
warning,
|
||||
warning_muted,
|
||||
success,
|
||||
success_muted,
|
||||
input,
|
||||
cursor,
|
||||
diff_add,
|
||||
diff_delete,
|
||||
diff_hunk,
|
||||
} = colors;
|
||||
|
||||
let colors = &variant.colors;
|
||||
Self {
|
||||
background: hsla(background),
|
||||
shell: hsla(shell),
|
||||
raised: hsla(raised),
|
||||
card: hsla(card),
|
||||
dialog: hsla(dialog),
|
||||
overlay: hsla(overlay),
|
||||
hover: hsla(hover),
|
||||
active: hsla(active),
|
||||
border: hsla(border),
|
||||
border_strong: hsla(border_strong),
|
||||
text: hsla(text),
|
||||
text_muted: hsla(text_muted),
|
||||
text_faint: hsla(text_faint),
|
||||
solid: hsla(solid),
|
||||
on_solid: hsla(on_solid),
|
||||
danger: hsla(danger),
|
||||
danger_muted: hsla(danger_muted),
|
||||
warning: hsla(warning),
|
||||
warning_muted: hsla(warning_muted),
|
||||
success: hsla(success),
|
||||
success_muted: hsla(success_muted),
|
||||
input: hsla(input),
|
||||
cursor: hsla(cursor),
|
||||
diff_add: hsla(diff_add),
|
||||
diff_delete: hsla(diff_delete),
|
||||
diff_hunk: hsla(diff_hunk),
|
||||
background: hsla(colors.background),
|
||||
shell: hsla(colors.shell),
|
||||
raised: hsla(colors.raised),
|
||||
card: hsla(colors.card),
|
||||
dialog: hsla(colors.dialog),
|
||||
overlay: hsla(colors.overlay),
|
||||
hover: hsla(colors.hover),
|
||||
active: hsla(colors.active),
|
||||
border: hsla(colors.border),
|
||||
border_strong: hsla(colors.border_strong),
|
||||
text: hsla(colors.text),
|
||||
text_muted: hsla(colors.text_muted),
|
||||
text_faint: hsla(colors.text_faint),
|
||||
solid: hsla(colors.solid),
|
||||
on_solid: hsla(colors.on_solid),
|
||||
danger: hsla(colors.danger),
|
||||
danger_muted: hsla(colors.danger_muted),
|
||||
warning: hsla(colors.warning),
|
||||
warning_muted: hsla(colors.warning_muted),
|
||||
success: hsla(colors.success),
|
||||
success_muted: hsla(colors.success_muted),
|
||||
input: hsla(colors.input),
|
||||
cursor: hsla(colors.cursor),
|
||||
diff_add: hsla(colors.diff_add),
|
||||
diff_delete: hsla(colors.diff_delete),
|
||||
diff_hunk: hsla(colors.diff_hunk),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user