86 lines
2.6 KiB
Rust
86 lines
2.6 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>,
|
|
/// No platform states a scrim color; preset and user files override it.
|
|
pub overlay: Option<Hsla>,
|
|
/// No platform states a scrollbar thumb color; presets override it.
|
|
pub scrollbar_thumb: 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,
|
|
/// The platform's stated control corner radius, if it has one.
|
|
pub control_radius: Option<Pixels>,
|
|
/// The platform's stated text-field height, if it has one.
|
|
pub input_height: Option<Pixels>,
|
|
/// The platform's native root font size, if it has one.
|
|
pub root_font_size: 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,
|
|
input_height: None,
|
|
root_font_size: None,
|
|
accessibility: AccessibilityPreferences::default(),
|
|
source: SourceKind::Fallback,
|
|
}
|
|
}
|
|
}
|