make badge sizable and use badges for sidebar counts
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -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<Icon>,
|
||||
variant: BadgeVariant,
|
||||
size: Size,
|
||||
tooltip: Option<TooltipBuilder>,
|
||||
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))
|
||||
})
|
||||
|
||||
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user