feat: unify theme system #7

Merged
reya merged 14 commits from unify-theme into master 2026-11-16 12:58:35 +00:00
27 changed files with 136 additions and 89 deletions
Showing only changes of commit 1dafa87bef - Show all commits
+6 -4
View File
@@ -8,7 +8,9 @@ use gpui::{
ease_out_quint, ease_out_quint,
}; };
use gpui_native_icons::{Icon, IconRole}; use gpui_native_icons::{Icon, IconRole};
use gpui_native_theme::{ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _}; use gpui_native_theme::{
ALERT_STACK_WIDTH, ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _,
};
use gpui_native_utils::ResultLogErr as _; use gpui_native_utils::ResultLogErr as _;
use crate::button::{Button, ButtonVariant}; use crate::button::{Button, ButtonVariant};
@@ -234,7 +236,7 @@ impl RenderOnce for Alert {
.items_start() .items_start()
.gap_3() .gap_3()
.px_3() .px_3()
.py_2p5() .py_2()
.when_some(self.icon.clone(), |alert, icon_glyph| { .when_some(self.icon.clone(), |alert, icon_glyph| {
alert.child( alert.child(
div() div()
@@ -242,7 +244,7 @@ impl RenderOnce for Alert {
.flex() .flex()
.items_center() .items_center()
.justify_center() .justify_center()
.size_6() .size(theme.sizes.small.avatar_size)
.rounded(theme.radius.full) .rounded(theme.radius.full)
.bg(ramp.base) .bg(ramp.base)
.child(icon_glyph.size(dense_icon_size).color(ramp.foreground)), .child(icon_glyph.size(dense_icon_size).color(ramp.foreground)),
@@ -370,7 +372,7 @@ impl RenderOnce for AlertsView {
.absolute() .absolute()
.top_4() .top_4()
.right_4() .right_4()
.w_80() .w(ALERT_STACK_WIDTH)
.flex() .flex()
.flex_col() .flex_col()
.items_end() .items_end()
+2 -2
View File
@@ -7,7 +7,7 @@ use gpui::{
StyleRefinement, Styled as _, Window, canvas, relative, transparent_black, StyleRefinement, Styled as _, Window, canvas, relative, transparent_black,
}; };
use gpui_native_icons::Icon; use gpui_native_icons::Icon;
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
use gpui_native_utils::{focus_ring, record_anchor_bounds}; use gpui_native_utils::{focus_ring, record_anchor_bounds};
use std::rc::Rc; use std::rc::Rc;
@@ -322,7 +322,7 @@ impl RenderOnce for Button {
.absolute() .absolute()
.inset_0(), .inset_0(),
) )
.when(self.disabled, |button| button.opacity(0.5)) .when(self.disabled, |button| button.opacity(DISABLED_OPACITY))
.when_some(self.tooltip, |button, tooltip| { .when_some(self.tooltip, |button, tooltip| {
button.tooltip(move |window, cx| tooltip(window, cx)) button.tooltip(move |window, cx| tooltip(window, cx))
}) })
+7 -3
View File
@@ -8,7 +8,7 @@ use gpui::{
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
}; };
use gpui_native_icons::{IconRole, icon}; 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 gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -132,7 +132,7 @@ impl RenderOnce for Checkbox {
.role(Role::CheckBox) .role(Role::CheckBox)
.when_some(a11y_label, |checkbox, label| checkbox.aria_label(label)) .when_some(a11y_label, |checkbox, label| checkbox.aria_label(label))
.aria_toggled(Toggled::from(self.checked)) .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| { .when(!self.disabled, |checkbox| {
checkbox checkbox
.cursor_pointer() .cursor_pointer()
@@ -154,7 +154,11 @@ impl RenderOnce for Checkbox {
indicator indicator
.bg(ramps.primary.base) .bg(ramps.primary.base)
.border_color(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( .child(
icon(IconRole::Check) icon(IconRole::Check)
.size(metrics.dense_icon_size) .size(metrics.dense_icon_size)
+3 -2
View File
@@ -331,7 +331,7 @@ impl Render for CommandPaletteState {
return div().into_any_element(); 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(); let theme = cx.theme();
( (
theme.colors, theme.colors,
@@ -339,6 +339,7 @@ impl Render for CommandPaletteState {
theme.sizes.resolve(Size::default()), theme.sizes.resolve(Size::default()),
theme.colors.border, theme.colors.border,
theme.elevations.dialog.shadows(), theme.elevations.dialog.shadows(),
theme.titlebar_height,
) )
}; };
@@ -516,7 +517,7 @@ impl Render for CommandPaletteState {
.flex() .flex()
.justify_center() .justify_center()
.items_start() .items_start()
.pt_10() .pt(titlebar_height)
.child(scrim) .child(scrim)
.child(panel), .child(panel),
) )
+4 -2
View File
@@ -8,7 +8,7 @@ use gpui::{
Styled as _, Window, canvas, deferred, div, ease_out_quint, relative, Styled as _, Window, canvas, deferred, div, ease_out_quint, relative,
}; };
use gpui_native_icons::IconRole; 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::button::{Button, ButtonVariant};
use crate::common::{DIALOG_LAYER, Sizable, StyledExt as _, v_flex}; use crate::common::{DIALOG_LAYER, Sizable, StyledExt as _, v_flex};
@@ -203,7 +203,9 @@ impl RenderOnce for Dialog {
.role(role) .role(role)
.aria_label(label) .aria_label(label)
.when_some(self.min_width, |panel, width| panel.min_w(width)) .when_some(self.min_width, |panel, width| panel.min_w(width))
.when(self.min_width.is_none(), |panel| panel.min_w_96()) .when(self.min_width.is_none(), |panel| {
panel.min_w(DIALOG_MIN_WIDTH)
})
.max_w(relative(0.9)) .max_w(relative(0.9))
.when_some(height, |panel, height| panel.h(height)) .when_some(height, |panel, height| panel.h(height))
.p_4() .p_4()
+2 -2
View File
@@ -11,7 +11,7 @@ use gpui::{
div, relative, div, relative,
}; };
use gpui_native_icons::{Icon, IconRole, icon}; use gpui_native_icons::{Icon, IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
use gpui_native_utils::{focus_handle, focus_ring}; use gpui_native_utils::{focus_handle, focus_ring};
use crate::button::ButtonVariant; use crate::button::ButtonVariant;
@@ -376,7 +376,7 @@ impl RenderOnce for DropdownMenu {
.border_1() .border_1()
.border_color(border) .border_color(border)
.when_some(background, |trigger, background| trigger.bg(background)) .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| { .when(!inert, |trigger| {
trigger trigger
.track_focus(&focus) .track_focus(&focus)
+4 -3
View File
@@ -16,7 +16,8 @@ use gpui::{
}; };
use gpui_native_icons::IconRole; use gpui_native_icons::IconRole;
use gpui_native_theme::{ use gpui_native_theme::{
ActiveTheme as _, CARET_WIDTH, ColorTokens, Size, UNDERLINE_WIDTH, WHEEL_LINE_HEIGHT, ActiveTheme as _, CARET_WIDTH, ColorTokens, DISABLED_OPACITY, Size, UNDERLINE_WIDTH,
WHEEL_LINE_HEIGHT,
}; };
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
@@ -2147,7 +2148,7 @@ impl RenderOnce for Input {
} else { } else {
metrics.dense_padding_x metrics.dense_padding_x
}) })
.gap_1p5() .gap_2()
.rounded(radius.control) .rounded(radius.control)
.bg(colors.input) .bg(colors.input)
.text_size(metrics.text_size) .text_size(metrics.text_size)
@@ -2155,7 +2156,7 @@ impl RenderOnce for Input {
.border_1() .border_1()
.border_color(colors.border) .border_color(colors.border)
.refine_style(&self.style) .refine_style(&self.style)
.when(self.disabled, |input| input.opacity(0.5)) .when(self.disabled, |input| input.opacity(DISABLED_OPACITY))
.when(!self.disabled, |input| { .when(!self.disabled, |input| {
input.track_focus(&focus_handle).tab_stop(true) input.track_focus(&focus_handle).tab_stop(true)
}) })
+3 -3
View File
@@ -4,7 +4,7 @@ use gpui::{
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
Window, Window,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -113,12 +113,12 @@ impl RenderOnce for Link {
h_flex() h_flex()
.id(self.id) .id(self.id)
.text_size(metrics.text_size) .text_size(metrics.text_size)
.text_color(colors.accent) .text_color(ramps.primary.base)
.underline() .underline()
.refine_style(&self.style) .refine_style(&self.style)
.role(Role::Link) .role(Role::Link)
.when_some(a11y_label, |link, label| link.aria_label(label)) .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| { .when(!self.disabled, |link| {
link.cursor_pointer() link.cursor_pointer()
.focusable() .focusable()
+4 -2
View File
@@ -12,7 +12,7 @@ use gpui::{
Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative, Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative,
}; };
use gpui_native_icons::{Icon, IconRole, icon as icon_glyph}; 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 gpui_native_utils::focus_handle;
use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex}; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
@@ -685,7 +685,9 @@ fn menu_panel(
.role(Role::Menu) .role(Role::Menu)
.aria_label(params.label) .aria_label(params.label)
.when_some(params.min_width, |panel, width| panel.min_w(width)) .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) .p(params.chrome.spacing_unit)
.bg(params.chrome.surface) .bg(params.chrome.surface)
.text_color(params.chrome.foreground) .text_color(params.chrome.foreground)
+2 -2
View File
@@ -8,7 +8,7 @@ use gpui::{
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
StyleRefinement, Styled as _, Window, anchored, canvas, deferred, div, ease_out_quint, point, 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}; use crate::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
@@ -181,7 +181,7 @@ impl RenderOnce for Popover {
.track_focus(&focus) .track_focus(&focus)
.role(Role::Dialog) .role(Role::Dialog)
.aria_label(label) .aria_label(label)
.min_w_32() .min_w(POPOVER_MIN_WIDTH)
.bg(colors.surface) .bg(colors.surface)
.text_color(colors.surface_foreground) .text_color(colors.surface_foreground)
.rounded(radius.overlay) .rounded(radius.overlay)
+7 -3
View File
@@ -4,7 +4,7 @@ use gpui::{
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
div, div,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex, v_flex}; use crate::common::{Sizable, StyledExt as _, h_flex, v_flex};
@@ -193,7 +193,7 @@ where
.role(Role::RadioButton) .role(Role::RadioButton)
.when_some(a11y_label, |row, label| row.aria_label(label)) .when_some(a11y_label, |row, label| row.aria_label(label))
.aria_toggled(Toggled::from(is_selected)) .aria_toggled(Toggled::from(is_selected))
.when(disabled, |row| row.opacity(0.5)) .when(disabled, |row| row.opacity(DISABLED_OPACITY))
.when(!disabled, move |row| { .when(!disabled, move |row| {
let value = radio.value.clone(); let value = radio.value.clone();
row.cursor_pointer() row.cursor_pointer()
@@ -217,7 +217,11 @@ where
indicator indicator
.bg(ramps.primary.base) .bg(ramps.primary.base)
.border_color(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( .child(
div() div()
.size(metrics.indicator_size / 2.0) .size(metrics.indicator_size / 2.0)
+2 -2
View File
@@ -8,7 +8,7 @@ use gpui::{
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas,
div, relative, 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 gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -186,7 +186,7 @@ impl RenderOnce for Slider {
.aria_numeric_value(f64::from(value)) .aria_numeric_value(f64::from(value))
.aria_min_numeric_value(f64::from(self.min)) .aria_min_numeric_value(f64::from(self.min))
.aria_max_numeric_value(f64::from(self.max)) .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| { .when(!self.disabled, |slider| {
slider slider
.track_focus(&focus_handle) .track_focus(&focus_handle)
+3 -3
View File
@@ -19,7 +19,7 @@ use gpui::{
StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative, StyleRefinement, Styled, Subscription, Task, WeakEntity, Window, div, relative,
}; };
use gpui_native_icons::{IconRole, icon}; use gpui_native_icons::{IconRole, icon};
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, SPEECH_WAVEFORM_WIDTH, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -750,7 +750,7 @@ impl RenderOnce for SpeechButton {
.text_color(foreground) .text_color(foreground)
.when(capturing, |button| button.bg(colors.muted)) .when(capturing, |button| button.bg(colors.muted))
.refine_style(&self.style) .refine_style(&self.style)
.when(disabled, |button| button.opacity(0.5)) .when(disabled, |button| button.opacity(DISABLED_OPACITY))
.aria_label(label.clone()) .aria_label(label.clone())
.tooltip(Tooltip::text(label)) .tooltip(Tooltip::text(label))
.child(if stopping { .child(if stopping {
@@ -877,7 +877,7 @@ impl RenderOnce for SpeechWaveform {
.justify_end() .justify_end()
.gap_0p5() .gap_0p5()
.h(metrics.icon_size) .h(metrics.icon_size)
.w_24() .w(SPEECH_WAVEFORM_WIDTH)
.overflow_hidden() .overflow_hidden()
.children(levels.iter().map(|level| { .children(levels.iter().map(|level| {
div() div()
+7 -3
View File
@@ -6,7 +6,7 @@ use gpui::{
RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _, RenderOnce, Role, SharedString, SpringAnimation, StatefulInteractiveElement as _,
StyleRefinement, Styled as _, Toggled, Window, div, px, StyleRefinement, Styled as _, Toggled, Window, div, px,
}; };
use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, Size}; use gpui_native_theme::{ActiveTheme as _, CONTROL_SPRING, DISABLED_OPACITY, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -128,7 +128,7 @@ impl RenderOnce for Switch {
.role(Role::Switch) .role(Role::Switch)
.when_some(a11y_label, |switch, label| switch.aria_label(label)) .when_some(a11y_label, |switch, label| switch.aria_label(label))
.aria_toggled(Toggled::from(self.checked)) .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| { .when(!self.disabled, |switch| {
switch switch
.cursor_pointer() .cursor_pointer()
@@ -152,7 +152,11 @@ impl RenderOnce for Switch {
track track
.bg(ramps.primary.base) .bg(ramps.primary.base)
.border_color(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)
})
}) })
.when(!self.checked, |track| { .when(!self.checked, |track| {
track.bg(colors.input).border_color(colors.border) track.bg(colors.input).border_color(colors.border)
+4 -3
View File
@@ -292,6 +292,7 @@ impl ToastEntry {
.max_w(TOAST_MAX_WIDTH) .max_w(TOAST_MAX_WIDTH)
.flex() .flex()
.items_center() .items_center()
.gap_2()
.py_1p5() .py_1p5()
.px_3() .px_3()
.bg(surface) .bg(surface)
@@ -304,7 +305,6 @@ impl ToastEntry {
pill.child( pill.child(
div() div()
.flex_none() .flex_none()
.mr_2()
.flex() .flex()
.items_center() .items_center()
.child(icon.size(icon_size).color(foreground)), .child(icon.size(icon_size).color(foreground)),
@@ -312,6 +312,7 @@ impl ToastEntry {
}) })
.child( .child(
div() div()
.flex_1()
.min_w(px(0.)) .min_w(px(0.))
.truncate() .truncate()
.text_size(text_size) .text_size(text_size)
@@ -321,7 +322,7 @@ impl ToastEntry {
.when_some(toast.action.clone(), |pill, action| { .when_some(toast.action.clone(), |pill, action| {
let toasts = toasts.clone(); let toasts = toasts.clone();
pill.child( pill.child(
div().flex_none().ml_2p5().child( div().flex_none().child(
Button::new(("toast-action", id)) Button::new(("toast-action", id))
.label(action.label.clone()) .label(action.label.clone())
.variant(ButtonVariant::Primary) .variant(ButtonVariant::Primary)
@@ -336,7 +337,7 @@ impl ToastEntry {
) )
}) })
.child( .child(
div().flex_none().ml_4().child( div().flex_none().child(
Button::new(("toast-close", id)) Button::new(("toast-close", id))
.icon(IconRole::Close) .icon(IconRole::Close)
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
+2 -2
View File
@@ -3,7 +3,7 @@ use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role, App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window, SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Toggled, Window,
}; };
use gpui_native_theme::{ActiveTheme as _, Size}; use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
use gpui_native_utils::focus_ring; use gpui_native_utils::focus_ring;
use crate::common::{Sizable, StyledExt as _, h_flex}; use crate::common::{Sizable, StyledExt as _, h_flex};
@@ -127,7 +127,7 @@ impl RenderOnce for Toggle {
.active(|style| style.bg(ramps.secondary.hover)) .active(|style| style.bg(ramps.secondary.hover))
}) })
.refine_style(&self.style) .refine_style(&self.style)
.when(self.disabled, |toggle| toggle.opacity(0.5)) .when(self.disabled, |toggle| toggle.opacity(DISABLED_OPACITY))
.when(!self.disabled, |toggle| { .when(!self.disabled, |toggle| {
toggle toggle
.cursor_pointer() .cursor_pointer()
+3 -1
View File
@@ -65,6 +65,7 @@ impl Render for Tooltip {
// Copied out: the mutable reads below need `cx` free of this borrow. // Copied out: the mutable reads below need `cx` free of this borrow.
let theme = cx.theme(); let theme = cx.theme();
let text_size = theme.sizes.medium.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 spacing_unit = theme.spacing.unit;
let surface = theme.colors.surface; let surface = theme.colors.surface;
let surface_foreground = theme.colors.surface_foreground; let surface_foreground = theme.colors.surface_foreground;
@@ -87,6 +88,7 @@ impl Render for Tooltip {
.rounded(radius_sm) .rounded(radius_sm)
.shadow(shadows.clone()) .shadow(shadows.clone())
.text_size(text_size) .text_size(text_size)
.line_height(line_height)
.text_color(surface_foreground) .text_color(surface_foreground)
.child(self.text.clone()) .child(self.text.clone())
}; };
@@ -102,7 +104,7 @@ impl Render for Tooltip {
cx, cx,
) )
.map(|bounds| bounds.size.height) .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 below = viewport_height - spacing_unit - parent.bottom();
let above = parent.top() - spacing_unit; let above = parent.top() - spacing_unit;
+5 -3
View File
@@ -8,11 +8,13 @@ use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent, AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
ParentElement as _, Pixels, RenderOnce, Role, SharedString, StatefulInteractiveElement as _, 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::grain::grain as grain_overlay;
use gpui_native_core::scroll_area::ScrollArea; 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}; 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. /// The change reporter, fired with the next selected row by pointer and keys.
@@ -160,7 +162,7 @@ impl Sidebar {
grain: false, grain: false,
border_right: true, border_right: true,
padded: true, padded: true,
width: px(240.0), width: SIDEBAR_DEFAULT_WIDTH,
a11y_label: None, a11y_label: None,
on_change: None, on_change: None,
entries: None, entries: None,
+8 -8
View File
@@ -16,7 +16,7 @@ use gpui_native_core::scroll_area::{ScrollArea, ScrollAxes};
use gpui_native_core::spinner::Spinner; use gpui_native_core::spinner::Spinner;
use gpui_native_core::tooltip::Tooltip; use gpui_native_core::tooltip::Tooltip;
use gpui_native_icons::IconRole; 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}; use gpui_native_utils::{StyledExt as _, adjacent_selectable};
/// Reports the next selected tab by pointer and keys. /// Reports the next selected tab by pointer and keys.
@@ -609,7 +609,7 @@ impl Tabs {
}) })
.flex() .flex()
.items_center() .items_center()
.gap_1p5() .gap_2()
.cursor_pointer() .cursor_pointer()
.role(Role::Tab) .role(Role::Tab)
.aria_selected(selected) .aria_selected(selected)
@@ -624,7 +624,7 @@ impl Tabs {
.py_1() .py_1()
.rounded_tl(theme.radius.sm) .rounded_tl(theme.radius.sm)
.rounded_tr(theme.radius.sm) .rounded_tr(theme.radius.sm)
.border_b_2() .border_b(TAB_INDICATOR_WIDTH)
.border_color(gpui::transparent_black()) .border_color(gpui::transparent_black())
.when(active, |chip| chip.border_color(theme.ramps.primary.base)), .when(active, |chip| chip.border_color(theme.ramps.primary.base)),
TabsVariant::Pill => chip TabsVariant::Pill => chip
@@ -1019,7 +1019,7 @@ impl Tab {
}) })
.flex() .flex()
.items_center() .items_center()
.gap_1p5() .gap_2()
.role(Role::Tab) .role(Role::Tab)
.aria_selected(selected) .aria_selected(selected)
.text_color(label_color) .text_color(label_color)
@@ -1033,7 +1033,7 @@ impl Tab {
.py_1() .py_1()
.rounded_tl(theme.radius.sm) .rounded_tl(theme.radius.sm)
.rounded_tr(theme.radius.sm) .rounded_tr(theme.radius.sm)
.border_b_2() .border_b(TAB_INDICATOR_WIDTH)
.border_color(gpui::transparent_black()) .border_color(gpui::transparent_black())
.when(active, |strip_tab| { .when(active, |strip_tab| {
strip_tab.border_color(theme.ramps.primary.base) strip_tab.border_color(theme.ramps.primary.base)
@@ -1072,9 +1072,9 @@ impl Tab {
div() div()
.absolute() .absolute()
.left_0() .left_0()
.top(px(2.0)) .top(TAB_INDICATOR_WIDTH)
.bottom(px(2.0)) .bottom(TAB_INDICATOR_WIDTH)
.w(px(2.0)) .w(TAB_INDICATOR_WIDTH)
.rounded(theme.radius.sm) .rounded(theme.radius.sm)
.bg(theme.ramps.primary.base), .bg(theme.ramps.primary.base),
) )
+2 -2
View File
@@ -12,7 +12,7 @@ use gpui::{
}; };
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility}; use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility};
use gpui_native_theme::{ use gpui_native_theme::{
ActiveTheme as _, ColorTokens, MONO_ADVANCE_RATIO, Ramps, WASH_ALPHA_SOFT, ActiveTheme as _, CODE_LINE_HEIGHT, ColorTokens, MONO_ADVANCE_RATIO, Ramps, WASH_ALPHA_SOFT,
}; };
use crate::highlight::{HighlightedCode, Language, Role, highlight}; use crate::highlight::{HighlightedCode, Language, Role, highlight};
@@ -256,7 +256,7 @@ impl Render for CodeViewState {
let colors = theme.colors; let colors = theme.colors;
let mono_font = theme.mono_font; let mono_font = theme.mono_font;
let text_size = theme.sizes.small.text_size; 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 char_width = text_size * MONO_ADVANCE_RATIO;
let root_font_size = theme.root_font_size; let root_font_size = theme.root_font_size;
+6 -4
View File
@@ -13,7 +13,7 @@ use gpui::{
point, uniform_list, point, uniform_list,
}; };
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarHandle, ScrollbarVisibility}; 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, MONO_ADVANCE_RATIO};
use similar::{Change, ChangeTag, TextDiff}; use similar::{Change, ChangeTag, TextDiff};
use std::ops::Range; use std::ops::Range;
@@ -535,7 +535,7 @@ fn render_row(
row_element.child( row_element.child(
div() div()
.flex_none() .flex_none()
.border_l_4() .border_l(BORDER_WIDTH * 4.0)
.border_color(gpui::transparent_black()), .border_color(gpui::transparent_black()),
) )
}, },
@@ -661,7 +661,9 @@ fn render_row(
_ => wash_strong(change_color), _ => wash_strong(change_color),
}) })
.when(options.indicators == DiffIndicators::Bars, |number| { .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() div()
.h_full() .h_full()
.flex_none() .flex_none()
.border_l_4() .border_l(BORDER_WIDTH * 4.0)
.border_color(change_color), .border_color(change_color),
) )
}, },
+17 -17
View File
@@ -9,19 +9,20 @@
use gpui::prelude::FluentBuilder as _; use gpui::prelude::FluentBuilder as _;
use gpui::{ use gpui::{
AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle, AnyElement, App, Bounds, ClipboardItem, Context, Div, Element, ElementId, Entity, FontStyle,
FontWeight, GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, GlobalElementId, HighlightStyle, InspectorElementId, InteractiveElement as _, InteractiveText,
InteractiveText, IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, IntoElement, KeyBinding, LayoutId, ListAlignment, ListOffset, ListState, MouseButton,
MouseButton, MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, MouseDownEvent, MouseMoveEvent, ObjectFit, ParentElement as _, Pixels, Refineable as _, Render,
Refineable as _, Render, SharedString, StatefulInteractiveElement as _, StrikethroughStyle, SharedString, StatefulInteractiveElement as _, StrikethroughStyle, StyleRefinement, Styled,
StyleRefinement, Styled, StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, StyledImage as _, StyledText, TextLayout, UnderlineStyle, Window, actions, div, img, list, px,
actions, div, img, list, px, relative, relative,
}; };
use gpui_native_core::button::{Button, ButtonVariant}; use gpui_native_core::button::{Button, ButtonVariant};
use gpui_native_core::checkbox::Checkbox; use gpui_native_core::checkbox::Checkbox;
use gpui_native_core::common::Sizable as _; use gpui_native_core::common::Sizable as _;
use gpui_native_core::scrollbar::{Scrollbar, ScrollbarVisibility}; use gpui_native_core::scrollbar::{Scrollbar, ScrollbarVisibility};
use gpui_native_theme::{ 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}; 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; const INDENT_STEP: f32 = 1.5;
/// The body line height. /// The body line height.
const BODY_LINE_HEIGHT: f32 = 1.6; 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. /// The tallest a standalone image renders, in root font sizes.
const IMAGE_MAX_HEIGHT: f32 = 14.0; const IMAGE_MAX_HEIGHT: f32 = 14.0;
/// The side of an inline image atom relative to the body text size. /// 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) .pb(bottom)
.when(quote, |frame| { .when(quote, |frame| {
frame frame
.border_l_2() .border_l(BORDER_WIDTH * 2.0)
.border_color(theme.colors.border) .border_color(theme.colors.border)
.pl(theme.root_font_size * QUOTE_INSET) .pl(theme.root_font_size * QUOTE_INSET)
}) })
@@ -1546,8 +1545,9 @@ fn text_row(
.pr_1() .pr_1()
.child(match marker { .child(match marker {
ListMarker::Bullet => div() ListMarker::Bullet => div()
.text_color(theme.colors.muted_foreground) .size(theme.spacing.unit)
.child("•") .rounded(theme.radius.full)
.bg(theme.colors.muted_foreground)
.into_any_element(), .into_any_element(),
ListMarker::Ordered(number) => div() ListMarker::Ordered(number) => div()
.text_color(theme.colors.muted_foreground) .text_color(theme.colors.muted_foreground)
@@ -1721,7 +1721,7 @@ fn code_row(
.when_some(language.cloned(), |row, language| { .when_some(language.cloned(), |row, language| {
row.child( row.child(
div() div()
.text_xs() .typeset(TextRole::Caption, cx)
.text_color(theme.colors.muted_foreground) .text_color(theme.colors.muted_foreground)
.child(language), .child(language),
) )
@@ -1845,7 +1845,7 @@ fn table_row(
.px_2() .px_2()
.py_1() .py_1()
.when(row.header, |cell_element| { .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)) .child(text_child(&cell.spans, &cell_id, piece, cx))
}) })
@@ -1981,7 +1981,7 @@ where
InlineStyle::Strong => highlights.push(( InlineStyle::Strong => highlights.push((
range, range,
HighlightStyle { HighlightStyle {
font_weight: Some(FontWeight::SEMIBOLD), font_weight: Some(theme.typography.headline.weight),
..Default::default() ..Default::default()
}, },
)), )),
@@ -1989,7 +1989,7 @@ where
range, range,
HighlightStyle { HighlightStyle {
font_style: Some(FontStyle::Italic), font_style: Some(FontStyle::Italic),
font_weight: Some(FontWeight::SEMIBOLD), font_weight: Some(theme.typography.headline.weight),
..Default::default() ..Default::default()
}, },
)), )),
@@ -2017,7 +2017,7 @@ where
highlights.push(( highlights.push((
range.clone(), range.clone(),
HighlightStyle { HighlightStyle {
color: Some(theme.colors.accent), color: Some(theme.ramps.primary.base),
underline: Some(UnderlineStyle { underline: Some(UnderlineStyle {
thickness: BORDER_WIDTH, thickness: BORDER_WIDTH,
color: None, color: None,
+2 -2
View File
@@ -7,7 +7,7 @@ use std::sync::Arc;
use gpui::{ use gpui::{
AnyElement, AnyView, App, Axis, Div, ElementId, Entity, IntoElement, ParentElement as _, 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_theme::ActiveTheme as _;
use gpui_native_utils::StyledExt as _; use gpui_native_utils::StyledExt as _;
@@ -126,7 +126,7 @@ impl gpui::Styled for PanelRow {
impl RenderOnce for PanelRow { impl RenderOnce for PanelRow {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let id = self.id.clone(); 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( let main = island(
div() div()
+6 -4
View File
@@ -9,9 +9,11 @@ use gpui::{
InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, InteractiveElement as _, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role, MouseMoveEvent, MouseUpEvent, ParentElement as _, Pixels, Point, RenderOnce, Role,
SharedString, StatefulInteractiveElement as _, StyleRefinement, Styled as _, Window, canvas, 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}; use gpui_native_utils::{StyledExt as _, focus_handle, focus_ring};
/// How far one keyboard arrow step moves the seam. /// 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 { fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme(); let theme = cx.theme();
let ring = theme.colors.ring; 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 let label = self
.accessibility_label .accessibility_label
@@ -150,7 +152,7 @@ impl RenderOnce for ResizeHandle {
handle.w_full().h(thickness) handle.w_full().h(thickness)
}) })
.refine_style(&self.style) .refine_style(&self.style)
.when(self.disabled, |handle| handle.opacity(0.5)) .when(self.disabled, |handle| handle.opacity(DISABLED_OPACITY))
.when(!self.disabled, |handle| { .when(!self.disabled, |handle| {
handle handle
.track_focus(&focus) .track_focus(&focus)
+2 -5
View File
@@ -23,9 +23,6 @@ use gpui_native_theme::ActiveTheme as _;
use gpui::Decorations; use gpui::Decorations;
#[cfg(any(target_os = "windows", target_os = "linux"))] #[cfg(any(target_os = "windows", target_os = "linux"))]
use gpui::SharedString; use gpui::SharedString;
#[cfg(target_os = "windows")]
use gpui::px;
/// macOS traffic-lights zone: the pad a leading titlebar strip reserves. /// macOS traffic-lights zone: the pad a leading titlebar strip reserves.
pub use gpui_native_theme::TRAFFIC_LIGHT_PAD; pub use gpui_native_theme::TRAFFIC_LIGHT_PAD;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@@ -232,7 +229,7 @@ fn caption_button(
close: bool, close: bool,
) -> AnyElement { ) -> AnyElement {
let theme = cx.theme(); 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 { let hover = if close {
WINDOWS_CLOSE_HOVER WINDOWS_CLOSE_HOVER
@@ -250,7 +247,7 @@ fn caption_button(
.flex() .flex()
.items_center() .items_center()
.justify_center() .justify_center()
.w(px(CAPTION_WIDTH)) .w(CAPTION_WIDTH)
.h_full() .h_full()
.window_control_area(area) .window_control_area(area)
.text_color(if enabled { .text_color(if enabled {
+18
View File
@@ -29,6 +29,24 @@ use std::time::Duration;
/// The hairline width of the control border every button and field paints. /// The hairline width of the control border every button and field paints.
pub const BORDER_WIDTH: Pixels = px(1.0); 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 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. /// The tallest an anchored popup's list may grow.
pub const POPUP_MAX_HEIGHT: Pixels = px(320.0); pub const POPUP_MAX_HEIGHT: Pixels = px(320.0);
/// The widest a tooltip may grow. /// The widest a tooltip may grow.
+5 -2
View File
@@ -4,7 +4,7 @@ use gpui::{
Refineable as _, StatefulInteractiveElement, StyleRefinement, Styled, Window, WindowId, div, Refineable as _, StatefulInteractiveElement, StyleRefinement, Styled, Window, WindowId, div,
px, 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; use std::collections::HashMap;
/// A row whose children center on the cross axis. /// 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. /// Returns a focus ring shadow with the given color at half ink.
pub fn focus_ring(color: Hsla) -> Vec<BoxShadow> { pub fn focus_ring(color: Hsla) -> Vec<BoxShadow> {
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. /// The next selectable row in the direction, or `None` at the ends.