feat: unify theme system (#7)

Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
2026-11-16 12:58:32 +00:00
parent 745a01d7af
commit aed3601c89
47 changed files with 888 additions and 1875 deletions
+30 -21
View File
@@ -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<I>(mut self, icon: I) -> Self
where
I: Into<Icon>,
@@ -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)