diff --git a/crates/core/src/alert.rs b/crates/core/src/alert.rs index ae6dca5..8eeaee6 100644 --- a/crates/core/src/alert.rs +++ b/crates/core/src/alert.rs @@ -8,7 +8,10 @@ use gpui::{ ease_out_quint, }; use gpui_native_icons::{Icon, IconRole}; -use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _}; +use gpui_native_theme::{ + ALERT_EDGE_WIDTH, ALERT_STACK_WIDTH, ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, + Typeset as _, +}; use gpui_native_utils::ResultLogErr as _; use crate::button::{Button, ButtonVariant}; @@ -150,7 +153,6 @@ impl RenderOnce for Alert { let metrics = theme.sizes.resolve(Size::Medium); let icon_size = metrics.icon_size; let dense_icon_size = metrics.dense_icon_size; - let caption_size = metrics.caption_size; let content = v_flex() .flex_1() @@ -171,7 +173,7 @@ impl RenderOnce for Alert { }; alert.child( div() - .text_size(caption_size) + .text_size(metrics.text_size) .text_color(color) .child(message), ) @@ -181,7 +183,7 @@ impl RenderOnce for Alert { Button::new((self.id.clone(), "alert-close")) .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .accessibility_label("Dismiss") .on_click(move |_, _window, cx| on_dismiss(cx)) }); @@ -189,11 +191,7 @@ impl RenderOnce for Alert { match self.presentation { AlertStyle::Overlay => { let surface = theme.colors.surface; - let border = if theme.borders.overlays { - theme.colors.border - } else { - surface - }; + let border = theme.colors.border; div() .id(self.id.clone()) @@ -231,7 +229,13 @@ impl RenderOnce for Alert { .overflow_hidden() .bg(ramp.subtle) .refine_style(&self.style) - .child(div().flex_none().w_1p5().self_stretch().bg(ramp.base)) + .child( + div() + .flex_none() + .w(ALERT_EDGE_WIDTH) + .self_stretch() + .bg(ramp.base), + ) .child( div() .flex_1() @@ -239,7 +243,7 @@ impl RenderOnce for Alert { .items_start() .gap_3() .px_3() - .py_2p5() + .py_2() .when_some(self.icon.clone(), |alert, icon_glyph| { alert.child( div() @@ -247,7 +251,7 @@ impl RenderOnce for Alert { .flex() .items_center() .justify_center() - .size_6() + .size(theme.sizes.small.avatar_size) .rounded(theme.radius.full) .bg(ramp.base) .child(icon_glyph.size(dense_icon_size).color(ramp.foreground)), @@ -375,7 +379,7 @@ impl RenderOnce for AlertsView { .absolute() .top_4() .right_4() - .w_80() + .w(ALERT_STACK_WIDTH) .flex() .flex_col() .items_end() diff --git a/crates/core/src/avatar.rs b/crates/core/src/avatar.rs index 2fc4333..2e92423 100644 --- a/crates/core/src/avatar.rs +++ b/crates/core/src/avatar.rs @@ -92,7 +92,13 @@ impl gpui::Styled for Avatar { impl RenderOnce for Avatar { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); - let side = theme.sizes.resolve(self.size).avatar_size; + // Avatars sit one class below the shared control scale. + let size = match self.size { + Size::XSmall | Size::Small => Size::XSmall, + Size::Medium => Size::Small, + Size::Large => Size::Medium, + }; + let side = theme.sizes.resolve(size).avatar_size; let radius = if self.fully_rounded { theme.radius.full diff --git a/crates/core/src/button.rs b/crates/core/src/button.rs index e435da0..5d90ad2 100644 --- a/crates/core/src/button.rs +++ b/crates/core/src/button.rs @@ -7,7 +7,7 @@ use gpui::{ StyleRefinement, Styled as _, Window, canvas, relative, transparent_black, }; use gpui_native_icons::Icon; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::{focus_ring, record_anchor_bounds}; use std::rc::Rc; @@ -207,10 +207,8 @@ impl RenderOnce for Button { let theme = cx.theme(); let colors = theme.colors; let ramps = theme.ramps; - let borders = theme.borders; let metrics = theme.sizes.resolve(self.size); - let show_border = borders.buttons && self.variant != ButtonVariant::Ghost; let on_click = self.on_click; let a11y_label = self.a11y_label.or_else(|| self.label.clone()); let is_icon_only = self.icon.is_some() && self.label.is_none() && self.children.is_empty(); @@ -224,10 +222,10 @@ impl RenderOnce for Button { ramps.primary.pressed, ), ButtonVariant::Secondary => ( - Some(colors.secondary), - colors.secondary_foreground, - ramps.secondary.hover, - ramps.secondary.pressed, + Some(colors.surface), + colors.foreground, + colors.muted, + colors.muted_hover, ), ButtonVariant::Ghost => ( None, @@ -243,17 +241,23 @@ impl RenderOnce for Button { ), }; - let (border, hover_border, pressed_border) = if show_border { - (colors.border, colors.border, colors.border) - } else { - match background { - Some(fill) => (fill, hover, pressed), - None => ( - transparent_black(), - transparent_black(), - transparent_black(), - ), - } + let (border, hover_border, pressed_border) = match self.variant { + ButtonVariant::Primary => ( + ramps.primary.base, + ramps.primary.hover, + ramps.primary.pressed, + ), + ButtonVariant::Secondary => (colors.border, colors.border, colors.border), + ButtonVariant::Ghost => ( + transparent_black(), + transparent_black(), + transparent_black(), + ), + ButtonVariant::Destructive => ( + ramps.destructive.base, + ramps.destructive.hover, + ramps.destructive.pressed, + ), }; h_flex() @@ -267,16 +271,10 @@ impl RenderOnce for Button { ButtonSide::Left => button.justify_start(), ButtonSide::Right => button.justify_end(), }) - .h(metrics.control_height + BORDER_WIDTH * 2.0) - .when(is_icon_only, |button| { - button.w(metrics.control_height + BORDER_WIDTH * 2.0) - }) + .h(metrics.control_height) + .when(is_icon_only, |button| button.w(metrics.control_height)) .when(!is_icon_only && self.padded, |button| { - button - .when(self.icon.is_some(), |button| { - button.px(metrics.dense_padding_x) - }) - .when(self.icon.is_none(), |button| button.px(metrics.padding_x)) + button.px(metrics.padding_x) }) .line_height(relative(1.0)) .rounded(theme.radius.control) @@ -324,7 +322,7 @@ impl RenderOnce for Button { .absolute() .inset_0(), ) - .when(self.disabled, |button| button.opacity(0.5)) + .when(self.disabled, |button| button.opacity(DISABLED_OPACITY)) .when_some(self.tooltip, |button, tooltip| { button.tooltip(move |window, cx| tooltip(window, cx)) }) diff --git a/crates/core/src/checkbox.rs b/crates/core/src/checkbox.rs index f8b5705..ac09989 100644 --- a/crates/core/src/checkbox.rs +++ b/crates/core/src/checkbox.rs @@ -8,7 +8,7 @@ use gpui::{ SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, }; use gpui_native_icons::{IconRole, icon}; -use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -123,7 +123,7 @@ impl RenderOnce for Checkbox { h_flex() .id(self.id) - .gap_1p5() + .gap_2() .text_size(metrics.text_size) .refine_style(&self.style) .when_some(self.debug_selector, |checkbox, selector| { @@ -132,7 +132,7 @@ impl RenderOnce for Checkbox { .role(Role::CheckBox) .when_some(a11y_label, |checkbox, label| checkbox.aria_label(label)) .aria_toggled(Toggled::from(self.checked)) - .when(self.disabled, |checkbox| checkbox.opacity(0.5)) + .when(self.disabled, |checkbox| checkbox.opacity(DISABLED_OPACITY)) .when(!self.disabled, |checkbox| { checkbox .cursor_pointer() @@ -154,7 +154,11 @@ impl RenderOnce for Checkbox { indicator .bg(ramps.primary.base) .border_color(ramps.primary.base) - .hover(|style| style.bg(ramps.primary.hover)) + .hover(|style| { + style + .bg(ramps.primary.hover) + .border_color(ramps.primary.hover) + }) .child( icon(IconRole::Check) .size(metrics.dense_icon_size) diff --git a/crates/core/src/combobox.rs b/crates/core/src/combobox.rs index 22e3d10..d8a4dd4 100644 --- a/crates/core/src/combobox.rs +++ b/crates/core/src/combobox.rs @@ -17,7 +17,7 @@ use gpui::{ }; use gpui_native_icons::{IconRole, icon}; use gpui_native_theme::ActiveTheme as _; -use gpui_native_theme::{BORDER_WIDTH, POPUP_MAX_HEIGHT, Size}; +use gpui_native_theme::{COMBOBOX_MIN_WIDTH, COMBOBOX_WIDTH, POPUP_MAX_HEIGHT, Size}; use gpui_native_utils::ResultLogErr as _; use crate::common::{OVERLAY_LAYER, Sizable, StyledExt as _, h_flex, v_flex}; @@ -479,16 +479,11 @@ where let theme = cx.theme(); let metrics = theme.sizes.resolve(self.size); - let panel_border = if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }; ( metrics, theme.colors, theme.radius, - panel_border, + theme.colors.border, theme.spacing.unit, theme.elevations.popover.shadows(), ) @@ -536,8 +531,8 @@ where .id(id.clone()) .key_context(COMBOBOX_CONTEXT) .relative() - .w(window.rem_size() * 12.0) - .min_w(window.rem_size() * 6.0) + .w(COMBOBOX_WIDTH) + .min_w(COMBOBOX_MIN_WIDTH) .refine_style(&self.style) .role(Role::ComboBox) .aria_expanded(open) @@ -587,7 +582,7 @@ where h_flex() .absolute() .right(metrics.dense_padding_x) - .top((metrics.input_height + BORDER_WIDTH * 2.0 - icon_size) / 2.) + .top((metrics.input_height - icon_size) / 2.) .child(chevron), ) .when(open, |wrapper| { @@ -618,6 +613,7 @@ where .gap_2() .px_2() .py_1() + .min_h(metrics.control_height) .rounded(radius.sm) .when(highlighted, |row| row.bg(colors.muted)) .when(!highlighted, |row| row.hover(|row| row.bg(colors.muted))) @@ -686,7 +682,7 @@ where let popup_width = wrapper_bounds .borrow() .map(|bounds| bounds.size.width) - .unwrap_or_else(|| window.rem_size() * 12.0); + .unwrap_or(COMBOBOX_WIDTH); let panel = v_flex() .id((id.clone(), "panel")) diff --git a/crates/core/src/command_palette.rs b/crates/core/src/command_palette.rs index 5d03204..200c86b 100644 --- a/crates/core/src/command_palette.rs +++ b/crates/core/src/command_palette.rs @@ -331,18 +331,15 @@ impl Render for CommandPaletteState { return div().into_any_element(); } - let (colors, radius, metrics, panel_border, shadows) = { + let (colors, radius, metrics, panel_border, shadows, titlebar_height) = { let theme = cx.theme(); ( theme.colors, theme.radius, theme.sizes.resolve(Size::default()), - if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }, + theme.colors.border, theme.elevations.dialog.shadows(), + theme.titlebar_height, ) }; @@ -370,6 +367,9 @@ impl Render for CommandPaletteState { .gap_2() .px_2() .py_1() + .min_h(metrics.control_height) + .text_size(metrics.text_size) + .line_height(relative(1.0)) .rounded(radius.sm) .when(highlighted, |row| row.bg(colors.muted)) .when(!highlighted, |row| row.hover(|row| row.bg(colors.muted))) @@ -519,7 +519,7 @@ impl Render for CommandPaletteState { .flex() .justify_center() .items_start() - .pt_10() + .pt(titlebar_height) .child(scrim) .child(panel), ) diff --git a/crates/core/src/common.rs b/crates/core/src/common.rs index 7a078f3..7110ad1 100644 --- a/crates/core/src/common.rs +++ b/crates/core/src/common.rs @@ -24,6 +24,14 @@ pub trait Sizable: Sized { /// Applies the size to the component's fields. fn apply_size(&mut self, size: Size); + /// Sets `Size::XSmall`. + fn xsmall(self) -> Self + where + Self: Sized, + { + self.with_size(Size::XSmall) + } + /// Sets `Size::Small`. fn small(self) -> Self where diff --git a/crates/core/src/dialog.rs b/crates/core/src/dialog.rs index 63359cd..a135332 100644 --- a/crates/core/src/dialog.rs +++ b/crates/core/src/dialog.rs @@ -8,7 +8,7 @@ use gpui::{ Styled as _, Window, canvas, deferred, div, ease_out_quint, relative, }; use gpui_native_icons::IconRole; -use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; +use gpui_native_theme::{ActiveTheme as _, DIALOG_MIN_WIDTH, TextRole, Typeset as _}; use crate::button::{Button, ButtonVariant}; use crate::common::{DIALOG_LAYER, Sizable, StyledExt as _, v_flex}; @@ -160,11 +160,7 @@ impl RenderOnce for Dialog { let theme = cx.theme(); ( theme.colors.overlay, - if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }, + theme.colors.border, theme.colors.foreground, theme.colors.surface, theme.radius.overlay, @@ -207,11 +203,13 @@ impl RenderOnce for Dialog { .role(role) .aria_label(label) .when_some(self.min_width, |panel, width| panel.min_w(width)) - .when(self.min_width.is_none(), |panel| panel.min_w_80()) + .when(self.min_width.is_none(), |panel| { + panel.min_w(DIALOG_MIN_WIDTH) + }) .max_w(relative(0.9)) .when_some(height, |panel, height| panel.h(height)) .p_4() - .gap_3() + .gap_4() .bg(surface) .text_color(foreground) .rounded(radius) @@ -247,7 +245,7 @@ impl RenderOnce for Dialog { Button::new("dialog-close") .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .debug_selector(|| "dialog-close".to_string()) .accessibility_label("Close") .on_click({ @@ -278,7 +276,7 @@ impl RenderOnce for Dialog { }) }) .when_some(actions, |panel, actions| { - panel.child(div().flex().justify_end().gap_2().children(actions)) + panel.child(div().flex().justify_end().gap_3().children(actions)) }) .child( canvas(|_, _, _| {}, { diff --git a/crates/core/src/dropdown_menu.rs b/crates/core/src/dropdown_menu.rs index ae2fe99..d2b1aa6 100644 --- a/crates/core/src/dropdown_menu.rs +++ b/crates/core/src/dropdown_menu.rs @@ -11,7 +11,7 @@ use gpui::{ div, relative, }; use gpui_native_icons::{Icon, IconRole, icon}; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::{focus_handle, focus_ring}; use crate::button::ButtonVariant; @@ -80,7 +80,7 @@ impl DropdownMenu { self } - /// Shows an icon beside the label. + /// Shows an icon. Omitting the label renders an icon-only trigger. pub fn icon(mut self, icon: I) -> Self where I: Into, @@ -186,7 +186,6 @@ impl RenderOnce for DropdownMenu { let radius = theme.radius.control; let ring = colors.ring; - let show_border = theme.borders.buttons && self.variant != ButtonVariant::Ghost; let (panel_chrome, enter_duration) = MenuChrome::read(cx); let (background, foreground, hover, pressed) = match self.variant { @@ -197,10 +196,10 @@ impl RenderOnce for DropdownMenu { ramps.primary.pressed, ), ButtonVariant::Secondary => ( - Some(colors.secondary), - colors.secondary_foreground, - ramps.secondary.hover, - ramps.secondary.pressed, + Some(colors.surface), + colors.foreground, + colors.muted, + colors.muted_hover, ), ButtonVariant::Ghost => ( None, @@ -216,13 +215,15 @@ impl RenderOnce for DropdownMenu { ), }; - let border = if show_border { - colors.border - } else { - background.unwrap_or_else(gpui::transparent_black) + let border = match self.variant { + ButtonVariant::Primary => ramps.primary.base, + ButtonVariant::Secondary => colors.border, + ButtonVariant::Ghost => gpui::transparent_black(), + ButtonVariant::Destructive => ramps.destructive.base, }; let split = self.on_click.is_some(); + let icon_only = self.icon.is_some() && self.label.is_none() && !split; let inert = self.disabled || self.loading; let label = self @@ -262,6 +263,7 @@ impl RenderOnce for DropdownMenu { }) .justify_center() .h_full() + .when(icon_only, |zone| zone.w_full()) .gap_2() .line_height(relative(1.0)) .text_size(metrics.text_size) @@ -269,20 +271,22 @@ impl RenderOnce for DropdownMenu { .role(Role::Button) .when_some(a11y_label, |zone, label| zone.aria_label(label)) .aria_expanded(self.open) - .px(if split && self.icon.is_none() { - metrics.padding_x + .px(if icon_only { + gpui::Pixels::ZERO } else { - metrics.dense_padding_x + metrics.padding_x }) .when(split, |zone| zone.rounded_l(radius)) .when(!split, |zone| { zone.rounded(radius) .when(self.open, |zone| zone.bg(pressed)) - .child( - icon(IconRole::ChevronDown) - .size(metrics.dense_icon_size) - .color(foreground), - ) + }) + .when(!icon_only && !split, |zone| { + zone.child( + icon(IconRole::ChevronDown) + .size(metrics.dense_icon_size) + .color(foreground), + ) }) .child( h_flex() @@ -375,12 +379,17 @@ impl RenderOnce for DropdownMenu { ); let trigger = h_flex() - .h(metrics.control_height + BORDER_WIDTH * 2.0) + .debug_selector({ + let id = self.id.clone(); + move || format!("{id}-trigger") + }) + .h(metrics.control_height) + .when(icon_only, |trigger| trigger.w(metrics.control_height)) .rounded(radius) .border_1() .border_color(border) .when_some(background, |trigger, background| trigger.bg(background)) - .when(self.disabled, |trigger| trigger.opacity(0.5)) + .when(self.disabled, |trigger| trigger.opacity(DISABLED_OPACITY)) .when(!inert, |trigger| { trigger .track_focus(&focus) diff --git a/crates/core/src/field.rs b/crates/core/src/field.rs index f24eea1..607b768 100644 --- a/crates/core/src/field.rs +++ b/crates/core/src/field.rs @@ -5,7 +5,7 @@ use gpui::{ AnyElement, App, ElementId, InteractiveElement as _, IntoElement, ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled, Window, div, }; -use gpui_native_theme::ActiveTheme as _; +use gpui_native_theme::{ActiveTheme as _, TextRole, Typeset as _}; use crate::common::{StyledExt, h_flex, v_flex}; @@ -99,7 +99,12 @@ impl RenderOnce for Field { let id = id.clone(); move || format!("{id}-label") }) - .text_size(metrics.text_size) + .when(self.description.is_some(), |title| { + title.typeset(TextRole::Headline, cx) + }) + .when(self.description.is_none(), |title| { + title.typeset(TextRole::Callout, cx) + }) .child(self.label.clone()); let control = h_flex() diff --git a/crates/core/src/input.rs b/crates/core/src/input.rs index c9edfc1..1a8dc89 100644 --- a/crates/core/src/input.rs +++ b/crates/core/src/input.rs @@ -16,10 +16,9 @@ use gpui::{ }; use gpui_native_icons::IconRole; use gpui_native_theme::{ - ActiveTheme as _, BORDER_WIDTH, CARET_WIDTH, ColorTokens, Size, UNDERLINE_WIDTH, + ActiveTheme as _, CARET_WIDTH, ColorTokens, DISABLED_OPACITY, Size, UNDERLINE_WIDTH, WHEEL_LINE_HEIGHT, }; -use gpui_native_utils::focus_ring; use crate::button::{Button, ButtonVariant}; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -1991,7 +1990,7 @@ impl RenderOnce for Input { let recording = focused && !self.disabled && !self.state.read(cx).is_read_only(); let small = theme.sizes.resolve(Size::Small); - let docked_height = small.control_height + BORDER_WIDTH * 2.0; + let docked_height = small.control_height; let edge_inset = ((metrics.input_height - docked_height) / 2.0).max(Pixels::ZERO); let vertical_inset = metrics.dense_padding_x * 0.5; @@ -2014,7 +2013,7 @@ impl RenderOnce for Input { let field_height = line_height.map_or(metrics.input_height, |line_height| { line_height * self.rows as f32 + vertical_inset * 2.0 - }) + BORDER_WIDTH * 2.0; + }); let fallback_label = self .a11y_label @@ -2148,28 +2147,19 @@ impl RenderOnce for Input { } else { metrics.dense_padding_x }) - .gap_1p5() + .gap_2() .rounded(radius.control) .bg(colors.input) .text_size(metrics.text_size) .text_color(colors.foreground) .border_1() - .border_color(if theme.borders.fields { - colors.border - } else { - colors.input - }) + .border_color(colors.border) .refine_style(&self.style) - .when(self.disabled, |input| input.opacity(0.5)) + .when(self.disabled, |input| input.opacity(DISABLED_OPACITY)) .when(!self.disabled, |input| { input.track_focus(&focus_handle).tab_stop(true) }) - .when(focused && !theme.borders.focus_ring, |input| { - input.border_color(colors.ring) - }) - .when(focused && theme.borders.focus_ring, |input| { - input.shadow(focus_ring(colors.ring)) - }) + .when(focused, |input| input.border_color(colors.ring)) .when_some(self.prefix, |input, prefix| { input.child(edge_zone("input-prefix", prefix)) }) diff --git a/crates/core/src/link.rs b/crates/core/src/link.rs index 4ce6ba8..775ce16 100644 --- a/crates/core/src/link.rs +++ b/crates/core/src/link.rs @@ -4,7 +4,7 @@ use gpui::{ RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, }; -use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -113,12 +113,12 @@ impl RenderOnce for Link { h_flex() .id(self.id) .text_size(metrics.text_size) - .text_color(colors.accent) + .text_color(ramps.primary.base) .underline() .refine_style(&self.style) .role(Role::Link) .when_some(a11y_label, |link, label| link.aria_label(label)) - .when(self.disabled, |link| link.opacity(0.5)) + .when(self.disabled, |link| link.opacity(DISABLED_OPACITY)) .when(!self.disabled, |link| { link.cursor_pointer() .focusable() diff --git a/crates/core/src/menu.rs b/crates/core/src/menu.rs index 6085a85..038aaa5 100644 --- a/crates/core/src/menu.rs +++ b/crates/core/src/menu.rs @@ -12,7 +12,7 @@ use gpui::{ Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative, }; use gpui_native_icons::{Icon, IconRole, icon as icon_glyph}; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, POPUP_MAX_HEIGHT}; +use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, MENU_MIN_WIDTH, POPUP_MAX_HEIGHT}; use gpui_native_utils::focus_handle; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex}; @@ -171,7 +171,6 @@ impl FluentBuilder for MenuItem {} pub(crate) struct MenuChrome { surface: gpui::Hsla, border: gpui::Hsla, - panel_border: gpui::Hsla, foreground: gpui::Hsla, muted_foreground: gpui::Hsla, muted_hover: gpui::Hsla, @@ -214,11 +213,6 @@ impl MenuChrome { Self { surface: theme.colors.surface, border: theme.colors.border, - panel_border: if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }, foreground: theme.colors.foreground, muted_foreground: theme.colors.muted_foreground, muted_hover: theme.colors.muted_hover, @@ -691,18 +685,15 @@ fn menu_panel( .role(Role::Menu) .aria_label(params.label) .when_some(params.min_width, |panel, width| panel.min_w(width)) - .when(params.min_width.is_none(), |panel| panel.min_w_56()) + .when(params.min_width.is_none(), |panel| { + panel.min_w(MENU_MIN_WIDTH) + }) .p(params.chrome.spacing_unit) .bg(params.chrome.surface) .text_color(params.chrome.foreground) .rounded(params.chrome.radius_overlay) .border_1() - // A flyout overlaps its parent, so it always wears a visible border. - .border_color(if params.is_flyout { - params.chrome.border - } else { - params.chrome.panel_border - }) + .border_color(params.chrome.border) .shadow(params.chrome.shadow.clone()) .overflow_hidden() .on_mouse_down_out({ @@ -963,7 +954,7 @@ fn row_shell( .items_center() .gap_2() .min_h(chrome.menu_item_height) - .px(chrome.spacing_unit * 2.0) + .px(chrome.spacing_unit * 4.0) .text_size(chrome.text_size) .line_height(relative(1.0)) .rounded(chrome.radius_sm) diff --git a/crates/core/src/popover.rs b/crates/core/src/popover.rs index d08e796..afbe6e4 100644 --- a/crates/core/src/popover.rs +++ b/crates/core/src/popover.rs @@ -8,7 +8,7 @@ use gpui::{ ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point, }; -use gpui_native_theme::ActiveTheme as _; +use gpui_native_theme::{ActiveTheme as _, POPOVER_MIN_WIDTH}; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex}; @@ -107,11 +107,7 @@ impl RenderOnce for Popover { theme.radius, theme.elevations.popover.shadows(), theme.motion.overlay, - if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }, + theme.colors.border, theme.spacing.unit, ) }; @@ -185,7 +181,7 @@ impl RenderOnce for Popover { .track_focus(&focus) .role(Role::Dialog) .aria_label(label) - .min_w_32() + .min_w(POPOVER_MIN_WIDTH) .bg(colors.surface) .text_color(colors.surface_foreground) .rounded(radius.overlay) diff --git a/crates/core/src/radio.rs b/crates/core/src/radio.rs index d848e0b..8ca324a 100644 --- a/crates/core/src/radio.rs +++ b/crates/core/src/radio.rs @@ -4,7 +4,7 @@ use gpui::{ SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, div, }; -use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex, v_flex}; @@ -189,11 +189,11 @@ where h_flex() .id(radio.id) - .gap_1p5() + .gap_2() .role(Role::RadioButton) .when_some(a11y_label, |row, label| row.aria_label(label)) .aria_toggled(Toggled::from(is_selected)) - .when(disabled, |row| row.opacity(0.5)) + .when(disabled, |row| row.opacity(DISABLED_OPACITY)) .when(!disabled, move |row| { let value = radio.value.clone(); row.cursor_pointer() @@ -217,7 +217,11 @@ where indicator .bg(ramps.primary.base) .border_color(ramps.primary.base) - .hover(|style| style.bg(ramps.primary.hover)) + .hover(|style| { + style + .bg(ramps.primary.hover) + .border_color(ramps.primary.hover) + }) .child( div() .size(metrics.indicator_size / 2.0) diff --git a/crates/core/src/segmented.rs b/crates/core/src/segmented.rs index e5f90f7..027c18d 100644 --- a/crates/core/src/segmented.rs +++ b/crates/core/src/segmented.rs @@ -164,7 +164,7 @@ where let track_height = metrics.strip_height; let track_inset = metrics.plate_inset; let horizontal_padding = metrics.dense_padding_x; - let text_size = metrics.caption_size; + let text_size = metrics.text_size; let icon_size = metrics.icon_size; let selected_index = self @@ -218,7 +218,7 @@ where h_flex() .id((ElementId::from("segment"), segment.label.clone())) - .gap_1p5() + .gap_2() .justify_center() .cursor_pointer() .h_full() diff --git a/crates/core/src/select.rs b/crates/core/src/select.rs index 979cea8..c6f65b4 100644 --- a/crates/core/src/select.rs +++ b/crates/core/src/select.rs @@ -7,8 +7,8 @@ use gpui::{ Window, canvas, }; use gpui_native_icons::{Icon, IconRole, icon}; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; -use gpui_native_utils::{focus_handle, focus_ring}; +use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_utils::focus_handle; use crate::common::{Sizable, StyledExt, h_flex}; use crate::menu::{Menu, MenuItem}; @@ -182,8 +182,6 @@ where let muted_foreground = theme.colors.muted_foreground; let radius = theme.radius.control; let icon_size = metrics.dense_icon_size; - let fields_bordered = theme.borders.fields; - let focus_ring_on = theme.borders.focus_ring; let label = self .a11y_label @@ -209,18 +207,8 @@ where let is_open = *open.read(cx); let open_for_items = open.clone(); - let (rest_border, hover_border) = if fields_bordered { - ( - if is_open && !focus_ring_on { - ring - } else { - border - }, - border, - ) - } else { - (input, muted) - }; + let rest_border = if is_open { ring } else { border }; + let hover_border = rest_border; let selected_index = self.selected.as_ref().and_then(|value| { self.options @@ -252,7 +240,7 @@ where .aria_expanded(is_open) .track_focus(&focus) .tab_stop(true) - .focus_visible(move |style| style.shadow(focus_ring(ring))) + .focus_visible(move |style| style.border_color(ring)) .on_key_down({ let open = open.clone(); move |event: &KeyDownEvent, _window, cx| { @@ -266,10 +254,11 @@ where }) .cursor_pointer() .justify_between() - .gap_2() + .gap_3() .w_full() - .h(metrics.input_height + BORDER_WIDTH * 2.0) - .px(metrics.dense_padding_x) + .h(metrics.input_height) + .pl(metrics.dense_padding_x) + .pr(metrics.plate_inset * 2.0) .rounded(radius) .border_1() .border_color(rest_border) @@ -280,9 +269,6 @@ where } else { muted_foreground }) - .when(is_open && focus_ring_on, |trigger| { - trigger.shadow(focus_ring(ring)) - }) .hover(|style| style.bg(muted).border_color(hover_border)) .child(trigger_text.clone()) .child( diff --git a/crates/core/src/slider.rs b/crates/core/src/slider.rs index c3ebfaa..e75d927 100644 --- a/crates/core/src/slider.rs +++ b/crates/core/src/slider.rs @@ -8,7 +8,7 @@ use gpui::{ SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas, div, relative, }; -use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -133,9 +133,9 @@ impl RenderOnce for Slider { let radius = theme.radius; let metrics = theme.sizes.resolve(self.size); - let row_height = metrics.icon_size; + let row_height = metrics.icon_size * 2.5; let track_height = metrics.icon_size / 4.0; - let knob = metrics.icon_size * 1.25; + let knob = metrics.indicator_size; let value = self.value.clamp(self.min, self.max); let fraction = if self.max > self.min { @@ -186,7 +186,7 @@ impl RenderOnce for Slider { .aria_numeric_value(f64::from(value)) .aria_min_numeric_value(f64::from(self.min)) .aria_max_numeric_value(f64::from(self.max)) - .when(self.disabled, |slider| slider.opacity(0.5)) + .when(self.disabled, |slider| slider.opacity(DISABLED_OPACITY)) .when(!self.disabled, |slider| { slider .track_focus(&focus_handle) diff --git a/crates/core/src/speech.rs b/crates/core/src/speech.rs index 8d996f4..cffd21f 100644 --- a/crates/core/src/speech.rs +++ b/crates/core/src/speech.rs @@ -19,7 +19,7 @@ use gpui::{ StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative, }; use gpui_native_icons::{IconRole, icon}; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, Size}; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, SPEECH_WAVEFORM_WIDTH, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -743,14 +743,14 @@ impl RenderOnce for SpeechButton { .group(group.clone()) .role(Role::Button) .justify_center() - .h(metrics.control_height + BORDER_WIDTH * 2.0) + .h(metrics.control_height) .px(metrics.dense_padding_x) .gap_0p5() .rounded(theme.radius.control) .text_color(foreground) .when(capturing, |button| button.bg(colors.muted)) .refine_style(&self.style) - .when(disabled, |button| button.opacity(0.5)) + .when(disabled, |button| button.opacity(DISABLED_OPACITY)) .aria_label(label.clone()) .tooltip(Tooltip::text(label)) .child(if stopping { @@ -877,7 +877,7 @@ impl RenderOnce for SpeechWaveform { .justify_end() .gap_0p5() .h(metrics.icon_size) - .w_24() + .w(SPEECH_WAVEFORM_WIDTH) .overflow_hidden() .children(levels.iter().map(|level| { div() diff --git a/crates/core/src/switch.rs b/crates/core/src/switch.rs index b9ac546..c688e95 100644 --- a/crates/core/src/switch.rs +++ b/crates/core/src/switch.rs @@ -6,7 +6,7 @@ use gpui::{ RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, div, px, }; -use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size}; +use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, CONTROL_SPRING, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -109,8 +109,9 @@ impl RenderOnce for Switch { let track_width = metrics.switch_width; let knob = metrics.switch_knob; - let inset = (track_height - knob) / 2.; - let travel = track_width - knob - inset * 2.; + // Absolute children sit inside the track's border, so remove it from the inset. + let inset = (track_height - knob) / 2. - BORDER_WIDTH; + let travel = track_width - BORDER_WIDTH * 2. - knob - inset * 2.; let next = !self.checked; let on_change = self.on_change; @@ -122,13 +123,13 @@ impl RenderOnce for Switch { h_flex() .id(self.id) - .gap_1p5() + .gap_2() .text_size(metrics.text_size) .refine_style(&self.style) .role(Role::Switch) .when_some(a11y_label, |switch, label| switch.aria_label(label)) .aria_toggled(Toggled::from(self.checked)) - .when(self.disabled, |switch| switch.opacity(0.5)) + .when(self.disabled, |switch| switch.opacity(DISABLED_OPACITY)) .when(!self.disabled, |switch| { switch .cursor_pointer() @@ -147,12 +148,20 @@ impl RenderOnce for Switch { .w(track_width) .h(track_height) .rounded(theme.radius.full) + .border_1() .when(self.checked, |track| { track .bg(ramps.primary.base) - .hover(|style| style.bg(ramps.primary.hover)) + .border_color(ramps.primary.base) + .hover(|style| { + style + .bg(ramps.primary.hover) + .border_color(ramps.primary.hover) + }) + }) + .when(!self.checked, |track| { + track.bg(colors.input).border_color(colors.border) }) - .when(!self.checked, |track| track.bg(colors.border)) .child( div() .absolute() diff --git a/crates/core/src/toast.rs b/crates/core/src/toast.rs index 7fe02bb..66fd005 100644 --- a/crates/core/src/toast.rs +++ b/crates/core/src/toast.rs @@ -274,16 +274,12 @@ impl ToastEntry { fn pill(&self, toasts: &Entity, cx: &App) -> gpui::Stateful { let theme = cx.theme(); let surface = theme.colors.surface; - let border = if theme.borders.overlays { - theme.colors.border - } else { - surface - }; + let border = theme.colors.border; let foreground = theme.colors.foreground; let radius = theme.radius.full; let shadows = theme.elevations.popover.shadows(); - let icon_size = theme.sizes.small.icon_size; - let text_size = theme.sizes.small.text_size; + let icon_size = theme.sizes.medium.icon_size; + let text_size = theme.sizes.medium.text_size; let toast = &self.toast; let toasts = toasts.clone(); let id = self.id; @@ -296,6 +292,7 @@ impl ToastEntry { .max_w(TOAST_MAX_WIDTH) .flex() .items_center() + .gap_2() .py_1p5() .px_3() .bg(surface) @@ -308,7 +305,6 @@ impl ToastEntry { pill.child( div() .flex_none() - .mr_2() .flex() .items_center() .child(icon.size(icon_size).color(foreground)), @@ -316,6 +312,7 @@ impl ToastEntry { }) .child( div() + .flex_1() .min_w(px(0.)) .truncate() .text_size(text_size) @@ -325,7 +322,7 @@ impl ToastEntry { .when_some(toast.action.clone(), |pill, action| { let toasts = toasts.clone(); pill.child( - div().flex_none().ml_2p5().child( + div().flex_none().child( Button::new(("toast-action", id)) .label(action.label.clone()) .variant(ButtonVariant::Primary) @@ -340,7 +337,7 @@ impl ToastEntry { ) }) .child( - div().flex_none().ml_4().child( + div().flex_none().child( Button::new(("toast-close", id)) .icon(IconRole::Close) .variant(ButtonVariant::Ghost) diff --git a/crates/core/src/toggle.rs b/crates/core/src/toggle.rs index 8aaba45..7797c59 100644 --- a/crates/core/src/toggle.rs +++ b/crates/core/src/toggle.rs @@ -3,7 +3,8 @@ use gpui::{ App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, }; -use gpui_native_theme::{ActiveTheme as _, Size}; +use gpui_native_icons::Icon; +use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size}; use gpui_native_utils::focus_ring; use crate::common::{Sizable, StyledExt as _, h_flex}; @@ -17,6 +18,7 @@ type ChangeHandler = Box; pub struct Toggle { id: ElementId, label: Option, + icon: Option, pressed: bool, size: Size, disabled: bool, @@ -34,6 +36,7 @@ impl Toggle { Self { id: id.into(), label: None, + icon: None, pressed: false, size: Size::default(), disabled: false, @@ -52,6 +55,15 @@ impl Toggle { self } + /// Shows an icon. Omitting the label renders an icon-only toggle. + pub fn icon(mut self, icon: I) -> Self + where + I: Into, + { + self.icon = Some(icon.into()); + self + } + /// Sets the current pressed state; the toggle never owns it. pub fn pressed(mut self, pressed: bool) -> Self { self.pressed = pressed; @@ -104,12 +116,16 @@ impl RenderOnce for Toggle { let on_change = self.on_change; let next = !self.pressed; let a11y_label = self.a11y_label.or_else(|| self.label.clone()); + let icon_only = self.icon.is_some() && self.label.is_none(); h_flex() .id(self.id) .justify_center() .h(metrics.control_height) - .px(metrics.dense_padding_x) + .when(icon_only, |toggle| { + toggle.w(metrics.control_height).px(gpui::Pixels::ZERO) + }) + .when(!icon_only, |toggle| toggle.px(metrics.dense_padding_x)) .rounded(theme.radius.control) .text_size(metrics.text_size) .text_color(colors.foreground) @@ -127,7 +143,7 @@ impl RenderOnce for Toggle { .active(|style| style.bg(ramps.secondary.hover)) }) .refine_style(&self.style) - .when(self.disabled, |toggle| toggle.opacity(0.5)) + .when(self.disabled, |toggle| toggle.opacity(DISABLED_OPACITY)) .when(!self.disabled, |toggle| { toggle .cursor_pointer() @@ -138,6 +154,13 @@ impl RenderOnce for Toggle { toggle.on_click(move |_, window, cx| on_change(next, window, cx)) }) }) - .when_some(self.label, |toggle, label| toggle.child(label)) + .child( + h_flex() + .gap_2() + .when_some(self.icon, |content, icon| { + content.child(icon.size(metrics.icon_size)) + }) + .when_some(self.label, |content, label| content.child(label)), + ) } } diff --git a/crates/core/src/tooltip.rs b/crates/core/src/tooltip.rs index b393380..4d47e7b 100644 --- a/crates/core/src/tooltip.rs +++ b/crates/core/src/tooltip.rs @@ -64,18 +64,15 @@ impl Render for Tooltip { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { // Copied out: the mutable reads below need `cx` free of this borrow. let theme = cx.theme(); - let text_size = theme.sizes.small.text_size; + let text_size = theme.sizes.medium.text_size; + let line_height = theme.typography.callout.line_height; let spacing_unit = theme.spacing.unit; let surface = theme.colors.surface; let surface_foreground = theme.colors.surface_foreground; let radius_sm = theme.radius.sm; let shadows = theme.elevations.popover.shadows(); - let border = if theme.borders.overlays { - theme.colors.border - } else { - theme.colors.surface - }; + let border = theme.colors.border; let build_panel = || { div() @@ -91,6 +88,7 @@ impl Render for Tooltip { .rounded(radius_sm) .shadow(shadows.clone()) .text_size(text_size) + .line_height(line_height) .text_color(surface_foreground) .child(self.text.clone()) }; @@ -106,7 +104,7 @@ impl Render for Tooltip { cx, ) .map(|bounds| bounds.size.height) - .unwrap_or_else(|| text_size * 1.5 + window.rem_size() * 0.5 + BORDER_WIDTH * 2.0); + .unwrap_or_else(|| line_height + spacing_unit * 2.0 + BORDER_WIDTH * 2.0); let below = viewport_height - spacing_unit - parent.bottom(); let above = parent.top() - spacing_unit; diff --git a/crates/core/tests/sizing.rs b/crates/core/tests/sizing.rs new file mode 100644 index 0000000..5abb86b --- /dev/null +++ b/crates/core/tests/sizing.rs @@ -0,0 +1,61 @@ +#![cfg(all(feature = "button", feature = "dropdown_menu"))] + +use gpui::{ + Context, IntoElement, ParentElement as _, Render, Styled as _, TestAppContext, + VisualTestContext, Window, div, px, size, +}; +use gpui_native_core::button::Button; +use gpui_native_core::common::Sizable as _; +use gpui_native_core::dropdown_menu::DropdownMenu; +use gpui_native_core::menu::MenuItem; +use gpui_native_icons::IconRole; +use gpui_native_theme::Theme; + +struct Harness; + +impl Render for Harness { + fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { + div() + .size_full() + .flex() + .flex_col() + .gap_2() + .child( + Button::new("height-probe") + .label("Probe") + .debug_selector(|| "height-probe".to_string()), + ) + .child( + Button::new("xsmall-height-probe") + .label("Probe") + .xsmall() + .debug_selector(|| "xsmall-height-probe".to_string()), + ) + .child( + DropdownMenu::new("icon-only-dropdown") + .icon(IconRole::More) + .accessibility_label("More actions") + .items(|_, _| vec![MenuItem::new("One")]), + ) + } +} + +#[gpui::test] +fn buttons_render_at_their_token_heights(cx: &mut TestAppContext) { + cx.update(Theme::init); + let window = cx.open_window(size(px(400.), px(400.)), |_, _| Harness); + let mut cx = VisualTestContext::from_window(window.into(), cx); + cx.run_until_parked(); + + let medium = cx.debug_bounds("height-probe").expect("button laid out"); + let xsmall = cx + .debug_bounds("xsmall-height-probe") + .expect("xsmall button laid out"); + let icon_only = cx + .debug_bounds("icon-only-dropdown-trigger") + .expect("icon-only dropdown laid out"); + + assert_eq!(medium.size.height, px(32.0)); + assert_eq!(xsmall.size.height, px(20.0)); + assert_eq!(icon_only.size, size(px(32.0), px(32.0))); +} diff --git a/crates/data/src/list.rs b/crates/data/src/list.rs index 02880ce..78ccc10 100644 --- a/crates/data/src/list.rs +++ b/crates/data/src/list.rs @@ -224,6 +224,7 @@ impl ListItem { .gap_2() .px_2() .py_1() + .min_h(theme.sizes.medium.control_height) .rounded(theme.radius.sm) .role(Role::ListItem) .aria_selected(selected) diff --git a/crates/data/src/sidebar.rs b/crates/data/src/sidebar.rs index 0bc306b..89db673 100644 --- a/crates/data/src/sidebar.rs +++ b/crates/data/src/sidebar.rs @@ -8,11 +8,13 @@ use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, - StyleRefinement, Styled as _, Window, div, px, + StyleRefinement, Styled as _, Window, div, }; use gpui_native_core::grain::grain as grain_overlay; use gpui_native_core::scroll_area::ScrollArea; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, TextRole, Typeset as _}; +use gpui_native_theme::{ + ActiveTheme as _, BORDER_WIDTH, SIDEBAR_DEFAULT_WIDTH, TextRole, Typeset as _, +}; use gpui_native_utils::{StyledExt as _, nav_key, paint_selectable_row, selectable_label_color}; /// The change reporter, fired with the next selected row by pointer and keys. @@ -160,7 +162,7 @@ impl Sidebar { grain: false, border_right: true, padded: true, - width: px(240.0), + width: SIDEBAR_DEFAULT_WIDTH, a11y_label: None, on_change: None, entries: None, @@ -463,6 +465,7 @@ impl SidebarEntry { .gap_2() .px_2() .py_1() + .min_h(theme.sizes.medium.control_height) .rounded(theme.radius.sm) .role(Role::ListItem) .aria_selected(selected) diff --git a/crates/data/src/tabs.rs b/crates/data/src/tabs.rs index 0da8738..3ea361b 100644 --- a/crates/data/src/tabs.rs +++ b/crates/data/src/tabs.rs @@ -16,7 +16,7 @@ use gpui_native_core::scroll_area::{ScrollArea, ScrollAxes}; use gpui_native_core::spinner::Spinner; use gpui_native_core::tooltip::Tooltip; use gpui_native_icons::IconRole; -use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size}; +use gpui_native_theme::{ActiveTheme as _, POPUP_MAX_HEIGHT, Size, TAB_INDICATOR_WIDTH}; use gpui_native_utils::{StyledExt as _, adjacent_selectable}; /// Reports the next selected tab by pointer and keys. @@ -609,7 +609,7 @@ impl Tabs { }) .flex() .items_center() - .gap_1p5() + .gap_2() .cursor_pointer() .role(Role::Tab) .aria_selected(selected) @@ -624,7 +624,7 @@ impl Tabs { .py_1() .rounded_tl(theme.radius.sm) .rounded_tr(theme.radius.sm) - .border_b_2() + .border_b(TAB_INDICATOR_WIDTH) .border_color(gpui::transparent_black()) .when(active, |chip| chip.border_color(theme.ramps.primary.base)), TabsVariant::Pill => chip @@ -1019,7 +1019,7 @@ impl Tab { }) .flex() .items_center() - .gap_1p5() + .gap_2() .role(Role::Tab) .aria_selected(selected) .text_color(label_color) @@ -1033,7 +1033,7 @@ impl Tab { .py_1() .rounded_tl(theme.radius.sm) .rounded_tr(theme.radius.sm) - .border_b_2() + .border_b(TAB_INDICATOR_WIDTH) .border_color(gpui::transparent_black()) .when(active, |strip_tab| { strip_tab.border_color(theme.ramps.primary.base) @@ -1072,9 +1072,9 @@ impl Tab { div() .absolute() .left_0() - .top(px(2.0)) - .bottom(px(2.0)) - .w(px(2.0)) + .top(TAB_INDICATOR_WIDTH) + .bottom(TAB_INDICATOR_WIDTH) + .w(TAB_INDICATOR_WIDTH) .rounded(theme.radius.sm) .bg(theme.ramps.primary.base), ) @@ -1201,7 +1201,7 @@ impl Tab { Button::new((self.key.clone(), "tab-close")) .icon(IconRole::Close) .variant(ButtonVariant::Ghost) - .small() + .xsmall() .tab_stop(false) .debug_selector({ let tabs_id = tabs_id.clone(); diff --git a/crates/data/src/tree.rs b/crates/data/src/tree.rs index e043c22..29b5f9f 100644 --- a/crates/data/src/tree.rs +++ b/crates/data/src/tree.rs @@ -354,6 +354,7 @@ impl TreeItem { .pl(indent) .pr_2() .py_1() + .min_h(theme.sizes.medium.control_height) .rounded(theme.radius.sm) .role(Role::TreeItem) .aria_selected(selected) diff --git a/crates/editor/src/code.rs b/crates/editor/src/code.rs index 7fb90d5..23ecfd7 100644 --- a/crates/editor/src/code.rs +++ b/crates/editor/src/code.rs @@ -12,7 +12,8 @@ use gpui::{ }; use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility}; use gpui_native_theme::{ - ActiveTheme as _, ColorTokens, MONO_ADVANCE_RATIO, Ramps, WASH_ALPHA_SOFT, + ActiveTheme as _, CODE_GUTTER_WIDTH, CODE_LINE_HEIGHT, ColorTokens, MONO_ADVANCE_RATIO, Ramps, + WASH_ALPHA_SOFT, }; use crate::highlight::{HighlightedCode, Language, Role, highlight}; @@ -256,7 +257,7 @@ impl Render for CodeViewState { let colors = theme.colors; let mono_font = theme.mono_font; let text_size = theme.sizes.small.text_size; - let line_height = text_size * 1.5; + let line_height = text_size * CODE_LINE_HEIGHT; let char_width = text_size * MONO_ADVANCE_RATIO; let root_font_size = theme.root_font_size; @@ -264,7 +265,7 @@ impl Render for CodeViewState { let state = cx.entity(); let line_count = self.code.lines.len(); let selection = self.selection(); - let gutter_width = root_font_size * 2.5; + let gutter_width = CODE_GUTTER_WIDTH; let bounds_cell: std::rc::Rc>>> = std::rc::Rc::new(std::cell::RefCell::new(None)); diff --git a/crates/editor/src/diff.rs b/crates/editor/src/diff.rs index ae5f352..11d3a2d 100644 --- a/crates/editor/src/diff.rs +++ b/crates/editor/src/diff.rs @@ -13,7 +13,7 @@ use gpui::{ point, uniform_list, }; use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility}; -use gpui_native_theme::{ActiveTheme as _, MONO_ADVANCE_RATIO}; +use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, CODE_GUTTER_WIDTH, MONO_ADVANCE_RATIO}; use similar::{Change, ChangeTag, TextDiff}; use std::ops::Range; @@ -524,10 +524,10 @@ fn render_row( .text_color(colors.muted_foreground) .when( options.indicators == DiffIndicators::Classic, - |row_element| row_element.child(div().w_10().flex_none()), + |row_element| row_element.child(div().w(CODE_GUTTER_WIDTH).flex_none()), ) .when(options.line_numbers, |row_element| { - row_element.child(div().w_10().flex_none()) + row_element.child(div().w(CODE_GUTTER_WIDTH).flex_none()) }) .when( options.indicators == DiffIndicators::Bars && !options.line_numbers, @@ -535,7 +535,7 @@ fn render_row( row_element.child( div() .flex_none() - .border_l_4() + .border_l(BORDER_WIDTH * 4.0) .border_color(gpui::transparent_black()), ) }, @@ -654,14 +654,16 @@ fn render_row( .map(|number| number.to_string()) .unwrap_or_default(), ) - .w_10() + .w(CODE_GUTTER_WIDTH) .whitespace_nowrap() .bg(match row.kind { DiffRowKind::Context => wash_gutter(&colors), _ => wash_strong(change_color), }) .when(options.indicators == DiffIndicators::Bars, |number| { - number.border_l_4().border_color(change_color) + number + .border_l(BORDER_WIDTH * 4.0) + .border_color(change_color) }), ) }) @@ -672,7 +674,7 @@ fn render_row( div() .h_full() .flex_none() - .border_l_4() + .border_l(BORDER_WIDTH * 4.0) .border_color(change_color), ) }, diff --git a/crates/editor/src/markdown.rs b/crates/editor/src/markdown.rs index ff84cd8..b8ba011 100644 --- a/crates/editor/src/markdown.rs +++ b/crates/editor/src/markdown.rs @@ -9,19 +9,20 @@ use gpui::prelude::FluentBuilder as _; use gpui::{ AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle, - FontWeight, GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, - InteractiveText, IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, - MouseButton, MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, - Refineable as _, Render, SharedString, StatefulInteractiveElement as _, StrikethroughStyle, - StyleRefinement, Styled, StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, - actions, div, img, list, px, relative, + GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, InteractiveText, + IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, MouseButton, + MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, Refineable as _, Render, + SharedString, StatefulInteractiveElement as _, StrikethroughStyle, StyleRefinement, Styled, + StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, actions, div, img, list, px, + relative, }; use gpui_native_core::button::{Button, ButtonVariant}; use gpui_native_core::checkbox::Checkbox; use gpui_native_core::common::Sizable as _; use gpui_native_core::scrollbar::{Scrollbar, ScrollbarVisibility}; use gpui_native_theme::{ - ActiveTheme as _, BORDER_WIDTH, CODE_OVERSCROLL_MAX, Size, TextRole, Typeset as _, + ActiveTheme as _, BORDER_WIDTH, CODE_LINE_HEIGHT, CODE_OVERSCROLL_MAX, Size, TextRole, + Typeset as _, }; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd}; @@ -46,8 +47,6 @@ const QUOTE_INSET: f32 = 1.0; const INDENT_STEP: f32 = 1.5; /// The body line height. const BODY_LINE_HEIGHT: f32 = 1.6; -/// The code line height inside fenced blocks. -const CODE_LINE_HEIGHT: f32 = 1.5; /// The tallest a standalone image renders, in root font sizes. const IMAGE_MAX_HEIGHT: f32 = 14.0; /// The side of an inline image atom relative to the body text size. @@ -1469,7 +1468,7 @@ fn block_frame(quote: bool, top: Pixels, bottom: Pixels, id: &ElementId, cx: &Ap .pb(bottom) .when(quote, |frame| { frame - .border_l_2() + .border_l(BORDER_WIDTH * 2.0) .border_color(theme.colors.border) .pl(theme.root_font_size * QUOTE_INSET) }) @@ -1546,8 +1545,9 @@ fn text_row( .pr_1() .child(match marker { ListMarker::Bullet => div() - .text_color(theme.colors.muted_foreground) - .child("•") + .size(theme.spacing.unit) + .rounded(theme.radius.full) + .bg(theme.colors.muted_foreground) .into_any_element(), ListMarker::Ordered(number) => div() .text_color(theme.colors.muted_foreground) @@ -1721,7 +1721,7 @@ fn code_row( .when_some(language.cloned(), |row, language| { row.child( div() - .text_xs() + .typeset(TextRole::Caption, cx) .text_color(theme.colors.muted_foreground) .child(language), ) @@ -1845,7 +1845,7 @@ fn table_row( .px_2() .py_1() .when(row.header, |cell_element| { - cell_element.font_weight(FontWeight::SEMIBOLD) + cell_element.font_weight(theme.typography.headline.weight) }) .child(text_child(&cell.spans, &cell_id, piece, cx)) }) @@ -1981,7 +1981,7 @@ where InlineStyle::Strong => highlights.push(( range, HighlightStyle { - font_weight: Some(FontWeight::SEMIBOLD), + font_weight: Some(theme.typography.headline.weight), ..Default::default() }, )), @@ -1989,7 +1989,7 @@ where range, HighlightStyle { font_style: Some(FontStyle::Italic), - font_weight: Some(FontWeight::SEMIBOLD), + font_weight: Some(theme.typography.headline.weight), ..Default::default() }, )), @@ -2017,7 +2017,7 @@ where highlights.push(( range.clone(), HighlightStyle { - color: Some(theme.colors.accent), + color: Some(theme.ramps.primary.base), underline: Some(UnderlineStyle { thickness: BORDER_WIDTH, color: None, diff --git a/crates/editor/src/utils.rs b/crates/editor/src/utils.rs index 7ddf56d..38c1a19 100644 --- a/crates/editor/src/utils.rs +++ b/crates/editor/src/utils.rs @@ -11,7 +11,7 @@ use gpui::StyledText; #[cfg(any(feature = "code", feature = "markdown"))] use gpui::{App, HighlightStyle, Hsla, IntoElement, ParentElement as _, Styled as _, div}; #[cfg(any(feature = "code", feature = "markdown"))] -use gpui_native_theme::{ActiveTheme as _, ColorTokens, Ramps}; +use gpui_native_theme::{ActiveTheme as _, CODE_GUTTER_WIDTH, ColorTokens, Ramps}; #[cfg(feature = "diff")] use gpui_native_theme::{WASH_ALPHA, WASH_ALPHA_GUTTER, WASH_ALPHA_STRONG}; @@ -74,7 +74,7 @@ where let theme = cx.theme(); div() - .size_10() + .size(CODE_GUTTER_WIDTH) .flex() .items_center() .justify_center() diff --git a/crates/layout/src/panel.rs b/crates/layout/src/panel.rs index a886d1e..156f32d 100644 --- a/crates/layout/src/panel.rs +++ b/crates/layout/src/panel.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use gpui::{ AnyElement, AnyView, App, Axis, Div, ElementId, Entity, IntoElement, ParentElement as _, - Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems, + Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, }; use gpui_native_theme::ActiveTheme as _; use gpui_native_utils::StyledExt as _; @@ -126,7 +126,7 @@ impl gpui::Styled for PanelRow { impl RenderOnce for PanelRow { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let id = self.id.clone(); - let gutter = rems(0.5).to_pixels(window.rem_size()); + let gutter = cx.theme().spacing.unit * 2.0; let main = island( div() diff --git a/crates/layout/src/resize_handle.rs b/crates/layout/src/resize_handle.rs index f33bb63..514a2e3 100644 --- a/crates/layout/src/resize_handle.rs +++ b/crates/layout/src/resize_handle.rs @@ -9,9 +9,11 @@ use gpui::{ InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas, - deferred, div, fill, point, px, rems, + deferred, div, fill, point, px, +}; +use gpui_native_theme::{ + ActiveTheme as _, BORDER_WIDTH, DISABLED_OPACITY, HAIRLINE_WIDTH, RESIZE_KEYBOARD_STEP, }; -use gpui_native_theme::{ActiveTheme as _, BORDER_WIDTH, HAIRLINE_WIDTH, RESIZE_KEYBOARD_STEP}; use gpui_native_utils::{StyledExt as _, focus_handle, focus_ring}; /// How far one keyboard arrow step moves the seam. @@ -108,7 +110,7 @@ impl RenderOnce for ResizeHandle { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); let ring = theme.colors.ring; - let thickness = rems(0.5).to_pixels(window.rem_size()); + let thickness = theme.spacing.unit * 2.0; let label = self .accessibility_label @@ -150,7 +152,7 @@ impl RenderOnce for ResizeHandle { handle.w_full().h(thickness) }) .refine_style(&self.style) - .when(self.disabled, |handle| handle.opacity(0.5)) + .when(self.disabled, |handle| handle.opacity(DISABLED_OPACITY)) .when(!self.disabled, |handle| { handle .track_focus(&focus) diff --git a/crates/layout/src/window_controls.rs b/crates/layout/src/window_controls.rs index 0c348aa..15aad4b 100644 --- a/crates/layout/src/window_controls.rs +++ b/crates/layout/src/window_controls.rs @@ -23,9 +23,6 @@ use gpui_native_theme::ActiveTheme as _; use gpui::Decorations; #[cfg(any(target_os = "windows", target_os = "linux"))] use gpui::SharedString; -#[cfg(target_os = "windows")] -use gpui::px; - /// macOS traffic-lights zone: the pad a leading titlebar strip reserves. pub use gpui_native_theme::TRAFFIC_LIGHT_PAD; #[cfg(target_os = "windows")] @@ -232,7 +229,7 @@ fn caption_button( close: bool, ) -> AnyElement { let theme = cx.theme(); - let glyph_size = theme.sizes.small.caption_size; + let glyph_size = theme.sizes.small.dense_icon_size; let hover = if close { WINDOWS_CLOSE_HOVER @@ -250,7 +247,7 @@ fn caption_button( .flex() .items_center() .justify_center() - .w(px(CAPTION_WIDTH)) + .w(CAPTION_WIDTH) .h_full() .window_control_area(area) .text_color(if enabled { diff --git a/crates/theme/src/colors.rs b/crates/theme/src/colors.rs index e7caafb..7cd4d53 100644 --- a/crates/theme/src/colors.rs +++ b/crates/theme/src/colors.rs @@ -21,7 +21,7 @@ pub struct ColorTokens { pub foreground: Hsla, pub surface: Hsla, pub surface_foreground: Hsla, - /// The docked sidebar's backdrop, matching the platform's window chrome. + /// The docked sidebar's backdrop. pub sidebar: Hsla, pub primary: Hsla, pub primary_foreground: Hsla, @@ -77,8 +77,8 @@ impl ColorTokens { info: hex(0x0284c7), info_foreground: hex(0xffffff), border: hex(0xe4e4e7), - input: hex(0xe4e4e7), - ring: hex(0x93c5fd), + input: hex(0xffffff), + ring: hex(0x2563eb), selection: hex(0xdbeafe), overlay: scrim(0.25), // macOS light overlay thumbs are translucent black. @@ -112,8 +112,8 @@ impl ColorTokens { info: hex(0x38bdf8), info_foreground: hex(0x082f49), border: hex(0x27272a), - input: hex(0x27272a), - ring: hex(0x1d4ed8), + input: hex(0x09090b), + ring: hex(0x3b82f6), selection: hex(0x1e3a8a), overlay: scrim(0.45), // macOS dark overlay thumbs are translucent light gray. diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index f3668b7..d025219 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -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::{ @@ -29,6 +29,32 @@ use std::time::Duration; /// The hairline width of the control border every button and field paints. pub const BORDER_WIDTH: Pixels = px(1.0); +/// The underline and drop indicators a tab strip paints. +pub const TAB_INDICATOR_WIDTH: Pixels = px(2.0); +/// Opacity applied to disabled controls. +pub const DISABLED_OPACITY: f32 = 0.5; +/// The focus ring's ink alpha. +pub const FOCUS_RING_ALPHA: f32 = 0.5; +/// The narrowest a popover may grow. +pub const POPOVER_MIN_WIDTH: Pixels = px(128.0); +/// The default minimum width of a dialog. +pub const DIALOG_MIN_WIDTH: Pixels = px(384.0); +/// The default minimum width of a menu. +pub const MENU_MIN_WIDTH: Pixels = px(224.0); +/// The width of the pushed-alert stack. +pub const ALERT_STACK_WIDTH: Pixels = px(320.0); +/// The accent edge of an inline alert. +pub const ALERT_EDGE_WIDTH: Pixels = px(6.0); +/// The default width of a combobox trigger. +pub const COMBOBOX_WIDTH: Pixels = px(192.0); +/// The narrowest a combobox trigger may shrink. +pub const COMBOBOX_MIN_WIDTH: Pixels = px(96.0); +/// The width of a code view's line-number gutter. +pub const CODE_GUTTER_WIDTH: Pixels = px(40.0); +/// The width of the speech waveform strip. +pub const SPEECH_WAVEFORM_WIDTH: Pixels = px(96.0); +/// The line-height ratio of monospace code. +pub const CODE_LINE_HEIGHT: f32 = 1.5; /// The tallest an anchored popup's list may grow. pub const POPUP_MAX_HEIGHT: Pixels = px(320.0); /// The widest a tooltip may grow. @@ -143,6 +169,7 @@ impl ThemeVariant { /// A named control size class. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum Size { + XSmall, Small, /// The default. #[default] @@ -159,21 +186,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 +221,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 +288,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 +397,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 +406,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 +435,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. @@ -541,6 +497,7 @@ pub struct ControlMetrics { /// The control metrics for every size class. #[derive(Clone, Copy, Debug, PartialEq)] pub struct SizeTable { + pub xsmall: ControlMetrics, pub small: ControlMetrics, pub medium: ControlMetrics, pub large: ControlMetrics, @@ -549,132 +506,136 @@ 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 xsmall = ClassFactors { + control_height: 1.25, + input_height: 1.25, + padding_x: 0.25, + text_size: 0.6875, + icon_size: 0.625, + dense_icon_size: 0.5, + indicator_size: 0.625, + avatar_size: 1.125, + caption_size: 0.625, + dense_padding_x: 0.25, + plate_inset: 0.0, + strip_height: 1.25, + menu_item_height: 1.25, + switch_height: 0.875, + switch_width: 1.5, + switch_knob: 0.5, + }; + 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 { + xsmall: metrics(&xsmall), 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`. pub fn resolve(&self, size: Size) -> ControlMetrics { match size { + Size::XSmall => self.xsmall, Size::Small => self.small, Size::Medium => self.medium, 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. diff --git a/crates/theme/src/resolve.rs b/crates/theme/src/resolve.rs index 75585c4..3f3c0fd 100644 --- a/crates/theme/src/resolve.rs +++ b/crates/theme/src/resolve.rs @@ -2,15 +2,11 @@ use crate::definition::ThemeDefinition; use crate::ramps::{AccentShades, Oklch, contrast_foreground, derive_shades, mix}; use crate::system::{SourceKind, SystemTheme}; use crate::{ - Borders, ColorTokens, CustomTheme, Elevations, MaterialTokens, Motion, Radius, Scrollbar, - SizeTable, Spacing, ThemeVariant, Typography, + ColorTokens, CustomTheme, Elevations, MaterialTokens, Motion, Radius, Scrollbar, SizeTable, + Spacing, ThemeVariant, Typography, }; use gpui::{WindowBackgroundAppearance, px}; -/// The floor of a custom titlebar's height, in px at 100% scaling: the height -/// macOS and Linux titlebars draw at regardless of the control scale. -const TITLEBAR_HEIGHT_MIN_PX: f32 = 34.0; - /// Derived state shades for the colors that get pressed and hovered. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Ramps { @@ -31,18 +27,17 @@ pub struct ResolvedTheme { pub material: MaterialTokens, pub ramps: Ramps, pub radius: Radius, - pub borders: Borders, pub spacing: Spacing, pub elevations: Elevations, pub motion: Motion, 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: gpui::Pixels, - /// The platform's native root font size; the fallback theme uses 16. + /// The theme's root font size. pub root_font_size: gpui::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: crate::system::AccessibilityPreferences, @@ -69,138 +64,54 @@ pub(crate) fn resolve( ThemeVariant::Dark => ColorTokens::dark(), }; - let system_palette = system.palette; - let pick = |def: Option, system: Option, base: gpui::Hsla| { - def.or(system).unwrap_or(base) - }; - let def_color = |field: fn(&ThemeDefinition) -> Option| preset.and_then(field); - let accent = pick(def_color(|d| d.accent()), system.accent, base.accent); - let primary = pick(def_color(|d| d.primary()), system.accent, base.primary); - - let destructive = pick( - def_color(|d| d.destructive()), - system_palette.destructive, - base.destructive, - ); - let success = pick( - def_color(|d| d.success()), - system_palette.success, - base.success, - ); - let warning = pick( - def_color(|d| d.warning()), - system_palette.warning, - base.warning, - ); - let info = pick(def_color(|d| d.info()), system_palette.info, base.info); + let accent = def_color(|d| d.accent()) + .or(system.accent) + .unwrap_or(base.accent); + let primary = def_color(|d| d.primary()).unwrap_or(accent); + let destructive = def_color(|d| d.destructive()).unwrap_or(base.destructive); + let success = def_color(|d| d.success()).unwrap_or(base.success); + let warning = def_color(|d| d.warning()).unwrap_or(base.warning); + let info = def_color(|d| d.info()).unwrap_or(base.info); let mut colors = ColorTokens { - background: pick( - def_color(|d| d.background()), - system_palette.background, - base.background, - ), - foreground: pick( - def_color(|d| d.foreground()), - system_palette.foreground, - base.foreground, - ), - surface: pick( - def_color(|d| d.surface()), - system_palette.surface, - base.surface, - ), - surface_foreground: pick( - def_color(|d| d.surface_foreground()), - system_palette.surface_foreground, - base.surface_foreground, - ), - sidebar: pick( - def_color(|d| d.sidebar()), - system_palette.sidebar, - base.sidebar, - ), + background: def_color(|d| d.background()).unwrap_or(base.background), + foreground: def_color(|d| d.foreground()).unwrap_or(base.foreground), + surface: def_color(|d| d.surface()).unwrap_or(base.surface), + surface_foreground: def_color(|d| d.surface_foreground()) + .unwrap_or(base.surface_foreground), + sidebar: def_color(|d| d.sidebar()).unwrap_or(base.sidebar), primary, - primary_foreground: pick( - def_color(|d| d.primary_foreground()), - system_palette.primary_foreground, - contrast_foreground(primary), - ), - secondary: pick( - def_color(|d| d.secondary()), - system_palette.secondary, - base.secondary, - ), - secondary_foreground: pick( - def_color(|d| d.secondary_foreground()), - system_palette.secondary_foreground, - base.secondary_foreground, - ), - muted: pick(def_color(|d| d.muted()), system_palette.muted, base.muted), - muted_hover: pick( - def_color(|d| d.muted_hover()), - system_palette.muted_hover, - base.muted_hover, - ), - muted_foreground: pick( - def_color(|d| d.muted_foreground()), - system_palette.muted_foreground, - base.muted_foreground, - ), + primary_foreground: def_color(|d| d.primary_foreground()) + .unwrap_or_else(|| contrast_foreground(primary)), + secondary: def_color(|d| d.secondary()).unwrap_or(base.secondary), + secondary_foreground: def_color(|d| d.secondary_foreground()) + .unwrap_or(base.secondary_foreground), + muted: def_color(|d| d.muted()).unwrap_or(base.muted), + muted_hover: def_color(|d| d.muted_hover()).unwrap_or(base.muted_hover), + muted_foreground: def_color(|d| d.muted_foreground()).unwrap_or(base.muted_foreground), accent, - accent_foreground: pick( - def_color(|d| d.accent_foreground()), - system_palette.accent_foreground, - contrast_foreground(accent), - ), + accent_foreground: def_color(|d| d.accent_foreground()) + .unwrap_or_else(|| contrast_foreground(accent)), destructive, - destructive_foreground: pick( - def_color(|d| d.destructive_foreground()), - None, - contrast_foreground(destructive), - ), + destructive_foreground: def_color(|d| d.destructive_foreground()) + .unwrap_or_else(|| contrast_foreground(destructive)), success, - success_foreground: pick( - def_color(|d| d.success_foreground()), - None, - contrast_foreground(success), - ), + success_foreground: def_color(|d| d.success_foreground()) + .unwrap_or_else(|| contrast_foreground(success)), warning, - warning_foreground: pick( - def_color(|d| d.warning_foreground()), - None, - contrast_foreground(warning), - ), + warning_foreground: def_color(|d| d.warning_foreground()) + .unwrap_or_else(|| contrast_foreground(warning)), info, - info_foreground: pick( - def_color(|d| d.info_foreground()), - None, - contrast_foreground(info), - ), - border: pick( - def_color(|d| d.border()), - system_palette.border, - base.border, - ), - input: pick(def_color(|d| d.input()), system_palette.input, base.input), - ring: pick(def_color(|d| d.ring()), system_palette.ring, base.ring), - selection: pick( - def_color(|d| d.selection()), - system_palette.selection, - base.selection, - ), - overlay: pick( - def_color(|d| d.overlay()), - system_palette.overlay, - base.overlay, - ), - scrollbar_thumb: pick( - def_color(|d| d.scrollbar_thumb()), - system_palette.scrollbar_thumb, - base.scrollbar_thumb, - ), + info_foreground: def_color(|d| d.info_foreground()) + .unwrap_or_else(|| contrast_foreground(info)), + border: def_color(|d| d.border()).unwrap_or(base.border), + input: def_color(|d| d.input()).unwrap_or(base.input), + ring: def_color(|d| d.ring()).unwrap_or(accent), + selection: def_color(|d| d.selection()).unwrap_or(base.selection), + overlay: def_color(|d| d.overlay()).unwrap_or(base.overlay), + scrollbar_thumb: def_color(|d| d.scrollbar_thumb()).unwrap_or(base.scrollbar_thumb), }; // The knob scales the fill over a platform-stated blur. @@ -228,50 +139,16 @@ pub(crate) fn resolve( .to_hsla(); } - // The platform's root font size scales every control metric: - // - A medium control's label is exactly the root font size. - // - A custom theme's stated font size wins over the platform's. - // - // Fallback: 16 (the web default gpui also uses for rems). - let root_font_size = custom - .root_font_size - .or(system.root_font_size) - .unwrap_or(px(16.)); - - // Initialize sizes with the resolved root font size. - let mut sizes = SizeTable::with_root_font_size(root_font_size); - - if let Some(control_height) = system.control_height { - sizes.set_control_height(control_height); - } - - if let Some(input_height) = system.input_height { - sizes.set_input_height(input_height); - } - - if let Some(switch_height) = system.switch_height { - sizes.set_switch_metrics( - switch_height, - system.switch_width.unwrap_or(switch_height * 2.25), - system.switch_knob.unwrap_or(switch_height * 0.85), - ); - } - - if let Some(menu_item_height) = system.menu_item_height { - sizes.set_menu_item_height(menu_item_height); - } - - // A platform that states its titlebar height wins. - let titlebar_height = system - .titlebar_height - .unwrap_or_else(|| sizes.medium.control_height.max(px(TITLEBAR_HEIGHT_MIN_PX))); + // A custom theme's stated font size wins over the 16px design root. + let root_font_size = custom.root_font_size.unwrap_or(px(16.)); + let sizes = SizeTable::with_root_font_size(root_font_size); + let titlebar_height = root_font_size * 2.5; let mut radius = Radius::default(); if let Some(control) = custom .control_radius .or(preset.and_then(|def| def.control_radius()).map(px)) - .or(system.control_radius) { radius.control = control; } @@ -279,7 +156,6 @@ pub(crate) fn resolve( if let Some(overlay) = custom .overlay_radius .or(preset.and_then(|def| def.overlay_radius()).map(px)) - .or(system.overlay_radius) { radius.overlay = overlay; } @@ -287,7 +163,6 @@ pub(crate) fn resolve( if let Some(sm) = custom .sm_radius .or(preset.and_then(|def| def.sm_radius()).map(px)) - .or(system.sm_radius) { radius.sm = sm; } @@ -309,6 +184,10 @@ pub(crate) fn resolve( info: derive_shades(info, colors.background, variant == ThemeVariant::Dark), }; + if def_color(|d| d.selection()).is_none() { + colors.selection = ramps.primary.subtle; + } + let material = MaterialTokens::derive( &colors, ramps.primary.base, @@ -317,17 +196,15 @@ pub(crate) fn resolve( transparency, ); - let platform_elevations = Elevations::for_platform(system.source, variant); + let default_elevations = Elevations::for_variant(variant); let elevations = Elevations { popover: custom .popover_elevation - .unwrap_or(platform_elevations.popover), - dialog: custom - .dialog_elevation - .unwrap_or(platform_elevations.dialog), + .unwrap_or(default_elevations.popover), + dialog: custom.dialog_elevation.unwrap_or(default_elevations.dialog), control: custom .control_elevation - .unwrap_or(platform_elevations.control), + .unwrap_or(default_elevations.control), }; ResolvedTheme { @@ -336,9 +213,8 @@ pub(crate) fn resolve( colors, material, radius, - borders: Borders::for_platform(system.source, variant), spacing: Spacing { - unit: system.source.spacing_unit(), + unit: root_font_size * 0.25, }, elevations, motion: Motion::default(), @@ -349,7 +225,7 @@ pub(crate) fn resolve( titlebar_height, root_font_size, mono_font: mono_font(), - typography: Typography::resolve(system.source, root_font_size), + typography: Typography::resolve(root_font_size), sizes, accessibility, window_background, @@ -370,34 +246,18 @@ fn mono_font() -> &'static str { #[cfg(test)] mod tests { use super::*; - use crate::system::{AccessibilityPreferences, PartialPalette, SourceKind}; + use crate::system::{AccessibilityPreferences, SourceKind}; use crate::{Elevation, Shadow}; - use gpui::{FontWeight, Rgba, WindowBackgroundAppearance, rgb}; + use gpui::{Rgba, WindowBackgroundAppearance, rgb}; fn hsla(hex: u32) -> gpui::Hsla { gpui::Hsla::from(rgb(hex)) } - fn system( - variant: ThemeVariant, - palette: PartialPalette, - accent: Option, - ) -> SystemTheme { + fn system(variant: ThemeVariant, accent: Option) -> SystemTheme { SystemTheme { variant, accent, - palette, - control_radius: None, - overlay_radius: None, - sm_radius: None, - control_height: None, - input_height: None, - menu_item_height: None, - switch_height: None, - switch_width: None, - switch_knob: None, - titlebar_height: None, - root_font_size: None, accessibility: AccessibilityPreferences::default(), window_background: None, source: SourceKind::Macos, @@ -410,7 +270,7 @@ mod tests { let resolved = resolve( &SystemTheme { source: SourceKind::Fallback, - ..system(variant, PartialPalette::default(), None) + ..system(variant, None) }, None, None, @@ -422,64 +282,58 @@ mod tests { }; assert_eq!(resolved.colors.background, base.background); assert_eq!(resolved.colors.accent, base.accent); + assert_eq!(resolved.colors.ring, base.accent); assert_eq!(resolved.ramps.primary.base, base.primary); assert_eq!(resolved.ramps.secondary.base, base.secondary); + assert_eq!(resolved.colors.selection, resolved.ramps.primary.subtle); assert_eq!(resolved.radius.sm, px(4.)); assert_eq!(resolved.radius.control, px(6.)); + assert_eq!(resolved.radius.overlay, px(10.)); assert_eq!(resolved.root_font_size, px(16.)); - assert_eq!(resolved.sizes.medium.control_height, px(28.)); - assert_eq!(resolved.sizes.medium.input_height, px(30.)); - assert_eq!(resolved.sizes.medium.text_size, px(16.)); - assert_eq!(resolved.sizes.small.avatar_size, px(18.)); - assert_eq!(resolved.sizes.medium.avatar_size, px(24.)); - assert_eq!(resolved.sizes.large.avatar_size, px(32.)); - assert_eq!(resolved.sizes.small.caption_size, px(13.6 * 0.85)); - assert_eq!(resolved.sizes.medium.caption_size, px(16.)); - assert_eq!(resolved.sizes.large.caption_size, px(16.)); - assert_eq!(resolved.sizes.medium.dense_padding_x, px(16. * 0.75)); - assert_eq!(resolved.sizes.medium.plate_inset, px(4.)); + assert_eq!(resolved.sizes.medium.control_height, px(32.)); + assert_eq!(resolved.sizes.medium.input_height, px(32.)); + assert_eq!(resolved.sizes.medium.text_size, px(14.)); + assert_eq!(resolved.sizes.xsmall.control_height, px(20.)); + assert_eq!(resolved.sizes.xsmall.input_height, px(20.)); + assert_eq!(resolved.sizes.xsmall.text_size, px(11.)); + assert_eq!(resolved.sizes.xsmall.icon_size, px(10.)); + assert_eq!(resolved.sizes.xsmall.indicator_size, px(10.)); + assert_eq!(resolved.sizes.xsmall.avatar_size, px(18.)); + assert_eq!(resolved.sizes.xsmall.caption_size, px(10.)); + assert_eq!(resolved.sizes.xsmall.dense_padding_x, px(4.)); + assert_eq!(resolved.sizes.xsmall.plate_inset, px(0.)); + assert_eq!(resolved.sizes.xsmall.menu_item_height, px(20.)); + assert_eq!(resolved.sizes.xsmall.switch_height, px(14.)); + assert_eq!(resolved.sizes.xsmall.switch_width, px(24.)); + assert_eq!(resolved.sizes.xsmall.switch_knob, px(8.)); + assert_eq!(resolved.sizes.small.control_height, px(28.)); + assert_eq!(resolved.sizes.small.text_size, px(12.)); + assert_eq!(resolved.sizes.small.avatar_size, px(24.)); + assert_eq!(resolved.sizes.medium.avatar_size, px(32.)); + assert_eq!(resolved.sizes.large.avatar_size, px(40.)); + assert_eq!(resolved.sizes.small.caption_size, px(12.)); + assert_eq!(resolved.sizes.medium.caption_size, px(12.)); + assert_eq!(resolved.sizes.large.caption_size, px(14.)); + assert_eq!(resolved.sizes.medium.dense_padding_x, px(8.)); + assert_eq!(resolved.sizes.medium.plate_inset, px(2.)); assert_eq!(resolved.sizes.medium.strip_height, px(32.)); assert_eq!(resolved.sizes.medium.icon_size, px(16.)); - assert_eq!(resolved.sizes.medium.menu_item_height, px(28. * 0.85)); - assert_eq!(resolved.sizes.medium.switch_height, px(21.)); - assert_eq!(resolved.sizes.medium.switch_width, px(21. * 2.25)); - assert_eq!(resolved.sizes.medium.switch_knob, px(21. * 0.85)); - assert_eq!( - resolved.borders, - Borders { - buttons: true, - fields: true, - overlays: true, - focus_ring: false, - } - ); + assert_eq!(resolved.sizes.medium.indicator_size, px(16.)); + assert_eq!(resolved.sizes.medium.menu_item_height, px(32.)); + assert_eq!(resolved.sizes.large.control_height, px(40.)); + assert_eq!(resolved.sizes.large.text_size, px(16.)); + assert_eq!(resolved.sizes.medium.switch_height, px(20.)); + assert_eq!(resolved.sizes.medium.switch_width, px(36.)); + assert_eq!(resolved.sizes.medium.switch_knob, px(14.)); assert_eq!(resolved.spacing.unit, px(4.)); - assert_eq!(resolved.titlebar_height, px(34.)); + assert_eq!(resolved.titlebar_height, px(40.)); + assert_eq!(resolved.typography.body.size, px(16.)); } } - #[test] - fn a_stated_titlebar_height_wins_over_the_control_scale() { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); - stated.titlebar_height = Some(px(32.)); - assert_eq!(resolve(&stated, None, None, None).titlebar_height, px(32.)); - } - - #[test] - fn a_stated_root_font_size_scales_the_size_table() { - // macOS states 13pt; the medium control shrinks to native proportions. - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.root_font_size = Some(px(13.)); - let resolved = resolve(&stated, None, None, None); - assert_eq!(resolved.root_font_size, px(13.)); - assert_eq!(resolved.sizes.medium.control_height, px(22.75)); - assert_eq!(resolved.sizes.medium.text_size, px(13.)); - assert_eq!(resolved.sizes.small.text_size, px(11.05)); - } - #[test] fn scrollbar_autohide_follows_the_platform_source() { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut stated = system(ThemeVariant::Dark, None); stated.source = SourceKind::Macos; assert!(resolve(&stated, None, None, None).scrollbar.autohide); @@ -500,114 +354,109 @@ mod tests { } #[test] - fn a_stated_input_height_overrides_the_derived_one_and_scales() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.input_height = Some(px(24.)); - let resolved = resolve(&stated, None, None, None); - assert_eq!(resolved.sizes.medium.input_height, px(24.)); - let derived = SizeTable::with_root_font_size(px(16.)); - let scale = px(24.) / derived.medium.input_height; - let expected_small = (derived.small.input_height * scale).floor(); - assert_eq!(resolved.sizes.small.input_height, expected_small); + fn accent_drives_primary_ring_and_selection() { + let red = hsla(0xdc2626); + let resolved = resolve(&system(ThemeVariant::Light, Some(red)), None, None, None); + assert_eq!(resolved.colors.accent, red); + assert_eq!(resolved.colors.primary, red); + assert_eq!(resolved.colors.ring, red); + assert_eq!(resolved.ramps.primary.base, red); + assert_eq!(resolved.colors.selection, resolved.ramps.primary.subtle); + + let base = ColorTokens::light(); + assert_eq!(resolved.colors.background, base.background); + assert_eq!(resolved.colors.foreground, base.foreground); + assert_eq!(resolved.colors.border, base.border); } #[test] - fn a_stated_control_height_overrides_the_medium_class_and_scales() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.control_height = Some(px(32.)); - let resolved = resolve(&stated, None, None, None); - assert_eq!(resolved.sizes.medium.control_height, px(32.)); + fn every_source_resolves_the_same_tokens() { + let mut stated = system(ThemeVariant::Dark, None); + stated.accent = Some(hsla(0x7aa2f7)); + stated.window_background = Some(WindowBackgroundAppearance::Blurred); + let sources = [ + SourceKind::Fallback, + SourceKind::Macos, + SourceKind::Windows, + SourceKind::Gnome, + SourceKind::Kde, + SourceKind::Omarchy, + ]; - let derived = SizeTable::with_root_font_size(px(16.)); - let scale = px(32.) / derived.medium.control_height; - let expected_small = (derived.small.control_height * scale).floor(); - let expected_large = (derived.large.control_height * scale).floor(); - assert_eq!(resolved.sizes.small.control_height, expected_small); - assert_eq!(resolved.sizes.large.control_height, expected_large); + let first = resolve( + &SystemTheme { + source: sources[0], + ..stated + }, + None, + None, + None, + ); + for source in &sources[1..] { + let next = resolve( + &SystemTheme { + source: *source, + ..stated + }, + None, + None, + None, + ); + assert_eq!(next.colors, first.colors, "{source:?}"); + assert_eq!(next.radius, first.radius, "{source:?}"); + assert_eq!(next.spacing, first.spacing, "{source:?}"); + assert_eq!(next.elevations, first.elevations, "{source:?}"); + assert_eq!(next.titlebar_height, first.titlebar_height, "{source:?}"); + assert_eq!(next.root_font_size, first.root_font_size, "{source:?}"); + assert_eq!(next.typography, first.typography, "{source:?}"); + assert_eq!(next.sizes, first.sizes, "{source:?}"); + } } #[test] - fn stated_switch_and_menu_metrics_override_the_derived_ones() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.switch_height = Some(px(20.)); - stated.switch_width = Some(px(40.)); - stated.switch_knob = Some(px(12.)); - stated.menu_item_height = Some(px(33.)); - let resolved = resolve(&stated, None, None, None); - - assert_eq!(resolved.sizes.medium.switch_height, px(20.)); - assert_eq!(resolved.sizes.medium.switch_width, px(40.)); - assert_eq!(resolved.sizes.medium.switch_knob, px(12.)); - assert_eq!(resolved.sizes.medium.menu_item_height, px(33.)); - } - - #[test] - fn the_radius_ladder_follows_stated_values_with_preset_priority() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.control_radius = Some(px(9.)); - stated.overlay_radius = Some(px(15.)); - stated.sm_radius = Some(px(6.)); - let resolved = resolve(&stated, None, None, None); - assert_eq!(resolved.radius.control, px(9.)); - assert_eq!(resolved.radius.overlay, px(15.)); - assert_eq!(resolved.radius.sm, px(6.)); + fn the_radius_ladder_follows_custom_values_with_preset_priority() { + let resolved = resolve(&system(ThemeVariant::Light, None), None, None, None); + assert_eq!(resolved.radius.sm, px(4.)); + assert_eq!(resolved.radius.control, px(6.)); + assert_eq!(resolved.radius.overlay, px(10.)); let def = ThemeDefinition::parse_toml("overlay_radius = 12.0\n").unwrap(); - let overridden = resolve(&stated, Some(&def), None, None); + let overridden = resolve(&system(ThemeVariant::Light, None), Some(&def), None, None); assert_eq!(overridden.radius.overlay, px(12.)); - assert_eq!(overridden.radius.sm, px(6.)); - } + assert_eq!(overridden.radius.sm, px(4.)); - #[test] - fn borders_and_spacing_follow_the_platform_source() { - let chrome = |source| { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.source = source; - let resolved = resolve(&stated, None, None, None); - (resolved.borders, resolved.spacing.unit) + let custom = CustomTheme { + sm_radius: Some(px(2.)), + control_radius: Some(px(9.)), + ..CustomTheme::default() }; - - let (borders, unit) = chrome(SourceKind::Windows); - assert!(borders.buttons && borders.fields && borders.overlays && !borders.focus_ring); - assert_eq!(unit, px(4.)); - - let (borders, unit) = chrome(SourceKind::Kde); - assert!(borders.buttons && borders.fields && borders.overlays && !borders.focus_ring); - assert_eq!(unit, px(4.)); - - let (borders, unit) = chrome(SourceKind::Macos); - assert!(!borders.buttons && borders.fields && !borders.overlays && borders.focus_ring); - assert_eq!(unit, px(4.)); - - for source in [SourceKind::Gnome, SourceKind::Omarchy] { - let (borders, unit) = chrome(source); - assert!(!borders.buttons && !borders.fields && !borders.overlays && borders.focus_ring); - assert_eq!(unit, px(6.)); - } - - let (borders, unit) = chrome(SourceKind::Fallback); - assert!(borders.buttons && borders.fields && borders.overlays && !borders.focus_ring); - assert_eq!(unit, px(4.)); + let custom = resolve( + &system(ThemeVariant::Light, None), + Some(&def), + None, + Some(custom), + ); + assert_eq!(custom.radius.sm, px(2.)); + assert_eq!(custom.radius.control, px(9.)); + assert_eq!(custom.radius.overlay, px(12.)); } #[test] - fn dark_mode_separates_overlays_by_border() { - for source in [SourceKind::Macos, SourceKind::Gnome, SourceKind::Omarchy] { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); - stated.source = source; - let resolved = resolve(&stated, None, None, None); - assert!( - resolved.borders.overlays, - "{source:?} frames floating layers in dark" - ); - assert!(resolved.elevations.popover.shadows().is_empty()); - assert!(resolved.elevations.dialog.shadows().is_empty()); - } + fn elevations_follow_the_variant() { + let light = resolve(&system(ThemeVariant::Light, None), None, None, None); + assert_eq!(light.elevations.popover.shadows().len(), 2); + assert_eq!(light.elevations.dialog.shadows().len(), 2); + assert_eq!(light.elevations.control.shadows().len(), 1); + + let dark = resolve(&system(ThemeVariant::Dark, None), None, None, None); + assert!(dark.elevations.popover.shadows().is_empty()); + assert!(dark.elevations.dialog.shadows().is_empty()); + assert_eq!(dark.elevations.control.shadows().len(), 1); } #[test] fn the_platforms_window_material_resolves_into_the_theme() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); + let mut stated = system(ThemeVariant::Light, None); stated.window_background = Some(WindowBackgroundAppearance::MicaBackdrop); let resolved = resolve(&stated, None, None, None); @@ -619,12 +468,7 @@ mod tests { assert!(resolved.material.background.a < resolved.colors.background.a); assert!(resolved.material.selection.a < 1.0); - let unstated = resolve( - &system(ThemeVariant::Light, PartialPalette::default(), None), - None, - None, - None, - ); + let unstated = resolve(&system(ThemeVariant::Light, None), None, None, None); assert_eq!( unstated.window_background, WindowBackgroundAppearance::Opaque @@ -636,7 +480,7 @@ mod tests { #[test] fn reduced_transparency_forces_an_opaque_window_and_material() { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut stated = system(ThemeVariant::Dark, None); stated.window_background = Some(WindowBackgroundAppearance::Blurred); stated.accessibility.reduce_transparency = true; let resolved = resolve(&stated, None, None, None); @@ -652,7 +496,7 @@ mod tests { #[test] fn a_custom_transparency_level_scales_the_material_fill() { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut stated = system(ThemeVariant::Dark, None); stated.window_background = Some(WindowBackgroundAppearance::Blurred); let custom = CustomTheme { transparency: Some(80), @@ -681,9 +525,9 @@ mod tests { #[test] fn light_mode_keeps_a_heavier_fill_at_full_transparency() { - let mut light_system = system(ThemeVariant::Light, PartialPalette::default(), None); + let mut light_system = system(ThemeVariant::Light, None); light_system.window_background = Some(WindowBackgroundAppearance::Blurred); - let mut dark_system = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut dark_system = system(ThemeVariant::Dark, None); dark_system.window_background = Some(WindowBackgroundAppearance::Blurred); let maxed = CustomTheme { transparency: Some(100), @@ -698,7 +542,7 @@ mod tests { #[test] fn transparency_zero_opens_an_opaque_window() { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut stated = system(ThemeVariant::Dark, None); stated.window_background = Some(WindowBackgroundAppearance::Blurred); let resolved = resolve( &stated, @@ -721,7 +565,7 @@ mod tests { #[test] fn the_transparency_knob_skips_windows_and_platforms_without_a_material() { - let mut windows = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut windows = system(ThemeVariant::Dark, None); windows.source = SourceKind::Windows; windows.window_background = Some(WindowBackgroundAppearance::MicaBackdrop); let resolved_windows = resolve( @@ -745,7 +589,7 @@ mod tests { unset.material.background ); - let mut unstated = system(ThemeVariant::Dark, PartialPalette::default(), None); + let mut unstated = system(ThemeVariant::Dark, None); unstated.window_background = None; let resolved_unstated = resolve( &unstated, @@ -769,42 +613,22 @@ mod tests { #[test] fn overlay_is_translucent_and_overridable() { - let light = resolve( - &system(ThemeVariant::Light, PartialPalette::default(), None), - None, - None, - None, - ); - let dark = resolve( - &system(ThemeVariant::Dark, PartialPalette::default(), None), - None, - None, - None, - ); + let light = resolve(&system(ThemeVariant::Light, None), None, None, None); + let dark = resolve(&system(ThemeVariant::Dark, None), None, None, None); // Both scrims are translucent black; dark is denser for contrast. assert!(light.colors.overlay.a > 0.0 && light.colors.overlay.a < 0.5); assert!(dark.colors.overlay.a > light.colors.overlay.a); let def = ThemeDefinition::parse_toml("overlay = \"#000000\"").unwrap(); - let overridden = resolve( - &system(ThemeVariant::Light, PartialPalette::default(), None), - Some(&def), - None, - None, - ); + let overridden = resolve(&system(ThemeVariant::Light, None), Some(&def), None, None); assert_eq!(overridden.colors.overlay, hsla(0x000000)); assert_eq!(overridden.colors.overlay.a, 1.0); } #[test] fn elevations_and_motion_resolve_with_defaults() { - let resolved = resolve( - &system(ThemeVariant::Light, PartialPalette::default(), None), - None, - None, - None, - ); + let resolved = resolve(&system(ThemeVariant::Light, None), None, None, None); // The popover shadow is softer and tighter than the dialog's. assert!( @@ -817,97 +641,13 @@ mod tests { assert!(!shadows[0].inset); } - #[test] - fn elevations_follow_the_platform_in_light_mode_and_share_one_dark_stack() { - let popover = |source| { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.source = source; - resolve(&stated, None, None, None).elevations.popover - }; - - // macOS paints a soft layered stack; Linux keeps a compact single one. - assert_eq!(popover(SourceKind::Macos).shadows().len(), 2); - assert_eq!(popover(SourceKind::Gnome).shadows().len(), 1); - assert!( - popover(SourceKind::Macos).layers[0].color.a - < popover(SourceKind::Gnome).layers[0].color.a - ); - - // Dark mode is one shared stack, however the adapter detected. - let dark = |source| { - let mut stated = system(ThemeVariant::Dark, PartialPalette::default(), None); - stated.source = source; - resolve(&stated, None, None, None).elevations - }; - assert_eq!(dark(SourceKind::Macos), dark(SourceKind::Windows)); - assert_eq!(dark(SourceKind::Macos), dark(SourceKind::Fallback)); - } - - #[test] - fn system_colors_override_the_base_but_leave_the_rest_intact() { - let palette = PartialPalette { - background: Some(hsla(0x112233)), - border: Some(hsla(0x445566)), - ..PartialPalette::default() - }; - let resolved = resolve( - &system(ThemeVariant::Dark, palette, Some(hsla(0xff8800))), - None, - None, - None, - ); - assert_eq!(resolved.colors.background, hsla(0x112233)); - assert_eq!(resolved.colors.border, hsla(0x445566)); - assert_eq!(resolved.colors.accent, hsla(0xff8800)); - assert_eq!(resolved.colors.foreground, ColorTokens::dark().foreground); - } - - #[test] - fn a_system_stated_accent_foreground_beats_the_derivation() { - // What macOS reports via alternateSelectedControlTextColor: white, - // even where the derivation would pick black (light accent). - let palette = PartialPalette { - accent_foreground: Some(hsla(0xffffff)), - ..PartialPalette::default() - }; - let resolved = resolve( - &system(ThemeVariant::Light, palette, Some(hsla(0xffd60a))), - None, - None, - None, - ); - assert_eq!(resolved.colors.accent, hsla(0xffd60a)); - assert_eq!(resolved.colors.accent_foreground, hsla(0xffffff)); - // Without the stated foreground the derivation applies. - let derived = resolve( - &system( - ThemeVariant::Light, - PartialPalette::default(), - Some(hsla(0xffd60a)), - ), - None, - None, - None, - ); - assert_eq!(derived.colors.accent_foreground, hsla(0x000000)); - } - #[test] fn preset_beats_system_and_the_mode_override_beats_everything() { let def = ThemeDefinition::parse_toml( "mode = \"dark\"\nbackground = \"#1a1b26\"\naccent = \"#7aa2f7\"\ncontrol_radius = 12.0\n", ) .unwrap(); - let palette = PartialPalette { - background: Some(hsla(0xffffff)), - ..PartialPalette::default() - }; - let resolved = resolve( - &system(ThemeVariant::Light, palette, None), - Some(&def), - None, - None, - ); + let resolved = resolve(&system(ThemeVariant::Light, None), Some(&def), None, None); assert_eq!(resolved.variant, ThemeVariant::Dark); // Compare in RGB space: Hsla round-trips are lossy at low saturation. let bg = Rgba::from(resolved.colors.background); @@ -919,7 +659,7 @@ mod tests { assert_eq!(resolved.radius.control, px(12.)); let forced = resolve( - &system(ThemeVariant::Light, palette, None), + &system(ThemeVariant::Light, None), Some(&def), Some(ThemeVariant::Light), None, @@ -934,22 +674,14 @@ mod tests { #[test] fn an_accent_only_override_derives_foregrounds_and_ramps() { let def = ThemeDefinition::parse_toml("mode = \"dark\"\naccent = \"#7aa2f7\"\n").unwrap(); - let resolved = resolve( - &system(ThemeVariant::Dark, PartialPalette::default(), None), - Some(&def), - None, - None, - ); - // The definition sets accent only; primary still falls back to the - // dark base. accent_foreground/primary_foreground are derived per - // color, and the ramp tracks its own base. + let resolved = resolve(&system(ThemeVariant::Dark, None), Some(&def), None, None); + // The definition sets accent only; primary follows it, and both + // foregrounds derive from their own color. let accent = Rgba::from(resolved.colors.accent); assert!((accent.r - 0x7a as f32 / 255.0).abs() < 0.001); - assert_eq!( - resolved.colors.primary, - ColorTokens::dark().primary, - "primary should stay at the base until a definition names it" - ); + assert_eq!(resolved.colors.primary, resolved.colors.accent); + assert_eq!(resolved.colors.ring, resolved.colors.accent); + assert_eq!(resolved.colors.selection, resolved.ramps.primary.subtle); assert_eq!(resolved.ramps.primary.base, resolved.colors.primary); assert_eq!(resolved.ramps.destructive.base, resolved.colors.destructive); assert_ne!(resolved.ramps.primary.hover, resolved.ramps.primary.base); @@ -959,11 +691,7 @@ mod tests { #[test] fn system_accent_becomes_primary() { let resolved = resolve( - &system( - ThemeVariant::Dark, - PartialPalette::default(), - Some(hsla(0x7aa2f7)), - ), + &system(ThemeVariant::Dark, Some(hsla(0x7aa2f7))), None, None, None, @@ -980,17 +708,12 @@ mod tests { #[test] fn high_contrast_sharpens_the_border_toward_the_foreground() { let mut a11y = AccessibilityPreferences::default(); - let plain = resolve( - &system(ThemeVariant::Dark, PartialPalette::default(), None), - None, - None, - None, - ); + let plain = resolve(&system(ThemeVariant::Dark, None), None, None, None); a11y.high_contrast = true; let contrasted = resolve( &SystemTheme { accessibility: a11y, - ..system(ThemeVariant::Dark, PartialPalette::default(), None) + ..system(ThemeVariant::Dark, None) }, None, None, @@ -1005,12 +728,7 @@ mod tests { #[test] fn every_resolved_role_is_distinct_enough_to_paint_with() { for variant in [ThemeVariant::Light, ThemeVariant::Dark] { - let resolved = resolve( - &system(variant, PartialPalette::default(), None), - None, - None, - None, - ); + let resolved = resolve(&system(variant, None), None, None, None); assert_ne!(resolved.colors.background, resolved.colors.foreground); assert_ne!(resolved.colors.border, resolved.colors.background); assert_ne!(resolved.colors.muted_foreground, resolved.colors.foreground); @@ -1024,11 +742,7 @@ mod tests { // red, Omarchy red themes) must not make Info toasts read as Danger. let red_accent = hsla(0xdc2626); let resolved = resolve( - &system( - ThemeVariant::Dark, - PartialPalette::default(), - Some(red_accent), - ), + &system(ThemeVariant::Dark, Some(red_accent)), None, None, None, @@ -1039,29 +753,15 @@ mod tests { } #[test] - fn info_follows_the_severity_overlay_chain() { - let palette = PartialPalette { - info: Some(hsla(0x155e75)), - ..PartialPalette::default() - }; - let system_stated = resolve(&system(ThemeVariant::Dark, palette, None), None, None, None); - assert_eq!(system_stated.colors.info, hsla(0x155e75)); - assert_eq!(system_stated.ramps.info.base, hsla(0x155e75)); - + fn info_follows_the_preset() { let def = ThemeDefinition::parse_toml("info = \"#0ea5e9\"\n").unwrap(); - let preset_stated = resolve( - &system(ThemeVariant::Dark, palette, None), - Some(&def), - None, - None, - ); - assert_eq!(preset_stated.colors.info, hsla(0x0ea5e9)); + let resolved = resolve(&system(ThemeVariant::Dark, None), Some(&def), None, None); + assert_eq!(resolved.colors.info, hsla(0x0ea5e9)); + assert_eq!(resolved.ramps.info.base, hsla(0x0ea5e9)); } #[test] - fn a_custom_theme_beats_preset_system_and_platform() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.control_radius = Some(px(9.)); + fn a_custom_theme_beats_the_preset_and_defaults() { let def = ThemeDefinition::parse_toml("overlay_radius = 12.0\n").unwrap(); let popover = Elevation::single(Shadow::black(0., 2., 8., 0.3)); let custom = CustomTheme { @@ -1070,49 +770,35 @@ mod tests { popover_elevation: Some(popover), ..CustomTheme::default() }; - let resolved = resolve(&stated, Some(&def), None, Some(custom)); + let resolved = resolve( + &system(ThemeVariant::Light, None), + Some(&def), + None, + Some(custom), + ); assert_eq!(resolved.radius.control, px(4.)); assert_eq!(resolved.radius.sm, px(2.)); // Fields the custom theme leaves unstated keep the resolved values. assert_eq!(resolved.radius.overlay, px(12.)); assert_eq!(resolved.elevations.popover, popover); - let platform = Elevations::for_platform(stated.source, ThemeVariant::Light); - assert_eq!(resolved.elevations.dialog, platform.dialog); - assert_eq!(resolved.elevations.control, platform.control); + let defaults = Elevations::for_variant(ThemeVariant::Light); + assert_eq!(resolved.elevations.dialog, defaults.dialog); + assert_eq!(resolved.elevations.control, defaults.control); } #[test] - fn a_custom_root_font_size_beats_the_platform_and_rescales_the_table() { - let mut stated = system(ThemeVariant::Light, PartialPalette::default(), None); - stated.root_font_size = Some(px(13.)); + fn a_custom_root_font_size_rescales_the_table() { let custom = CustomTheme { root_font_size: Some(px(20.)), ..CustomTheme::default() }; - let resolved = resolve(&stated, None, None, Some(custom)); + let resolved = resolve(&system(ThemeVariant::Light, None), None, None, Some(custom)); assert_eq!(resolved.root_font_size, px(20.)); - assert_eq!(resolved.sizes.medium.control_height, px(35.)); - 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::SEMIBOLD); - - // 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.)); + assert_eq!(resolved.sizes.medium.control_height, px(40.)); + assert_eq!(resolved.sizes.medium.text_size, px(17.5)); + assert_eq!(resolved.spacing.unit, px(5.)); + assert_eq!(resolved.titlebar_height, px(50.)); + assert_eq!(resolved.typography.body.size, px(20.)); + assert_eq!(resolved.typography.large_title.size, px(30.)); } } diff --git a/crates/theme/src/source/kde.rs b/crates/theme/src/source/kde.rs index 461ea62..4898bbb 100644 --- a/crates/theme/src/source/kde.rs +++ b/crates/theme/src/source/kde.rs @@ -4,74 +4,40 @@ use std::collections::HashMap; -use gpui::{Hsla, Pixels, px}; +use gpui::Hsla; -use crate::system::{PartialPalette, SourceKind, SystemTheme}; +use crate::system::{SourceKind, SystemTheme}; -/// The colors stated in kdeglobals' `[Colors:*]` groups. +/// The accent and window background stated in kdeglobals. #[derive(Clone, Copy, Debug, Default, PartialEq)] pub(crate) struct KdeScheme { pub(crate) accent: Option, pub(crate) background: Option, - pub(crate) palette: PartialPalette, - /// The root font size parsed from `[General] font=` (family, pointSize, - /// pixelSize, ...). - pub(crate) root_font_size: Option, } impl KdeScheme { /// Parses kdeglobals text. pub(crate) fn parse(text: &str) -> Self { let groups = parse_groups(text); - let window = groups.get("Colors:Window"); - let view = groups.get("Colors:View"); - let button = groups.get("Colors:Button"); - let selection = groups.get("Colors:Selection"); - let background = window.and_then(|group| group_color(group, "BackgroundNormal")); + let background = groups + .get("Colors:Window") + .and_then(|group| group_color(group, "BackgroundNormal")); let accent = groups .get("General") .and_then(|group| group.get("AccentColor")) .and_then(|value| color_list(value)); - let palette = PartialPalette { - background, - foreground: window.and_then(|group| group_color(group, "ForegroundNormal")), - surface: view.and_then(|group| group_color(group, "BackgroundNormal")), - surface_foreground: view.and_then(|group| group_color(group, "ForegroundNormal")), - secondary: button.and_then(|group| group_color(group, "BackgroundNormal")), - secondary_foreground: button.and_then(|group| group_color(group, "ForegroundNormal")), - muted: window.and_then(|group| group_color(group, "DecorationHover")), - muted_foreground: window.and_then(|group| group_color(group, "ForegroundInactive")), - destructive: window.and_then(|group| group_color(group, "ForegroundNegative")), - success: window.and_then(|group| group_color(group, "ForegroundPositive")), - border: window.and_then(|group| group_color(group, "DecorationNormal")), - ring: window.and_then(|group| group_color(group, "DecorationFocus")), - selection: selection.and_then(|group| group_color(group, "BackgroundNormal")), - primary_foreground: selection.and_then(|group| group_color(group, "ForegroundNormal")), - ..PartialPalette::default() - }; - - Self { - accent, - background, - palette, - root_font_size: root_font_size(groups.get("General")), - } + Self { accent, background } } pub(crate) fn into_system( - mut self, + self, accessibility: crate::system::AccessibilityPreferences, portal_accent: Option, portal_variant: Option, ) -> SystemTheme { - // Schemes that state no DecorationFocus fall back to the accent. - if self.palette.ring.is_none() { - self.palette.ring = self.accent; - } - SystemTheme { // The portal states the mode on Plasma 5.21+. // @@ -80,18 +46,6 @@ impl KdeScheme { .or(self.background.map(crate::ThemeVariant::by_lightness)) .unwrap_or(crate::ThemeVariant::Light), accent: self.accent.or(portal_accent), - palette: self.palette, - control_radius: Some(px(5.)), - overlay_radius: Some(px(5.)), - sm_radius: None, - control_height: Some(px(33.)), - input_height: Some(px(29.)), - menu_item_height: Some(px(29.)), - switch_height: Some(px(18.)), - switch_width: Some(px(36.)), - switch_knob: Some(px(18.)), - titlebar_height: Some(px(44.)), - root_font_size: Some(self.root_font_size.unwrap_or(px(13.33))), accessibility, window_background: None, source: SourceKind::Kde, @@ -99,22 +53,6 @@ impl KdeScheme { } } -/// The root font size of a `[General]` group's `font=` QFont string. -fn root_font_size(group: Option<&HashMap<&str, &str>>) -> Option { - let fields: Vec<&str> = group?.get("font")?.split(',').map(str::trim).collect(); - let points = fields.get(1)?.parse::().ok()?; - let pixels = fields - .get(2) - .and_then(|size| size.parse::().ok()) - .unwrap_or(-1.0); - let size = if pixels > 0.0 { - pixels - } else { - points * 96.0 / 72.0 - }; - (size > 0.0).then(|| px(size)) -} - fn parse_groups(text: &str) -> HashMap<&str, HashMap<&str, &str>> { let mut groups: HashMap<&str, HashMap<&str, &str>> = HashMap::new(); let mut section: Option<&str> = None; @@ -236,10 +174,10 @@ activeBackground=39,44,49 "; #[test] - fn breeze_groups_map_onto_roles() { + fn breeze_states_the_window_background() { let scheme = KdeScheme::parse(BREEZE_DARK); let scale = |component: u32| component as f32 / 255.0; - let background = scheme.palette.background.expect("window background"); + let background = scheme.background.expect("window background"); assert_eq!( gpui::Rgba::from(background), @@ -250,41 +188,12 @@ activeBackground=39,44,49 a: 1.0, } ); - assert_eq!( - scheme.palette.selection, - Some(Hsla::from(gpui::Rgba { - r: scale(61), - g: scale(174), - b: scale(233), - a: 1.0, - })) - ); - assert_eq!( - scheme.palette.muted_foreground, - Some(Hsla::from(gpui::Rgba { - r: scale(161), - g: scale(169), - b: scale(177), - a: 1.0, - })) - ); - assert_eq!( - scheme.palette.destructive, - Some(Hsla::from(gpui::Rgba { - r: scale(218), - g: scale(68), - b: scale(83), - a: 1.0, - })) - ); } #[test] fn localized_and_unrelated_keys_are_ignored() { let scheme = KdeScheme::parse(BREEZE_DARK); - assert!(scheme.accent.is_none()); - assert_eq!(scheme.palette.foreground, scheme.palette.surface_foreground); } #[test] @@ -329,29 +238,12 @@ activeBackground=39,44,49 assert_eq!(system.variant, crate::ThemeVariant::Light); } - #[test] - fn the_default_font_applies_without_a_stated_font() { - let system = KdeScheme::parse(BREEZE_DARK).into_system(Default::default(), None, None); - assert!((system.root_font_size.expect("default font") - px(13.33)).abs() < px(0.01)); - } - #[test] fn color_components_outside_0_to_255_are_rejected() { let above = KdeScheme::parse("[Colors:Window]\nBackgroundNormal=300,20,20\n"); - assert!(above.palette.background.is_none()); + assert!(above.background.is_none()); let below = KdeScheme::parse("[Colors:Window]\nBackgroundNormal=-5,20,20\n"); - assert!(below.palette.background.is_none()); - } - - #[test] - fn the_stated_font_beats_the_default() { - let text = "[General]\nfont=Noto Sans,10,-1,5,50,0,0,0,0,0\n"; - let system = KdeScheme::parse(text).into_system(Default::default(), None, None); - assert!((system.root_font_size.unwrap() - px(10.0 * 96.0 / 72.0)).abs() < px(0.01)); - - let text = "[General]\nfont=Adwaita Sans,-1,12,5,50,0,0,0,0,0\n"; - let system = KdeScheme::parse(text).into_system(Default::default(), None, None); - assert_eq!(system.root_font_size, Some(px(12.))); + assert!(below.background.is_none()); } } diff --git a/crates/theme/src/source/linux.rs b/crates/theme/src/source/linux.rs index dc0ec9d..abebc45 100644 --- a/crates/theme/src/source/linux.rs +++ b/crates/theme/src/source/linux.rs @@ -1,11 +1,11 @@ //! Linux adapter selection: Omarchy → KDE → portal (GNOME/generic) → -//! fallback, per the plan's detection cascade. Omarchy and KDE palettes come -//! from their files; the portal supplements mode, accent, and the -//! accessibility flags; `gsettings` covers sessions without a portal. +//! fallback, per the plan's detection cascade. Omarchy and KDE state the mode +//! and accent; the portal supplements both with the accessibility flags; +//! `gsettings` covers sessions without a portal. use std::path::{Path, PathBuf}; -use gpui::{Hsla, Pixels}; +use gpui::Hsla; use notify::{RecursiveMode, Watcher}; use super::ThemeSource; @@ -16,26 +16,7 @@ use super::signal::ReapplySignal; use crate::ThemeVariant; -use crate::system::{PartialPalette, SourceKind, SystemTheme}; - -/// libadwaita's control corner radius, in px at 100% scaling. -const CONTROL_RADIUS_PX: f32 = 9.0; -/// libadwaita's popover corner radius. -const OVERLAY_RADIUS_PX: f32 = 15.0; -/// The checkbox indicator's corner radius. -const SM_RADIUS_PX: f32 = 6.0; -/// libadwaita's standard control and text-field height. -const CONTROL_HEIGHT_PX: f32 = 34.0; -/// The GTK menu row height. -const MENU_ITEM_HEIGHT_PX: f32 = 32.0; -/// The GTK switch: a 46x26 track with a 20px knob. -const SWITCH_HEIGHT_PX: f32 = 26.0; -const SWITCH_WIDTH_PX: f32 = 46.0; -const SWITCH_KNOB_PX: f32 = 20.0; -/// GNOME's headerbar height, in px at 100% scaling. -const TITLEBAR_HEIGHT_PX: f32 = 47.0; -/// The default 11pt interface font, in px. -const ROOT_FONT_SIZE_PX: f32 = 14.67; +use crate::system::{SourceKind, SystemTheme}; pub(crate) struct LinuxSource { backend: Backend, @@ -87,7 +68,6 @@ fn detect(home: &Path, portal_reachable: bool, gsettings_reachable: bool) -> Bac struct GSettingsSnapshot { variant: Option, accent: Option, - root_font_size: Option, } fn gsettings_value(args: &[&str]) -> Option { @@ -129,22 +109,10 @@ fn read_gsettings() -> Option { let accent = gsettings_value(&["get", "org.gnome.desktop.interface", "accent-color"]) .and_then(|value| accent_rgb(value.trim().trim_matches('\''))); - let root_font_size = gsettings_value(&["get", "org.gnome.desktop.interface", "font-name"]) - .and_then(|value| font_root_px(value.trim().trim_matches('\''))); - - if variant.is_none() && accent.is_none() && root_font_size.is_none() { + if variant.is_none() && accent.is_none() { return None; } - Some(GSettingsSnapshot { - variant, - accent, - root_font_size, - }) -} - -fn font_root_px(name: &str) -> Option { - let points = name.split_whitespace().last()?.parse::().ok()?; - (points > 0.0).then(|| gpui::px(points * 96.0 / 72.0)) + Some(GSettingsSnapshot { variant, accent }) } pub(crate) fn platform_source() -> Box { @@ -174,22 +142,6 @@ impl LinuxSource { SystemTheme { variant, accent, - palette: PartialPalette::default(), - control_radius: Some(gpui::px(CONTROL_RADIUS_PX)), - overlay_radius: Some(gpui::px(OVERLAY_RADIUS_PX)), - sm_radius: Some(gpui::px(SM_RADIUS_PX)), - control_height: Some(gpui::px(CONTROL_HEIGHT_PX)), - input_height: Some(gpui::px(CONTROL_HEIGHT_PX)), - menu_item_height: Some(gpui::px(MENU_ITEM_HEIGHT_PX)), - switch_height: Some(gpui::px(SWITCH_HEIGHT_PX)), - switch_width: Some(gpui::px(SWITCH_WIDTH_PX)), - switch_knob: Some(gpui::px(SWITCH_KNOB_PX)), - titlebar_height: Some(gpui::px(TITLEBAR_HEIGHT_PX)), - root_font_size: Some( - self.gsettings - .and_then(|gsettings| gsettings.root_font_size) - .unwrap_or(gpui::px(ROOT_FONT_SIZE_PX)), - ), accessibility, window_background: None, source: SourceKind::Gnome, @@ -358,25 +310,7 @@ mod tests { } #[test] - fn the_gsettings_font_name_states_the_root_font_size() { - assert_eq!( - font_root_px("Adwaita Sans 11"), - Some(gpui::px(11.0 * 96.0 / 72.0)) - ); - assert_eq!( - font_root_px("Noto Sans 10"), - Some(gpui::px(10.0 * 96.0 / 72.0)) - ); - assert_eq!( - font_root_px("Cantarell Bold 12.5"), - Some(gpui::px(12.5 * 96.0 / 72.0)) - ); - assert_eq!(font_root_px("Adwaita Sans"), None); - assert_eq!(font_root_px("Sans 0"), None); - } - - #[test] - fn the_gnome_snapshot_labels_gnome_and_defaults_the_root_font() { + fn the_gnome_snapshot_labels_gnome() { let source = LinuxSource { backend: Backend::Portal, portal: None, @@ -391,7 +325,7 @@ mod tests { ); assert_eq!(system.source, SourceKind::Gnome); - // The default 11pt font when gsettings states none. - assert_eq!(system.root_font_size, Some(gpui::px(ROOT_FONT_SIZE_PX))); + assert_eq!(system.variant, ThemeVariant::Light); + assert_eq!(system.accent, None); } } diff --git a/crates/theme/src/source/macos.rs b/crates/theme/src/source/macos.rs index cfb2a70..df8b161 100644 --- a/crates/theme/src/source/macos.rs +++ b/crates/theme/src/source/macos.rs @@ -1,14 +1,12 @@ //! macOS Adapter //! -//! Reads AppKit's semantic colors in the effective appearance and watches -//! the system's color preferences. +//! Reads the system accent and watches the system's color preferences. use objc2::rc::Retained; use objc2::runtime::{AnyObject, NSObject}; use objc2::{AnyThread, DefinedClass, define_class, msg_send, sel}; use objc2_app_kit::{ - NSAppearance, NSAppearanceNameAqua, NSAppearanceNameDarkAqua, NSColor, NSColorSpace, - NSWorkspace, NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification, + NSColor, NSColorSpace, NSWorkspace, NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification, }; use objc2_foundation::{ NSDictionary, NSDistributedNotificationCenter, NSKeyValueObservingOptions, NSNotification, @@ -20,24 +18,7 @@ use super::narrow_component; use super::ThemeSource; use super::signal::ReapplySignal; use crate::ThemeVariant; -use crate::system::{AccessibilityPreferences, PartialPalette, SourceKind, SystemTheme}; - -/// Default control radius for macOS controls. -const CONTROL_RADIUS_PTS: f32 = 6.0; -/// The text field's intrinsic height at regular size, square or rounded bezel alike. -const INPUT_HEIGHT_PTS: f32 = 24.0; -/// AppKit's regular push button, measured via `NSButton::fittingSize`. -const CONTROL_HEIGHT_PTS: f32 = 24.0; -/// The `NSMenu` row height; 20 before the macOS 26 redesign. -const MENU_ITEM_HEIGHT_PTS: f32 = 24.0; -/// `NSSwitch`, measured via `fittingSize`. -const SWITCH_TRACK_HEIGHT_PTS: f32 = 24.0; -const SWITCH_TRACK_WIDTH_PTS: f32 = 54.0; -const SWITCH_KNOB_PTS: f32 = 20.0; -/// The standard titled window's titlebar, measured via `contentLayoutRect`. -const TITLEBAR_HEIGHT_PTS: f32 = 32.0; -/// The HIG's default body text on macOS is 13 pt (system font size 13 at 1x). -const ROOT_FONT_SIZE_PTS: f32 = 13.0; +use crate::system::{AccessibilityPreferences, SourceKind, SystemTheme}; // An observer that forwards distributed notifications and preference. define_class!( @@ -91,58 +72,6 @@ impl MacosSource { a: narrow_component(converted.alphaComponent()), })) } - - /// Resolves the semantic colors with `variant` as the current drawing appearance. - fn snapshot_in_appearance(&self, variant: ThemeVariant) -> PartialPalette { - let name = match variant { - ThemeVariant::Light => { - // SAFETY: extern statics exported by AppKit, always initialized. - unsafe { NSAppearanceNameAqua } - } - ThemeVariant::Dark => { - // SAFETY: as above. - unsafe { NSAppearanceNameDarkAqua } - } - }; - - let Some(appearance) = NSAppearance::appearanceNamed(name) else { - return self.read_palette(); - }; - - let palette = std::cell::Cell::new(PartialPalette::default()); - appearance.performAsCurrentDrawingAppearance(&block2::RcBlock::new(|| { - palette.set(self.read_palette()); - })); - - palette.into_inner() - } - - fn read_palette(&self) -> PartialPalette { - PartialPalette { - background: Self::color_to_hsla(&NSColor::windowBackgroundColor()), - foreground: Self::color_to_hsla(&NSColor::labelColor()), - surface: Self::color_to_hsla(&NSColor::textBackgroundColor()), - surface_foreground: Self::color_to_hsla(&NSColor::labelColor()), - sidebar: Self::color_to_hsla(&NSColor::windowBackgroundColor()), - primary_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()), - accent_foreground: Self::color_to_hsla(&NSColor::alternateSelectedControlTextColor()), - secondary: None, - secondary_foreground: Self::color_to_hsla(&NSColor::secondaryLabelColor()), - muted: None, - muted_hover: None, - muted_foreground: Self::color_to_hsla(&NSColor::secondaryLabelColor()), - destructive: Self::color_to_hsla(&NSColor::systemRedColor()), - success: None, - warning: None, - info: None, - border: Self::color_to_hsla(&NSColor::separatorColor()), - input: Self::color_to_hsla(&NSColor::controlBackgroundColor()), - ring: Self::color_to_hsla(&NSColor::keyboardFocusIndicatorColor()), - selection: Self::color_to_hsla(&NSColor::selectedTextBackgroundColor()), - overlay: None, - scrollbar_thumb: None, - } - } } impl ThemeSource for MacosSource { @@ -155,26 +84,12 @@ impl ThemeSource for MacosSource { reduce_transparency: workspace.accessibilityDisplayShouldReduceTransparency(), }; - let palette = self.snapshot_in_appearance(variant); - SystemTheme { variant, accent: Self::color_to_hsla(&NSColor::controlAccentColor()), - palette, + accessibility, // macOS blurs what is behind the window natively. window_background: Some(gpui::WindowBackgroundAppearance::Blurred), - control_radius: Some(gpui::px(CONTROL_RADIUS_PTS)), - overlay_radius: None, - sm_radius: None, - control_height: Some(gpui::px(CONTROL_HEIGHT_PTS)), - input_height: Some(gpui::px(INPUT_HEIGHT_PTS)), - menu_item_height: Some(gpui::px(MENU_ITEM_HEIGHT_PTS)), - switch_height: Some(gpui::px(SWITCH_TRACK_HEIGHT_PTS)), - switch_width: Some(gpui::px(SWITCH_TRACK_WIDTH_PTS)), - switch_knob: Some(gpui::px(SWITCH_KNOB_PTS)), - titlebar_height: Some(gpui::px(TITLEBAR_HEIGHT_PTS)), - root_font_size: Some(gpui::px(ROOT_FONT_SIZE_PTS)), - accessibility, source: SourceKind::Macos, } } diff --git a/crates/theme/src/source/omarchy.rs b/crates/theme/src/source/omarchy.rs index bae6f5a..126ee6e 100644 --- a/crates/theme/src/source/omarchy.rs +++ b/crates/theme/src/source/omarchy.rs @@ -5,15 +5,14 @@ use gpui::Hsla; use toml::Table; -use crate::system::{PartialPalette, SourceKind, SystemTheme}; +use crate::system::{SourceKind, SystemTheme}; use crate::{AccessibilityPreferences, ThemeVariant}; -/// The palette Omarchy deploys with the current theme. +/// The mode and accent Omarchy deploys with the current theme. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct OmarchyTheme { pub(crate) variant: ThemeVariant, pub(crate) accent: Option, - pub(crate) palette: PartialPalette, } impl OmarchyTheme { @@ -21,7 +20,6 @@ impl OmarchyTheme { let table = text.parse::().ok()?; let background = hex_color(&table, "background")?; - let foreground = hex_color(&table, "foreground")?; let variant = table .get("mode") @@ -30,47 +28,14 @@ impl OmarchyTheme { .unwrap_or_else(|| ThemeVariant::by_lightness(background)); let accent = hex_color(&table, "accent").or_else(|| hex_color(&table, "color4")); - let selection = hex_color(&table, "selection"); - let muted_foreground = - hex_color(&table, "dark_foreground").or_else(|| hex_color(&table, "color8")); - let palette = PartialPalette { - background: Some(background), - foreground: Some(foreground), - surface: hex_color(&table, "lighter_background"), - surface_foreground: Some(foreground), - muted_foreground, - destructive: hex_color(&table, "red").or_else(|| hex_color(&table, "color1")), - success: hex_color(&table, "green").or_else(|| hex_color(&table, "color2")), - warning: hex_color(&table, "yellow").or_else(|| hex_color(&table, "orange")), - ring: accent, - selection, - ..PartialPalette::default() - }; - - Some(Self { - variant, - accent, - palette, - }) + Some(Self { variant, accent }) } pub(crate) fn into_system(self, accessibility: AccessibilityPreferences) -> SystemTheme { SystemTheme { variant: self.variant, accent: self.accent, - palette: self.palette, - control_radius: Some(gpui::px(9.)), - overlay_radius: Some(gpui::px(15.)), - sm_radius: Some(gpui::px(6.)), - control_height: Some(gpui::px(34.)), - input_height: Some(gpui::px(34.)), - menu_item_height: Some(gpui::px(32.)), - switch_height: Some(gpui::px(26.)), - switch_width: Some(gpui::px(46.)), - switch_knob: Some(gpui::px(20.)), - titlebar_height: None, - root_font_size: None, accessibility, window_background: None, source: SourceKind::Omarchy, @@ -171,25 +136,11 @@ color15 = \"#635d6f\" "; #[test] - fn semantic_keys_map_onto_roles() { + fn semantic_keys_state_the_mode_and_accent() { let theme = OmarchyTheme::parse(TOKYO_NIGHT).expect("tokyo-night parses"); assert_eq!(theme.variant, ThemeVariant::Dark); assert_eq!(theme.accent, Some(Hsla::from(gpui::rgb(0x7aa2f7)))); - - let palette = theme.palette; - let background = palette.background.expect("background stated"); - assert_eq!(background, Hsla::from(gpui::rgb(0x1a1b26))); - assert_eq!(palette.surface, Some(Hsla::from(gpui::rgb(0x24283b)))); - assert_eq!( - palette.muted_foreground, - Some(Hsla::from(gpui::rgb(0x565f89))) - ); - assert_eq!(palette.destructive, Some(Hsla::from(gpui::rgb(0xf7768e)))); - assert_eq!(palette.success, Some(Hsla::from(gpui::rgb(0x9ece6a)))); - assert_eq!(palette.warning, Some(Hsla::from(gpui::rgb(0xe0af68)))); - assert_eq!(palette.selection, Some(Hsla::from(gpui::rgb(0x292e42)))); - assert_eq!(palette.ring, theme.accent); } #[test] @@ -198,14 +149,6 @@ color15 = \"#635d6f\" assert_eq!(theme.variant, ThemeVariant::Light); assert_eq!(theme.accent, Some(Hsla::from(gpui::rgb(0x0060ff)))); - assert_eq!( - theme.palette.destructive, - Some(Hsla::from(gpui::rgb(0xab2833))) - ); - assert_eq!( - theme.palette.muted_foreground, - Some(Hsla::from(gpui::rgb(0x625e6a))) - ); } #[test] @@ -216,11 +159,12 @@ color15 = \"#635d6f\" } #[test] - fn omarchy_states_no_titlebar_or_root_font() { + fn the_system_snapshot_keeps_only_mode_and_accent() { let theme = OmarchyTheme::parse(TOKYO_NIGHT).expect("parses"); let system = theme.into_system(Default::default()); - assert_eq!(system.titlebar_height, None); - assert_eq!(system.root_font_size, None); + assert_eq!(system.variant, ThemeVariant::Dark); + assert_eq!(system.accent, theme.accent); + assert_eq!(system.source, SourceKind::Omarchy); } } diff --git a/crates/theme/src/source/windows.rs b/crates/theme/src/source/windows.rs index 49bd5c4..e30d81e 100644 --- a/crates/theme/src/source/windows.rs +++ b/crates/theme/src/source/windows.rs @@ -1,7 +1,6 @@ -//! Windows 11 adapter: WinRT `UISettings` semantic colors with a +//! Windows 11 adapter: WinRT `UISettings` accent and background with a //! `Personalize` registry fallback, watched through `ColorValuesChanged`, -//! `TextScaleFactorChanged`, `AdvancedEffectsEnabledChanged`, and -//! `HighContrastChanged`. +//! `AdvancedEffectsEnabledChanged`, and `HighContrastChanged`. use windows::Foundation::TypedEventHandler; use windows::UI::ViewManagement::{AccessibilitySettings, UIColorType, UISettings}; @@ -12,26 +11,7 @@ use windows::core::IInspectable; use super::ThemeSource; use super::signal::ReapplySignal; use crate::ThemeVariant; -use crate::system::{AccessibilityPreferences, PartialPalette, SourceKind, SystemTheme}; - -/// WinUI 11's `ControlCornerRadius`, in pixels at 100% scaling. -const CONTROL_RADIUS_PX: f32 = 4.0; -/// WinUI 11's `OverlayCornerRadius`, in pixels at 100% scaling. -const OVERLAY_RADIUS_PX: f32 = 8.0; -/// WinUI 11's default text-box height, in pixels at 100% scaling. -const INPUT_HEIGHT_PX: f32 = 32.0; -/// The default button height, in pixels at 100% scaling. -const CONTROL_HEIGHT_PX: f32 = 32.0; -/// The default menu row: item padding 4/5 + a 20px Body line + 2px item margins. -const MENU_ITEM_HEIGHT_PX: f32 = 33.0; -/// ToggleSwitch: a 40x20 track with a 12px resting knob. -const SWITCH_TRACK_HEIGHT_PX: f32 = 20.0; -const SWITCH_TRACK_WIDTH_PX: f32 = 40.0; -const SWITCH_KNOB_PX: f32 = 12.0; -/// The window caption's height, in pixels at 100% scaling, as Win32 reports it. -const TITLEBAR_HEIGHT_PX: f32 = 32.0; -/// WinUI 11's default body text size, in pixels at 100% scaling. -const ROOT_FONT_SIZE_PX: f32 = 14.0; +use crate::system::{AccessibilityPreferences, SourceKind, SystemTheme}; /// The `Personalize` registry values and the OS build number. #[derive(Clone, Copy, Debug, Default)] @@ -159,7 +139,6 @@ impl ThemeSource for WindowsSource { fn snapshot(&self, variant: ThemeVariant) -> SystemTheme { let accent = self.color(UIColorType::Accent); let background = self.color(UIColorType::Background); - let foreground = self.color(UIColorType::Foreground); let variant = background .map(ThemeVariant::by_lightness) @@ -172,30 +151,9 @@ impl ThemeSource for WindowsSource { })) .unwrap_or(variant); - let text_scale = self.ui_settings.TextScaleFactor().unwrap_or(1.0); - SystemTheme { variant, accent, - // Windows states its ramp through UIColorType's accent variants. - palette: PartialPalette { - background, - foreground, - // Windows paints keyboard focus with the accent itself. - ring: accent, - ..PartialPalette::default() - }, - control_radius: Some(gpui::px(CONTROL_RADIUS_PX)), - overlay_radius: Some(gpui::px(OVERLAY_RADIUS_PX)), - sm_radius: None, - control_height: Some(gpui::px(CONTROL_HEIGHT_PX)), - input_height: Some(gpui::px(INPUT_HEIGHT_PX)), - menu_item_height: Some(gpui::px(MENU_ITEM_HEIGHT_PX)), - switch_height: Some(gpui::px(SWITCH_TRACK_HEIGHT_PX)), - switch_width: Some(gpui::px(SWITCH_TRACK_WIDTH_PX)), - switch_knob: Some(gpui::px(SWITCH_KNOB_PX)), - titlebar_height: Some(gpui::px(TITLEBAR_HEIGHT_PX)), - root_font_size: Some(gpui::px(ROOT_FONT_SIZE_PX * text_scale as f32)), accessibility: self.accessibility(), window_background: self.window_material(), source: SourceKind::Windows, @@ -214,16 +172,6 @@ impl ThemeSource for WindowsSource { log::warn!("theme: color change watch failed: {error}"); } - let scale_signal = signal.sender(); - let scale_handler = TypedEventHandler::::new(move |_, _| { - ReapplySignal::poke(&scale_signal); - Ok(()) - }); - - if let Err(error) = self.ui_settings.TextScaleFactorChanged(&scale_handler) { - log::warn!("theme: text scale watch failed: {error}"); - } - let effects_signal = signal.sender(); let effects_handler = TypedEventHandler::::new(move |_, _| { ReapplySignal::poke(&effects_signal); diff --git a/crates/theme/src/system.rs b/crates/theme/src/system.rs index 77eb9d4..36f4809 100644 --- a/crates/theme/src/system.rs +++ b/crates/theme/src/system.rs @@ -1,6 +1,6 @@ //! The normalized snapshot a platform adapter produces. -use gpui::{Hsla, Pixels, WindowBackgroundAppearance, px}; +use gpui::{Hsla, WindowBackgroundAppearance}; use crate::ThemeVariant; @@ -43,49 +43,6 @@ impl SourceKind { pub fn scrollbar_autohide(self) -> bool { matches!(self, Self::Macos | Self::Omarchy | Self::Gnome) } - - /// The base spacing unit: - /// - /// - GNOME lays out on a 6px grid - /// - Other platform on 4px grid - pub fn spacing_unit(self) -> Pixels { - match self { - Self::Gnome | Self::Omarchy => px(6.), - _ => px(4.), - } - } -} - -/// A partial palette with optional colors. -#[derive(Clone, Copy, Debug, Default, PartialEq)] -pub struct PartialPalette { - pub background: Option, - pub foreground: Option, - pub surface: Option, - pub surface_foreground: Option, - /// Only macOS states it, the window backdrop its sidebars show. - pub sidebar: Option, - pub primary_foreground: Option, - pub accent_foreground: Option, - pub secondary: Option, - pub secondary_foreground: Option, - pub muted: Option, - /// No platform states a hover wash, presets override it. - pub muted_hover: Option, - pub muted_foreground: Option, - pub destructive: Option, - /// No platform states severity colors, presets override them. - pub success: Option, - pub warning: Option, - pub info: Option, - pub border: Option, - pub input: Option, - pub ring: Option, - pub selection: Option, - /// No platform states a scrim color; preset and user files override it. - pub overlay: Option, - /// No platform states a scrollbar thumb color; presets override it. - pub scrollbar_thumb: Option, } /// A normalized snapshot of the running system's theme. @@ -93,29 +50,6 @@ pub struct PartialPalette { pub struct SystemTheme { pub variant: ThemeVariant, pub accent: Option, - pub palette: PartialPalette, - /// The platform's stated control corner radius, if it has one. - pub control_radius: Option, - /// The platform's stated menu/popover radius, if it has one. - pub overlay_radius: Option, - /// The platform's stated checkbox radius, if it has one. - pub sm_radius: Option, - /// The platform's stated control height, if it has one. - pub control_height: Option, - /// The platform's stated text-field height, if it has one. - pub input_height: Option, - /// The platform's stated menu row height, if it has one. - pub menu_item_height: Option, - /// The platform's stated switch track height, if it has one. - pub switch_height: Option, - /// The platform's stated switch track width, if it has one. - pub switch_width: Option, - /// The platform's stated switch knob size, if it has one. - pub switch_knob: Option, - /// The platform's native titlebar height, if it states one. - pub titlebar_height: Option, - /// The platform's native root font size, if it has one. - pub root_font_size: Option, pub accessibility: AccessibilityPreferences, /// The window material the platform natively applies, if any. pub window_background: Option, @@ -127,18 +61,6 @@ impl SystemTheme { Self { variant, accent: None, - palette: PartialPalette::default(), - control_radius: None, - overlay_radius: None, - sm_radius: None, - control_height: None, - input_height: None, - menu_item_height: None, - switch_height: None, - switch_width: None, - switch_knob: None, - titlebar_height: None, - root_font_size: None, accessibility: AccessibilityPreferences::default(), window_background: None, source: SourceKind::Fallback, diff --git a/crates/theme/src/typography.rs b/crates/theme/src/typography.rs index 0d9de9a..20547c1 100644 --- a/crates/theme/src/typography.rs +++ b/crates/theme/src/typography.rs @@ -1,224 +1,29 @@ -//! The platform's type ladder: eleven roles resolved from the OS's own text -//! styles. -//! -//! Each [`SourceKind`] paints its stated ramp — Apple's macOS built-in text -//! styles, WinUI's type ramp, GTK 4's typography classes, Kirigami's heading -//! levels — and every rung scales with the theme's root font size, the way -//! XAML text scaling and GTK's relative font sizes work. Platforms that state -//! no styles paint the neutral ladder. +//! One type ladder shared by every platform, scaled by the theme's root font +//! size. use gpui::{App, FontWeight, Pixels, Styled, px}; use crate::ActiveTheme; -use crate::system::SourceKind; -const MACOS_BASE_PX: f32 = 13.0; -const WINDOWS_BASE_PX: f32 = 14.0; -const GNOME_BASE_PX: f32 = 44.0 / 3.0; -const KDE_BASE_PX: f32 = 40.0 / 3.0; -const NEUTRAL_BASE_PX: f32 = 16.0; -const GNOME_LEADING: f32 = 1.33; -const KDE_LEADING: f32 = 1.36; - -/// Apple's macOS built-in text styles (HIG, Typography specifications). -const MACOS: [Rung; 11] = [ - // Large Title - (26.0, 32.0, FontWeight::NORMAL), - // Title 1 - (22.0, 26.0, FontWeight::NORMAL), - // Title 2 - (17.0, 22.0, FontWeight::NORMAL), - // Title 3 - (15.0, 20.0, FontWeight::NORMAL), - // Headline - (13.0, 16.0, FontWeight::SEMIBOLD), - // Body - (13.0, 16.0, FontWeight::NORMAL), - // Callout - (12.0, 15.0, FontWeight::NORMAL), - // Subheadline - (11.0, 14.0, FontWeight::NORMAL), - // Footnote - (10.0, 13.0, FontWeight::NORMAL), - // Caption 1 - (10.0, 13.0, FontWeight::NORMAL), - // Caption 2 - (10.0, 13.0, FontWeight::MEDIUM), -]; - -/// WinUI's type ramp (Segoe UI Variable, Windows 11). -const WINDOWS: [Rung; 11] = [ - // TitleLarge - (40.0, 52.0, FontWeight::SEMIBOLD), - // Title - (28.0, 36.0, FontWeight::SEMIBOLD), - // Subtitle +/// The shared ladder at a 16px root: size, line height, then weight. +const LADDER: [Rung; 11] = [ + (24.0, 32.0, FontWeight::SEMIBOLD), (20.0, 28.0, FontWeight::SEMIBOLD), - // BodyLarge - (18.0, 24.0, FontWeight::NORMAL), - // BodyStrong - (14.0, 20.0, FontWeight::SEMIBOLD), - // Body - (14.0, 20.0, FontWeight::NORMAL), - // Body - (14.0, 20.0, FontWeight::NORMAL), - // Caption - (12.0, 16.0, FontWeight::NORMAL), - // Caption - (12.0, 16.0, FontWeight::NORMAL), - // Caption - (12.0, 16.0, FontWeight::NORMAL), - // Caption - (12.0, 16.0, FontWeight::NORMAL), -]; - -/// GTK 4's typography classes (Adwaita, "General Typography"), stated as -/// percentages of the default font. -const GNOME: [Rung; 11] = [ - // large-title: 240%, light - ( - GNOME_BASE_PX * 2.4, - GNOME_BASE_PX * 2.4 * GNOME_LEADING, - FontWeight::LIGHT, - ), - // title-1: 200% - ( - GNOME_BASE_PX * 2.0, - GNOME_BASE_PX * 2.0 * GNOME_LEADING, - FontWeight::EXTRA_BOLD, - ), - // title-2: 150% - ( - GNOME_BASE_PX * 1.5, - GNOME_BASE_PX * 1.5 * GNOME_LEADING, - FontWeight::EXTRA_BOLD, - ), - // title-3: 150% - ( - GNOME_BASE_PX * 1.5, - GNOME_BASE_PX * 1.5 * GNOME_LEADING, - FontWeight::BOLD, - ), - // heading: 110% - ( - GNOME_BASE_PX * 1.1, - GNOME_BASE_PX * 1.1 * GNOME_LEADING, - FontWeight::BOLD, - ), - // body: the default font; the HIG's body is control-label size, so the - // theme's `.body` class adds a further 10% only where apps ask for it. - ( - GNOME_BASE_PX, - GNOME_BASE_PX * GNOME_LEADING, - FontWeight::NORMAL, - ), - // body - ( - GNOME_BASE_PX, - GNOME_BASE_PX * GNOME_LEADING, - FontWeight::NORMAL, - ), - // caption: 90% - ( - GNOME_BASE_PX * 0.9, - GNOME_BASE_PX * 0.9 * GNOME_LEADING, - FontWeight::NORMAL, - ), - // caption - ( - GNOME_BASE_PX * 0.9, - GNOME_BASE_PX * 0.9 * GNOME_LEADING, - FontWeight::NORMAL, - ), - // caption - ( - GNOME_BASE_PX * 0.9, - GNOME_BASE_PX * 0.9 * GNOME_LEADING, - FontWeight::NORMAL, - ), - // caption-heading: 90% - ( - GNOME_BASE_PX * 0.9, - GNOME_BASE_PX * 0.9 * GNOME_LEADING, - FontWeight::BOLD, - ), -]; - -/// Kirigami's heading levels and Plasma's small font (Breeze). -const KDE: [Rung; 11] = [ - // Heading level 1: 1.35×, DemiBold - ( - KDE_BASE_PX * 1.35, - KDE_BASE_PX * 1.35 * KDE_LEADING, - FontWeight::SEMIBOLD, - ), - // level 2: 1.20× - ( - KDE_BASE_PX * 1.2, - KDE_BASE_PX * 1.2 * KDE_LEADING, - FontWeight::SEMIBOLD, - ), - // level 3: 1.15× - ( - KDE_BASE_PX * 1.15, - KDE_BASE_PX * 1.15 * KDE_LEADING, - FontWeight::SEMIBOLD, - ), - // level 4: 1.10× - ( - KDE_BASE_PX * 1.1, - KDE_BASE_PX * 1.1 * KDE_LEADING, - FontWeight::SEMIBOLD, - ), - // level 5: DemiBold at the default size - (KDE_BASE_PX, KDE_BASE_PX * KDE_LEADING, FontWeight::SEMIBOLD), - // the default font - (KDE_BASE_PX, KDE_BASE_PX * KDE_LEADING, FontWeight::NORMAL), - // the default font - (KDE_BASE_PX, KDE_BASE_PX * KDE_LEADING, FontWeight::NORMAL), - // Plasma's small font (8pt at the 10pt default) - ( - KDE_BASE_PX * 0.8, - KDE_BASE_PX * 0.8 * KDE_LEADING, - FontWeight::NORMAL, - ), - ( - KDE_BASE_PX * 0.8, - KDE_BASE_PX * 0.8 * KDE_LEADING, - FontWeight::NORMAL, - ), - ( - KDE_BASE_PX * 0.8, - KDE_BASE_PX * 0.8 * KDE_LEADING, - FontWeight::NORMAL, - ), - // DemiBold, the platform's only stated emphasis weight - ( - KDE_BASE_PX * 0.8, - KDE_BASE_PX * 0.8 * KDE_LEADING, - FontWeight::SEMIBOLD, - ), -]; - -/// The fallback ladder for platforms that state no text styles. -const NEUTRAL: [Rung; 11] = [ - (32.0, 40.0, FontWeight::NORMAL), - (24.0, 32.0, FontWeight::NORMAL), - (20.0, 26.0, FontWeight::NORMAL), - (18.0, 24.0, FontWeight::NORMAL), + (18.0, 24.0, FontWeight::SEMIBOLD), (16.0, 24.0, FontWeight::SEMIBOLD), + (14.0, 20.0, FontWeight::SEMIBOLD), (16.0, 24.0, FontWeight::NORMAL), - (15.0, 22.0, FontWeight::NORMAL), + (14.0, 20.0, FontWeight::NORMAL), (14.0, 20.0, FontWeight::NORMAL), (13.0, 18.0, FontWeight::NORMAL), (12.0, 16.0, FontWeight::NORMAL), (12.0, 16.0, FontWeight::MEDIUM), ]; -/// One rung: size and line height at the table's base size, then the weight. +/// One rung: size and line height at a 16px root, then the weight. type Rung = (f32, f32, FontWeight); -/// A role in the platform's type ladder. +/// A role in the unified type ladder. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum TextRole { /// The largest heading — hero panels, greeters, welcome screens. @@ -253,7 +58,7 @@ pub struct TypeMetrics { pub weight: FontWeight, } -/// The platform's type ladder, resolved at the theme's root font size. +/// The unified type ladder, resolved at the theme's root font size. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Typography { pub large_title: TypeMetrics, @@ -270,19 +75,12 @@ pub struct Typography { } impl Typography { - pub(crate) fn resolve(source: SourceKind, root_font_size: Pixels) -> Self { - let (ladder, base_px) = match source { - SourceKind::Macos => (MACOS, MACOS_BASE_PX), - SourceKind::Windows => (WINDOWS, WINDOWS_BASE_PX), - SourceKind::Gnome => (GNOME, GNOME_BASE_PX), - SourceKind::Kde => (KDE, KDE_BASE_PX), - SourceKind::Fallback | SourceKind::Omarchy => (NEUTRAL, NEUTRAL_BASE_PX), - }; - let scale = root_font_size / px(base_px); + pub(crate) fn resolve(root_font_size: Pixels) -> Self { + let scale = root_font_size / px(16.); let metrics = |(size, line_height, weight): Rung| TypeMetrics { - size: px(size * scale), - line_height: px(line_height * scale), + size: px(size) * scale, + line_height: px(line_height) * scale, weight, }; @@ -298,7 +96,7 @@ impl Typography { footnote, caption, caption2, - ] = ladder.map(metrics); + ] = LADDER.map(metrics); Self { large_title, @@ -335,7 +133,7 @@ impl Typography { /// Paints a [`TextRole`] from the resolved theme, on anything styled. pub trait Typeset: Styled + Sized { - /// Sizes, leads, and weights the element as the platform's `role`. + /// Sizes, leads, and weights the element as `role`. fn typeset(self, role: TextRole, cx: &App) -> Self { let theme = cx.theme(); let metrics = theme.typography.get(role); @@ -351,181 +149,61 @@ impl Typeset for E {} mod tests { use super::*; - fn typography(source: SourceKind, root_font_size: f32) -> Typography { - Typography::resolve(source, px(root_font_size)) + fn typography(root_font_size: f32) -> Typography { + Typography::resolve(px(root_font_size)) } #[test] - fn the_platforms_paint_their_stated_styles() { - let macos = typography(SourceKind::Macos, 13.0); - assert_eq!( - macos.body, - TypeMetrics { - size: px(13.0), - line_height: px(16.0), - weight: FontWeight::NORMAL - } - ); - assert_eq!( - macos.headline, - TypeMetrics { - size: px(13.0), - line_height: px(16.0), - weight: FontWeight::SEMIBOLD - } - ); - assert_eq!( - macos.caption2, - TypeMetrics { - size: px(10.0), - line_height: px(13.0), - weight: FontWeight::MEDIUM - } - ); - assert_eq!(macos.large_title.size, px(26.0)); - - let windows = typography(SourceKind::Windows, 14.0); - assert_eq!( - windows.body, - TypeMetrics { - size: px(14.0), - line_height: px(20.0), - weight: FontWeight::NORMAL - } - ); - assert_eq!( - windows.headline, - TypeMetrics { - size: px(14.0), - line_height: px(20.0), - weight: FontWeight::SEMIBOLD - } - ); - assert_eq!( - windows.large_title, - TypeMetrics { - size: px(40.0), - line_height: px(52.0), - weight: FontWeight::SEMIBOLD - } - ); - - let gnome_base = 44.0 / 3.0; - let gnome = typography(SourceKind::Gnome, gnome_base); - assert_eq!( - gnome.body, - TypeMetrics { - size: px(gnome_base), - line_height: px(gnome_base * GNOME_LEADING), - weight: FontWeight::NORMAL - } - ); - assert_eq!( - gnome.large_title, - TypeMetrics { - size: px(gnome_base * 2.4), - line_height: px(gnome_base * 2.4 * GNOME_LEADING), - weight: FontWeight::LIGHT - } - ); - assert_eq!( - gnome.caption2, - TypeMetrics { - size: px(gnome_base * 0.9), - line_height: px(gnome_base * 0.9 * GNOME_LEADING), - weight: FontWeight::BOLD - } - ); - - let kde_base = 40.0 / 3.0; - let kde = typography(SourceKind::Kde, kde_base); - assert_eq!( - kde.body, - TypeMetrics { - size: px(kde_base), - line_height: px(kde_base * KDE_LEADING), - weight: FontWeight::NORMAL - } - ); - assert_eq!( - kde.large_title, - TypeMetrics { - size: px(kde_base * 1.35), - line_height: px(kde_base * 1.35 * KDE_LEADING), - weight: FontWeight::SEMIBOLD - } - ); - } - - #[test] - fn a_raised_root_font_size_scales_the_whole_ladder() { - // 26pt over macOS's 13pt base doubles every rung, weights carry over. - let doubled = typography(SourceKind::Macos, 26.0); - assert_eq!( - doubled.body, - TypeMetrics { - size: px(26.0), - line_height: px(32.0), - weight: FontWeight::NORMAL - } - ); - assert_eq!( - doubled.large_title, - TypeMetrics { - size: px(52.0), - line_height: px(64.0), - weight: FontWeight::NORMAL - } - ); - } - - #[test] - fn the_body_rung_equals_the_root_font_size_on_every_platform() { - let native = [ - (SourceKind::Macos, 13.0), - (SourceKind::Windows, 14.0), - (SourceKind::Gnome, 44.0 / 3.0), - (SourceKind::Kde, 40.0 / 3.0), - (SourceKind::Fallback, 16.0), - (SourceKind::Omarchy, 16.0), + fn the_unified_ladder_matches_the_base_contract() { + let typography = typography(16.0); + let expected = [ + (TextRole::LargeTitle, 24.0, 32.0, FontWeight::SEMIBOLD), + (TextRole::Title, 20.0, 28.0, FontWeight::SEMIBOLD), + (TextRole::Title2, 18.0, 24.0, FontWeight::SEMIBOLD), + (TextRole::Title3, 16.0, 24.0, FontWeight::SEMIBOLD), + (TextRole::Headline, 14.0, 20.0, FontWeight::SEMIBOLD), + (TextRole::Body, 16.0, 24.0, FontWeight::NORMAL), + (TextRole::Callout, 14.0, 20.0, FontWeight::NORMAL), + (TextRole::Subheadline, 14.0, 20.0, FontWeight::NORMAL), + (TextRole::Footnote, 13.0, 18.0, FontWeight::NORMAL), + (TextRole::Caption, 12.0, 16.0, FontWeight::NORMAL), + (TextRole::Caption2, 12.0, 16.0, FontWeight::MEDIUM), ]; - for (source, base) in native { - let typography = typography(source, base); - assert_eq!(typography.body.size, px(base), "{source:?}"); + for (role, size, line_height, weight) in expected { + assert_eq!( + typography.get(role), + TypeMetrics { + size: px(size), + line_height: px(line_height), + weight, + }, + "{role:?}" + ); } - - let raised = typography(SourceKind::Windows, 18.9); - assert!((raised.body.size - px(18.9)).abs() < px(0.01)); } #[test] - fn every_platform_ladder_descends() { - let sources = [ - SourceKind::Fallback, - SourceKind::Omarchy, - SourceKind::Macos, - SourceKind::Windows, - SourceKind::Gnome, - SourceKind::Kde, - ]; - for source in sources { - let typography = typography(source, 16.0); - let ladder = [ - typography.get(TextRole::LargeTitle).size, - typography.get(TextRole::Title).size, - typography.get(TextRole::Title2).size, - typography.get(TextRole::Title3).size, - typography.get(TextRole::Headline).size, - typography.get(TextRole::Body).size, - typography.get(TextRole::Callout).size, - typography.get(TextRole::Subheadline).size, - typography.get(TextRole::Footnote).size, - typography.get(TextRole::Caption).size, - typography.get(TextRole::Caption2).size, - ]; - for pair in ladder.windows(2) { - assert!(pair[0] >= pair[1], "{source:?}: {ladder:?}"); - } + fn the_ladder_scales_from_a_16px_root() { + let base = typography(16.0); + let raised = typography(20.0); + for role in [ + TextRole::LargeTitle, + TextRole::Title, + TextRole::Title2, + TextRole::Title3, + TextRole::Headline, + TextRole::Body, + TextRole::Callout, + TextRole::Subheadline, + TextRole::Footnote, + TextRole::Caption, + TextRole::Caption2, + ] { + let base = base.get(role); + let raised = raised.get(role); + assert!((raised.size - base.size * 1.25).abs() < px(0.01)); + assert!((raised.line_height - base.line_height * 1.25).abs() < px(0.01)); + assert_eq!(raised.weight, base.weight); } } } diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index db4e7fb..986921d 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -4,7 +4,7 @@ use gpui::{ Refineable as _, StatefulInteractiveElement, StyleRefinement, Styled, Window, WindowId, div, px, }; -use gpui_native_theme::{ActiveTheme as _, FOCUS_RING_SPREAD}; +use gpui_native_theme::{ActiveTheme as _, FOCUS_RING_ALPHA, FOCUS_RING_SPREAD}; use std::collections::HashMap; /// A row whose children center on the cross axis. @@ -94,7 +94,10 @@ pub fn record_anchor_bounds( /// Returns a focus ring shadow with the given color at half ink. pub fn focus_ring(color: Hsla) -> Vec { - vec![BoxShadow::new(px(0.), px(0.), color.alpha(0.5)).spread_radius(FOCUS_RING_SPREAD)] + vec![ + BoxShadow::new(px(0.), px(0.), color.alpha(FOCUS_RING_ALPHA)) + .spread_radius(FOCUS_RING_SPREAD), + ] } /// The next selectable row in the direction, or `None` at the ends. diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index e567a01..ced00e7 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -500,7 +500,11 @@ impl Gallery { plan: SharedString::from("starter"), })), "switch" => Arc::new(cx.new(|_| SwitchDemo { checked: true })), - "toggle" => Arc::new(cx.new(|_| ToggleDemo { pressed: false })), + "toggle" => Arc::new(cx.new(|_| ToggleDemo { + pressed: false, + icon_pressed: false, + icon_label_pressed: false, + })), "slider" => Arc::new(cx.new(|_| SliderDemo { volume: 40.0 })), "segmented" => Arc::new(cx.new(|_| SegmentedDemo { filter: ExploreFilter::default(), @@ -1585,6 +1589,8 @@ impl Render for SwitchDemo { struct ToggleDemo { pressed: bool, + icon_pressed: bool, + icon_label_pressed: bool, } impl Panel for ToggleDemo { @@ -1609,11 +1615,14 @@ impl Render for ToggleDemo { Toggle::new("toggle-demo-bold") .label("Bold") .pressed(self.pressed) - .on_change(move |pressed, _, cx| { - view.update(cx, |demo, cx| { - demo.pressed = pressed; - cx.notify(); - }); + .on_change({ + let view = view.clone(); + move |pressed, _, cx| { + view.update(cx, |demo, cx| { + demo.pressed = pressed; + cx.notify(); + }); + } }), ) .child( @@ -1621,6 +1630,36 @@ impl Render for ToggleDemo { .label("Disabled") .pressed(true) .disabled(true), + ) + .child( + Toggle::new("toggle-demo-icon") + .icon(IconRole::Star) + .accessibility_label("Favorite") + .pressed(self.icon_pressed) + .on_change({ + let view = view.clone(); + move |pressed, _, cx| { + view.update(cx, |demo, cx| { + demo.icon_pressed = pressed; + cx.notify(); + }); + } + }), + ) + .child( + Toggle::new("toggle-demo-icon-label") + .icon(IconRole::Star) + .label("Favorite") + .pressed(self.icon_label_pressed) + .on_change({ + let view = view.clone(); + move |pressed, _, cx| { + view.update(cx, |demo, cx| { + demo.icon_label_pressed = pressed; + cx.notify(); + }); + } + }), ), )) } @@ -3104,7 +3143,8 @@ impl Render for DropdownMenuDemo { }); let more = DropdownMenu::new("dropdown-demo-more") - .label("More") + .icon(IconRole::More) + .accessibility_label("More actions") .variant(ButtonVariant::Ghost) .open(self.open_menu == Some(DemoDropdown::More)) .on_open_change({