Unify theme sizing and spacing on Base UI metrics
- Read only mode, accent, accessibility, and native window material from the OS. - Replace platform palettes, metrics, type ramps, borders, and elevations with unified tokens. - Align controls, overlays, and data rows with Base UI sizing.
This commit is contained in:
+102
-190
@@ -19,7 +19,7 @@ pub use colors::{ColorTokens, MaterialTokens};
|
||||
pub use definition::ThemeDefinition;
|
||||
pub use ramps::{AccentShades, Oklch};
|
||||
pub use resolve::{Ramps, ResolvedTheme};
|
||||
pub use system::{AccessibilityPreferences, PartialPalette, SourceKind, SystemTheme};
|
||||
pub use system::{AccessibilityPreferences, SourceKind, SystemTheme};
|
||||
pub use typography::{TextRole, TypeMetrics, Typeset, Typography};
|
||||
|
||||
use gpui::{
|
||||
@@ -159,21 +159,19 @@ pub struct Theme {
|
||||
pub material: MaterialTokens,
|
||||
pub ramps: Ramps,
|
||||
pub radius: Radius,
|
||||
/// Per-platform border and focus chrome.
|
||||
pub borders: Borders,
|
||||
pub spacing: Spacing,
|
||||
pub elevations: Elevations,
|
||||
/// Overlay transition timing; gpui's animation primitives do the rest.
|
||||
pub motion: Motion,
|
||||
/// Overlay scrollbar geometry.
|
||||
pub scrollbar: Scrollbar,
|
||||
/// The height the window's titlebar strips draw at, per the platform.
|
||||
/// The height the window's titlebar strips draw at.
|
||||
pub titlebar_height: Pixels,
|
||||
/// The platform's native root font size; rem-based sizing scales with it.
|
||||
/// The theme's root font size; rem-based sizing scales with it.
|
||||
pub root_font_size: Pixels,
|
||||
/// The platform's monospace family, for code surfaces.
|
||||
/// The monospace family, for code surfaces.
|
||||
pub mono_font: &'static str,
|
||||
/// The platform's type ladder, resolved at the root font size.
|
||||
/// The type ladder, resolved at the root font size.
|
||||
pub typography: Typography,
|
||||
pub sizes: SizeTable,
|
||||
pub accessibility: AccessibilityPreferences,
|
||||
@@ -196,7 +194,6 @@ impl Theme {
|
||||
material: resolved.material,
|
||||
ramps: resolved.ramps,
|
||||
radius: resolved.radius,
|
||||
borders: resolved.borders,
|
||||
spacing: resolved.spacing,
|
||||
elevations: resolved.elevations,
|
||||
motion: resolved.motion,
|
||||
@@ -264,54 +261,7 @@ impl Default for Radius {
|
||||
}
|
||||
}
|
||||
|
||||
/// Which surfaces keep a 1px border, per the platform's chrome: Windows and
|
||||
/// KDE frame their controls, macOS and GNOME paint fills.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Borders {
|
||||
/// Filled actions keep a border (Windows, KDE).
|
||||
pub buttons: bool,
|
||||
/// Text fields and selects keep a border.
|
||||
pub fields: bool,
|
||||
/// Floating layers keep a border.
|
||||
pub overlays: bool,
|
||||
/// Keyboard focus paints an accent ring around the control.
|
||||
pub focus_ring: bool,
|
||||
}
|
||||
|
||||
impl Borders {
|
||||
pub(crate) fn for_platform(source: SourceKind, variant: ThemeVariant) -> Self {
|
||||
let overlays = variant == ThemeVariant::Dark;
|
||||
|
||||
match source {
|
||||
SourceKind::Windows | SourceKind::Kde => Self {
|
||||
buttons: true,
|
||||
fields: true,
|
||||
overlays: true,
|
||||
focus_ring: false,
|
||||
},
|
||||
SourceKind::Macos => Self {
|
||||
buttons: false,
|
||||
fields: true,
|
||||
overlays,
|
||||
focus_ring: true,
|
||||
},
|
||||
SourceKind::Omarchy | SourceKind::Gnome => Self {
|
||||
buttons: false,
|
||||
fields: false,
|
||||
overlays,
|
||||
focus_ring: true,
|
||||
},
|
||||
SourceKind::Fallback => Self {
|
||||
buttons: true,
|
||||
fields: true,
|
||||
overlays: true,
|
||||
focus_ring: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The spacing rhythm of the platform: paddings and gaps step by this unit.
|
||||
/// The spacing rhythm: paddings and gaps step by this unit.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Spacing {
|
||||
pub unit: Pixels,
|
||||
@@ -420,7 +370,7 @@ pub struct Elevations {
|
||||
}
|
||||
|
||||
impl Elevations {
|
||||
pub(crate) fn for_platform(source: SourceKind, variant: ThemeVariant) -> Self {
|
||||
pub(crate) fn for_variant(variant: ThemeVariant) -> Self {
|
||||
if variant == ThemeVariant::Dark {
|
||||
return Self {
|
||||
popover: Elevation::none(),
|
||||
@@ -429,41 +379,21 @@ impl Elevations {
|
||||
};
|
||||
}
|
||||
|
||||
match source {
|
||||
SourceKind::Macos => Self {
|
||||
popover: Elevation::layered(
|
||||
Shadow::black(0., 4., 24., 0.12),
|
||||
Shadow::black(0., 1., 1., 0.05),
|
||||
),
|
||||
dialog: Elevation::layered(
|
||||
Shadow::black(0., 8., 40., 0.14),
|
||||
Shadow::black(0., 1., 2., 0.06),
|
||||
),
|
||||
control: Elevation::single(Shadow::black(0., 1., 2., 0.1)),
|
||||
},
|
||||
SourceKind::Windows => Self {
|
||||
popover: Elevation::layered(
|
||||
Shadow::black(0., 8., 16., 0.14),
|
||||
Shadow::black(0., 2., 4., 0.1),
|
||||
),
|
||||
dialog: Elevation::layered(
|
||||
Shadow::black(0., 16., 32., 0.16),
|
||||
Shadow::black(0., 4., 8., 0.1),
|
||||
),
|
||||
control: Elevation::single(Shadow::black(0., 1., 2., 0.12)),
|
||||
},
|
||||
SourceKind::Omarchy | SourceKind::Kde | SourceKind::Gnome | SourceKind::Fallback => {
|
||||
Self {
|
||||
popover: Elevation::single(Shadow::black(0., 3., 6., 0.2)),
|
||||
dialog: Elevation::single(Shadow::black(0., 9., 18., 0.24)),
|
||||
control: Elevation::single(Shadow::black(0., 1., 2., 0.16)),
|
||||
}
|
||||
}
|
||||
Self {
|
||||
popover: Elevation::layered(
|
||||
Shadow::black(0., 4., 24., 0.12),
|
||||
Shadow::black(0., 1., 1., 0.05),
|
||||
),
|
||||
dialog: Elevation::layered(
|
||||
Shadow::black(0., 8., 40., 0.14),
|
||||
Shadow::black(0., 1., 2., 0.06),
|
||||
),
|
||||
control: Elevation::single(Shadow::black(0., 1., 2., 0.1)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Overlay transition timings; the platform refines these per phase.
|
||||
/// Overlay transition timings.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Motion {
|
||||
/// The enter transition of popovers, menus, and dialogs.
|
||||
@@ -478,8 +408,7 @@ impl Default for Motion {
|
||||
}
|
||||
}
|
||||
|
||||
/// Overlay scrollbar presentation, transcribed from the platform's overlay
|
||||
/// crollbars.
|
||||
/// Overlay scrollbar presentation.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Scrollbar {
|
||||
/// The painted thumb's thickness.
|
||||
@@ -549,85 +478,105 @@ pub struct SizeTable {
|
||||
impl SizeTable {
|
||||
pub fn with_root_font_size(rem_size: Pixels) -> Self {
|
||||
struct ClassFactors {
|
||||
height: f32,
|
||||
padding: f32,
|
||||
text: f32,
|
||||
icon: f32,
|
||||
avatar: f32,
|
||||
strip: f32,
|
||||
inset: f32,
|
||||
floor_icon: bool,
|
||||
control_height: f32,
|
||||
input_height: f32,
|
||||
padding_x: f32,
|
||||
text_size: f32,
|
||||
icon_size: f32,
|
||||
dense_icon_size: f32,
|
||||
indicator_size: f32,
|
||||
avatar_size: f32,
|
||||
caption_size: f32,
|
||||
dense_padding_x: f32,
|
||||
plate_inset: f32,
|
||||
strip_height: f32,
|
||||
menu_item_height: f32,
|
||||
switch_height: f32,
|
||||
switch_width: f32,
|
||||
switch_knob: f32,
|
||||
}
|
||||
|
||||
let small = ClassFactors {
|
||||
height: 1.5,
|
||||
padding: 0.75,
|
||||
text: 0.85,
|
||||
icon: 0.875,
|
||||
avatar: 1.125,
|
||||
strip: 1.5,
|
||||
inset: 0.125,
|
||||
floor_icon: false,
|
||||
control_height: 1.75,
|
||||
input_height: 1.75,
|
||||
padding_x: 0.5,
|
||||
text_size: 0.75,
|
||||
icon_size: 0.875,
|
||||
dense_icon_size: 0.75,
|
||||
indicator_size: 0.875,
|
||||
avatar_size: 1.5,
|
||||
caption_size: 0.75,
|
||||
dense_padding_x: 0.5,
|
||||
plate_inset: 0.125,
|
||||
strip_height: 1.75,
|
||||
menu_item_height: 1.75,
|
||||
switch_height: 1.125,
|
||||
switch_width: 2.0,
|
||||
switch_knob: 0.75,
|
||||
};
|
||||
|
||||
let medium = ClassFactors {
|
||||
height: 1.75,
|
||||
padding: 1.0,
|
||||
text: 1.0,
|
||||
icon: 1.0,
|
||||
avatar: 1.5,
|
||||
strip: 2.0,
|
||||
inset: 0.25,
|
||||
floor_icon: true,
|
||||
control_height: 2.0,
|
||||
input_height: 2.0,
|
||||
padding_x: 0.75,
|
||||
text_size: 0.875,
|
||||
icon_size: 1.0,
|
||||
dense_icon_size: 0.75,
|
||||
indicator_size: 1.0,
|
||||
avatar_size: 2.0,
|
||||
caption_size: 0.75,
|
||||
dense_padding_x: 0.5,
|
||||
plate_inset: 0.125,
|
||||
strip_height: 2.0,
|
||||
menu_item_height: 2.0,
|
||||
switch_height: 1.25,
|
||||
switch_width: 2.25,
|
||||
switch_knob: 0.875,
|
||||
};
|
||||
|
||||
let large = ClassFactors {
|
||||
height: 2.25,
|
||||
padding: 1.25,
|
||||
text: 1.15,
|
||||
icon: 1.25,
|
||||
avatar: 2.0,
|
||||
strip: 3.0,
|
||||
inset: 0.375,
|
||||
floor_icon: true,
|
||||
control_height: 2.5,
|
||||
input_height: 2.5,
|
||||
padding_x: 1.0,
|
||||
text_size: 1.0,
|
||||
icon_size: 1.25,
|
||||
dense_icon_size: 0.9375,
|
||||
indicator_size: 1.25,
|
||||
avatar_size: 2.5,
|
||||
caption_size: 0.875,
|
||||
dense_padding_x: 0.75,
|
||||
plate_inset: 0.1875,
|
||||
strip_height: 2.5,
|
||||
menu_item_height: 2.25,
|
||||
switch_height: 1.5,
|
||||
switch_width: 2.75,
|
||||
switch_knob: 1.125,
|
||||
};
|
||||
|
||||
let metrics = |f: &ClassFactors| {
|
||||
let icon_size = if f.floor_icon {
|
||||
(rem_size * f.icon).max(px(16.))
|
||||
} else {
|
||||
rem_size * f.icon
|
||||
};
|
||||
let switch_height = rem_size * f.height * 0.75;
|
||||
ControlMetrics {
|
||||
control_height: rem_size * f.height,
|
||||
input_height: rem_size * (f.height + 0.125),
|
||||
padding_x: rem_size * f.padding,
|
||||
text_size: rem_size * f.text,
|
||||
icon_size,
|
||||
dense_icon_size: icon_size * 0.75,
|
||||
indicator_size: rem_size * f.height * 0.7,
|
||||
avatar_size: rem_size * f.avatar,
|
||||
caption_size: rem_size * f.text,
|
||||
dense_padding_x: rem_size * f.padding * 0.75,
|
||||
plate_inset: rem_size * f.inset,
|
||||
strip_height: rem_size * f.strip,
|
||||
menu_item_height: rem_size * f.height * 0.85,
|
||||
switch_height,
|
||||
switch_width: switch_height * 2.25,
|
||||
switch_knob: switch_height * 0.85,
|
||||
}
|
||||
let metrics = |f: &ClassFactors| ControlMetrics {
|
||||
control_height: rem_size * f.control_height,
|
||||
input_height: rem_size * f.input_height,
|
||||
padding_x: rem_size * f.padding_x,
|
||||
text_size: rem_size * f.text_size,
|
||||
icon_size: rem_size * f.icon_size,
|
||||
dense_icon_size: rem_size * f.dense_icon_size,
|
||||
indicator_size: rem_size * f.indicator_size,
|
||||
avatar_size: rem_size * f.avatar_size,
|
||||
caption_size: rem_size * f.caption_size,
|
||||
dense_padding_x: rem_size * f.dense_padding_x,
|
||||
plate_inset: rem_size * f.plate_inset,
|
||||
strip_height: rem_size * f.strip_height,
|
||||
menu_item_height: rem_size * f.menu_item_height,
|
||||
switch_height: rem_size * f.switch_height,
|
||||
switch_width: rem_size * f.switch_width,
|
||||
switch_knob: rem_size * f.switch_knob,
|
||||
};
|
||||
|
||||
let mut table = Self {
|
||||
Self {
|
||||
small: metrics(&small),
|
||||
medium: metrics(&medium),
|
||||
large: metrics(&large),
|
||||
};
|
||||
|
||||
table.small.caption_size = table.small.text_size * 0.85;
|
||||
table.large.caption_size = table.medium.text_size;
|
||||
table
|
||||
}
|
||||
}
|
||||
|
||||
/// The metrics for `size`.
|
||||
@@ -638,43 +587,6 @@ impl SizeTable {
|
||||
Size::Large => self.large,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the medium class's text-field height to the platform's stated value.
|
||||
pub fn set_input_height(&mut self, medium_input_height: Pixels) {
|
||||
let ratio = medium_input_height / self.medium.input_height;
|
||||
self.small.input_height = (self.small.input_height * ratio).floor();
|
||||
self.medium.input_height = medium_input_height;
|
||||
self.large.input_height = (self.large.input_height * ratio).floor();
|
||||
}
|
||||
|
||||
/// Sets the medium class's control height to the platform's stated value.
|
||||
pub fn set_control_height(&mut self, medium_control_height: Pixels) {
|
||||
let ratio = medium_control_height / self.medium.control_height;
|
||||
self.small.control_height = (self.small.control_height * ratio).floor();
|
||||
self.medium.control_height = medium_control_height;
|
||||
self.large.control_height = (self.large.control_height * ratio).floor();
|
||||
}
|
||||
|
||||
/// Sets the medium class's menu row height to the platform's stated value.
|
||||
pub fn set_menu_item_height(&mut self, medium_menu_item_height: Pixels) {
|
||||
let ratio = medium_menu_item_height / self.medium.menu_item_height;
|
||||
self.small.menu_item_height *= ratio;
|
||||
self.medium.menu_item_height = medium_menu_item_height;
|
||||
self.large.menu_item_height *= ratio;
|
||||
}
|
||||
|
||||
/// Sets the medium class's switch dimensions to the platform's stated values.
|
||||
pub fn set_switch_metrics(&mut self, track_height: Pixels, track_width: Pixels, knob: Pixels) {
|
||||
let ratio = track_height / self.medium.switch_height;
|
||||
for metrics in [&mut self.small, &mut self.large] {
|
||||
metrics.switch_height *= ratio;
|
||||
metrics.switch_width *= ratio;
|
||||
metrics.switch_knob *= ratio;
|
||||
}
|
||||
self.medium.switch_height = track_height;
|
||||
self.medium.switch_width = track_width;
|
||||
self.medium.switch_knob = knob;
|
||||
}
|
||||
}
|
||||
|
||||
/// User customizations layered over the resolved theme.
|
||||
|
||||
Reference in New Issue
Block a user