theme: add typography scale per platforms
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::ramps::{AccentShades, Oklch, contrast_foreground, derive_shades, mix}
|
||||
use crate::system::SystemTheme;
|
||||
use crate::{
|
||||
Borders, ColorTokens, CustomTheme, Elevations, MaterialTokens, Motion, Radius, Scrollbar,
|
||||
SizeTable, Spacing, ThemeVariant,
|
||||
SizeTable, Spacing, ThemeVariant, Typography,
|
||||
};
|
||||
use gpui::{WindowBackgroundAppearance, px};
|
||||
|
||||
@@ -42,6 +42,8 @@ pub struct ResolvedTheme {
|
||||
pub root_font_size: gpui::Pixels,
|
||||
/// The platform's monospace family, for code surfaces.
|
||||
pub mono_font: &'static str,
|
||||
/// The platform's type ladder, resolved at the root font size.
|
||||
pub typography: Typography,
|
||||
pub sizes: SizeTable,
|
||||
pub accessibility: crate::system::AccessibilityPreferences,
|
||||
/// The material a window should open with, after accessibility.
|
||||
@@ -335,6 +337,7 @@ pub(crate) fn resolve(
|
||||
titlebar_height,
|
||||
root_font_size,
|
||||
mono_font: mono_font(),
|
||||
typography: Typography::resolve(system.source, root_font_size),
|
||||
sizes,
|
||||
accessibility,
|
||||
window_background,
|
||||
@@ -357,7 +360,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::system::{AccessibilityPreferences, PartialPalette, SourceKind};
|
||||
use crate::{Elevation, Shadow};
|
||||
use gpui::{Rgba, WindowBackgroundAppearance, rgb};
|
||||
use gpui::{FontWeight, Rgba, WindowBackgroundAppearance, rgb};
|
||||
|
||||
fn hsla(hex: u32) -> gpui::Hsla {
|
||||
gpui::Hsla::from(rgb(hex))
|
||||
@@ -963,4 +966,24 @@ mod tests {
|
||||
assert_eq!(resolved.sizes.medium.text_size, px(20.));
|
||||
assert_eq!(resolved.titlebar_height, px(35.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_platforms_ladder_resolves_at_the_root_font_size_and_rescales() {
|
||||
// macOS states 13pt, so its HIG sizes paint exactly.
|
||||
let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None);
|
||||
stated.root_font_size = Some(px(13.));
|
||||
let native = resolve(&stated, None, None, None);
|
||||
assert_eq!(native.typography.body.size, px(13.));
|
||||
assert_eq!(native.typography.headline.weight, FontWeight::BOLD);
|
||||
|
||||
// A custom root rescales the whole ladder off the platform's base.
|
||||
let custom = CustomTheme {
|
||||
root_font_size: Some(px(26.)),
|
||||
..CustomTheme::default()
|
||||
};
|
||||
let raised = resolve(&stated, None, None, Some(custom));
|
||||
assert_eq!(raised.root_font_size, px(26.));
|
||||
assert_eq!(raised.typography.body.size, px(26.));
|
||||
assert_eq!(raised.typography.large_title.size, px(52.));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user