theme: build out the theme engine core with resolve pipeline

This commit is contained in:
2026-10-28 10:54:02 +07:00
parent b4d3359d4f
commit 12d4120bfd
14 changed files with 1434 additions and 37 deletions
+72
View File
@@ -0,0 +1,72 @@
//! The normalized snapshot a platform adapter produces.
use gpui::Hsla;
use crate::ThemeVariant;
/// Accessibility preferences read from the OS, forwarded into resolution.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct AccessibilityPreferences {
pub high_contrast: bool,
pub reduce_motion: bool,
pub reduce_transparency: bool,
}
/// Which adapter produced a [`SystemTheme`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SourceKind {
#[default]
Fallback,
Macos,
}
impl SourceKind {
pub fn label(self) -> &'static str {
match self {
Self::Fallback => "neutral fallback",
Self::Macos => "macOS (NSColor)",
}
}
}
/// A partial palette with optional colors.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct PartialPalette {
pub background: Option<Hsla>,
pub foreground: Option<Hsla>,
pub surface: Option<Hsla>,
pub surface_foreground: Option<Hsla>,
pub primary_foreground: Option<Hsla>,
pub accent_foreground: Option<Hsla>,
pub secondary: Option<Hsla>,
pub secondary_foreground: Option<Hsla>,
pub muted: Option<Hsla>,
pub muted_foreground: Option<Hsla>,
pub destructive: Option<Hsla>,
pub border: Option<Hsla>,
pub input: Option<Hsla>,
pub ring: Option<Hsla>,
pub selection: Option<Hsla>,
}
/// A normalized snapshot of the running system's theme.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SystemTheme {
pub variant: ThemeVariant,
pub accent: Option<Hsla>,
pub palette: PartialPalette,
pub accessibility: AccessibilityPreferences,
pub source: SourceKind,
}
impl SystemTheme {
pub fn fallback(variant: ThemeVariant) -> Self {
Self {
variant,
accent: None,
palette: PartialPalette::default(),
accessibility: AccessibilityPreferences::default(),
source: SourceKind::Fallback,
}
}
}