Use shared theme tokens across components
- Replace remaining raw component metrics with theme constants. - Share disabled opacity, focus ring alpha, and code line height. - Route editor borders, weights, and links through the theme. - Align tab, alert, toast, panel, and resize spacing.
This commit is contained in:
@@ -8,7 +8,9 @@ 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_STACK_WIDTH, ActiveTheme as _, ENTER_SLIDE_DISTANCE, Size, TextRole, Typeset as _,
|
||||
};
|
||||
use gpui_native_utils::ResultLogErr as _;
|
||||
|
||||
use crate::button::{Button, ButtonVariant};
|
||||
@@ -234,7 +236,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()
|
||||
@@ -242,7 +244,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)),
|
||||
@@ -370,7 +372,7 @@ impl RenderOnce for AlertsView {
|
||||
.absolute()
|
||||
.top_4()
|
||||
.right_4()
|
||||
.w_80()
|
||||
.w(ALERT_STACK_WIDTH)
|
||||
.flex()
|
||||
.flex_col()
|
||||
.items_end()
|
||||
|
||||
@@ -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 _, Size};
|
||||
use gpui_native_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
|
||||
use gpui_native_utils::{focus_ring, record_anchor_bounds};
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -322,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))
|
||||
})
|
||||
|
||||
@@ -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};
|
||||
@@ -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)
|
||||
|
||||
@@ -331,7 +331,7 @@ 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,
|
||||
@@ -339,6 +339,7 @@ impl Render for CommandPaletteState {
|
||||
theme.sizes.resolve(Size::default()),
|
||||
theme.colors.border,
|
||||
theme.elevations.dialog.shadows(),
|
||||
theme.titlebar_height,
|
||||
)
|
||||
};
|
||||
|
||||
@@ -516,7 +517,7 @@ impl Render for CommandPaletteState {
|
||||
.flex()
|
||||
.justify_center()
|
||||
.items_start()
|
||||
.pt_10()
|
||||
.pt(titlebar_height)
|
||||
.child(scrim)
|
||||
.child(panel),
|
||||
)
|
||||
|
||||
@@ -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};
|
||||
@@ -203,7 +203,9 @@ 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_96())
|
||||
.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()
|
||||
|
||||
@@ -11,7 +11,7 @@ use gpui::{
|
||||
div, relative,
|
||||
};
|
||||
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 crate::button::ButtonVariant;
|
||||
@@ -376,7 +376,7 @@ impl RenderOnce for DropdownMenu {
|
||||
.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)
|
||||
|
||||
@@ -16,7 +16,8 @@ use gpui::{
|
||||
};
|
||||
use gpui_native_icons::IconRole;
|
||||
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;
|
||||
|
||||
@@ -2147,7 +2148,7 @@ impl RenderOnce for Input {
|
||||
} else {
|
||||
metrics.dense_padding_x
|
||||
})
|
||||
.gap_1p5()
|
||||
.gap_2()
|
||||
.rounded(radius.control)
|
||||
.bg(colors.input)
|
||||
.text_size(metrics.text_size)
|
||||
@@ -2155,7 +2156,7 @@ impl RenderOnce for Input {
|
||||
.border_1()
|
||||
.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)
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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};
|
||||
@@ -685,7 +685,9 @@ 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)
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -181,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)
|
||||
|
||||
@@ -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};
|
||||
@@ -193,7 +193,7 @@ where
|
||||
.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)
|
||||
|
||||
@@ -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};
|
||||
@@ -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)
|
||||
|
||||
@@ -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 _, 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};
|
||||
@@ -750,7 +750,7 @@ impl RenderOnce for SpeechButton {
|
||||
.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()
|
||||
|
||||
@@ -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 _, CONTROL_SPRING, DISABLED_OPACITY, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
@@ -128,7 +128,7 @@ impl RenderOnce for Switch {
|
||||
.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()
|
||||
@@ -152,7 +152,11 @@ impl RenderOnce for Switch {
|
||||
track
|
||||
.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)
|
||||
})
|
||||
})
|
||||
.when(!self.checked, |track| {
|
||||
track.bg(colors.input).border_color(colors.border)
|
||||
|
||||
@@ -292,6 +292,7 @@ impl ToastEntry {
|
||||
.max_w(TOAST_MAX_WIDTH)
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.py_1p5()
|
||||
.px_3()
|
||||
.bg(surface)
|
||||
@@ -304,7 +305,6 @@ impl ToastEntry {
|
||||
pill.child(
|
||||
div()
|
||||
.flex_none()
|
||||
.mr_2()
|
||||
.flex()
|
||||
.items_center()
|
||||
.child(icon.size(icon_size).color(foreground)),
|
||||
@@ -312,6 +312,7 @@ impl ToastEntry {
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w(px(0.))
|
||||
.truncate()
|
||||
.text_size(text_size)
|
||||
@@ -321,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)
|
||||
@@ -336,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)
|
||||
|
||||
@@ -3,7 +3,7 @@ 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_theme::{ActiveTheme as _, DISABLED_OPACITY, Size};
|
||||
use gpui_native_utils::focus_ring;
|
||||
|
||||
use crate::common::{Sizable, StyledExt as _, h_flex};
|
||||
@@ -127,7 +127,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()
|
||||
|
||||
@@ -65,6 +65,7 @@ impl Render for Tooltip {
|
||||
// Copied out: the mutable reads below need `cx` free of this borrow.
|
||||
let theme = cx.theme();
|
||||
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;
|
||||
@@ -87,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())
|
||||
};
|
||||
@@ -102,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;
|
||||
|
||||
Reference in New Issue
Block a user