From 41f34d0192d5990a56cc963899500936f8841fb7 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Wed, 18 Nov 2026 11:37:15 +0700 Subject: [PATCH] make badge sizable and use badges for sidebar counts --- crates/signed_app/src/repo/helpers.rs | 4 ++-- crates/signed_app/src/repo/history.rs | 1 + crates/signed_app/src/repo/mod.rs | 14 +++++++++++--- crates/ui/src/components/badge.rs | 23 ++++++++++++++++++----- crates/ui/src/components/sidebar.rs | 2 +- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/crates/signed_app/src/repo/helpers.rs b/crates/signed_app/src/repo/helpers.rs index f930c23..3d41aef 100644 --- a/crates/signed_app/src/repo/helpers.rs +++ b/crates/signed_app/src/repo/helpers.rs @@ -378,7 +378,7 @@ pub(crate) fn commit_row( .child( div() .font_family(cx.theme().mono_font) - .typeset(TextRole::Caption, cx) + .typeset(TextRole::Callout, cx) .text_color(cx.theme().colors.muted_foreground) .child(commit.id.clone()), ) @@ -386,7 +386,7 @@ pub(crate) fn commit_row( div() .flex_1() .min_w_0() - .typeset(TextRole::Body, cx) + .typeset(TextRole::Callout, cx) .text_ellipsis() .whitespace_nowrap() .child(commit.summary.clone()), diff --git a/crates/signed_app/src/repo/history.rs b/crates/signed_app/src/repo/history.rs index a3e2949..2d42f3e 100644 --- a/crates/signed_app/src/repo/history.rs +++ b/crates/signed_app/src/repo/history.rs @@ -155,6 +155,7 @@ impl Render for RepoHistoryView { let commit = commits[ix].clone(); let id = commit.id.clone(); let view = view.clone(); + commit_row( ix, &commit, diff --git a/crates/signed_app/src/repo/mod.rs b/crates/signed_app/src/repo/mod.rs index 3422a3c..b347959 100644 --- a/crates/signed_app/src/repo/mod.rs +++ b/crates/signed_app/src/repo/mod.rs @@ -17,6 +17,7 @@ use signed_state::{ }; use ui::alert::{Alert, AlertSeverity}; use ui::avatar::Avatar; +use ui::badge::Badge; use ui::common::{Sizable as _, h_flex, v_flex}; use ui::icons::{Icon, IconRole}; use ui::layout::panel::Panel; @@ -886,19 +887,25 @@ impl RepoDetailView { let mut entries = vec![ SidebarEntry::row("repo-nav-commits", "Commits") .prefix(Icon::named(IconRole::GitCommit)) - .when_some(commit_count, |entry, count| entry.suffix(count.to_string())), + .when_some(commit_count, |entry, count| { + entry.suffix(Badge::new(count, count.to_string()).xsmall()) + }), ]; if include_issues { entries.push( SidebarEntry::row("repo-nav-issues", "Issues") .prefix(Icon::named(IconRole::GitIssueDone)) - .when_some(issue_count, |entry, count| entry.suffix(count.to_string())), + .when_some(issue_count, |entry, count| { + entry.suffix(Badge::new(count, count.to_string()).xsmall()) + }), ); entries.push( SidebarEntry::row("repo-nav-pulls", "Pull requests") .prefix(Icon::named(IconRole::GitPullRequest)) - .when_some(pull_count, |entry, count| entry.suffix(count.to_string())), + .when_some(pull_count, |entry, count| { + entry.suffix(Badge::new(count, count.to_string()).xsmall()) + }), ); } @@ -991,6 +998,7 @@ impl Render for RepoDetailView { .severity(AlertSeverity::Danger) .title("Repository error") .message(error) + .style(ui::alert::AlertStyle::Inline) .on_dismiss(move |cx| { if let Err(error) = weak.update(cx, |this, cx| { this.error = None; diff --git a/crates/ui/src/components/badge.rs b/crates/ui/src/components/badge.rs index 331675c..309f7c1 100644 --- a/crates/ui/src/components/badge.rs +++ b/crates/ui/src/components/badge.rs @@ -17,7 +17,7 @@ use gpui::{ Window, transparent_black, }; -use crate::components::common::{StyledExt, h_flex}; +use crate::components::common::{Sizable, StyledExt, h_flex}; use crate::icons::Icon; use crate::theme::{ActiveTheme as _, Size, Theme}; @@ -87,6 +87,7 @@ pub struct Badge { label: SharedString, icon: Option, variant: BadgeVariant, + size: Size, tooltip: Option, style: StyleRefinement, } @@ -103,6 +104,7 @@ impl Badge { label: label.into(), icon: None, variant: BadgeVariant::default(), + size: Size::default(), tooltip: None, style: StyleRefinement::default(), } @@ -133,6 +135,12 @@ impl Badge { } } +impl Sizable for Badge { + fn apply_size(&mut self, size: Size) { + self.size = size; + } +} + impl gpui::Styled for Badge { fn style(&mut self) -> &mut gpui::StyleRefinement { &mut self.style @@ -142,8 +150,12 @@ impl gpui::Styled for Badge { impl RenderOnce for Badge { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { let theme = cx.theme(); - let metrics = theme.sizes.resolve(Size::Small); - let label_size = metrics.caption_size; + let metrics = theme.sizes.resolve(self.size); + let label_size = match self.size { + Size::XSmall | Size::Small => metrics.caption_size * 0.9, + Size::Medium | Size::Large => metrics.caption_size, + }; + let square = label_size * 2.; let (background, foreground, border) = self.variant.tokens(theme); h_flex() @@ -157,8 +169,9 @@ impl RenderOnce for Badge { .bg(background) .text_color(foreground) .text_size(label_size) - .px(metrics.dense_padding_x) - .py_0p5() + .px(label_size * 0.5) + .min_w(square) + .min_h(square) .when_some(self.icon, |badge, icon| { badge.child(icon.size(metrics.dense_icon_size).color(foreground)) }) diff --git a/crates/ui/src/components/sidebar.rs b/crates/ui/src/components/sidebar.rs index 5100024..e6efea2 100644 --- a/crates/ui/src/components/sidebar.rs +++ b/crates/ui/src/components/sidebar.rs @@ -473,6 +473,7 @@ impl SidebarEntry { .py_1() .min_h(theme.sizes.medium.control_height) .rounded(theme.radius.sm) + .text_color(label_color) .role(Role::ListItem) .aria_selected(selected) .aria_position_in_set(position_in_set) @@ -508,7 +509,6 @@ impl SidebarEntry { .overflow_hidden() .whitespace_nowrap() .text_ellipsis() - .text_color(label_color) .child(label), ) .when_some(detail, |row, detail| {