75 lines
2.0 KiB
Rust
75 lines
2.0 KiB
Rust
//! The normalized snapshot a platform adapter produces.
|
|
|
|
use gpui::{Hsla, Pixels};
|
|
|
|
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 control_radius: Option<Pixels>,
|
|
pub accessibility: AccessibilityPreferences,
|
|
pub source: SourceKind,
|
|
}
|
|
|
|
impl SystemTheme {
|
|
pub fn fallback(variant: ThemeVariant) -> Self {
|
|
Self {
|
|
variant,
|
|
accent: None,
|
|
palette: PartialPalette::default(),
|
|
control_radius: None,
|
|
accessibility: AccessibilityPreferences::default(),
|
|
source: SourceKind::Fallback,
|
|
}
|
|
}
|
|
}
|