diff --git a/crates/ui2/src/components/label.rs b/crates/ui2/src/components/label.rs index 4b9cea8dc2..c316a07483 100644 --- a/crates/ui2/src/components/label.rs +++ b/crates/ui2/src/components/label.rs @@ -3,6 +3,13 @@ use gpui::{relative, Hsla, Text, TextRun, WindowContext}; use crate::prelude::*; use crate::styled_ext::StyledExt; +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)] +pub enum LabelSize { + #[default] + Default, + Small, +} + #[derive(Default, PartialEq, Copy, Clone)] pub enum LabelColor { #[default] @@ -56,6 +63,7 @@ pub enum LineHeightStyle { #[derive(Component)] pub struct Label { label: SharedString, + size: LabelSize, line_height_style: LineHeightStyle, color: LabelColor, strikethrough: bool, @@ -65,12 +73,18 @@ impl Label { pub fn new(label: impl Into) -> Self { Self { label: label.into(), + size: LabelSize::Default, line_height_style: LineHeightStyle::default(), color: LabelColor::Default, strikethrough: false, } } + pub fn size(mut self, size: LabelSize) -> Self { + self.size = size; + self + } + pub fn color(mut self, color: LabelColor) -> Self { self.color = color; self @@ -98,7 +112,10 @@ impl Label { .bg(LabelColor::Hidden.hsla(cx)), ) }) - .text_ui() + .map(|this| match self.size { + LabelSize::Default => this.text_ui(), + LabelSize::Small => this.text_ui_sm(), + }) .when(self.line_height_style == LineHeightStyle::UILabel, |this| { this.line_height(relative(1.)) }) @@ -110,6 +127,7 @@ impl Label { #[derive(Component)] pub struct HighlightedLabel { label: SharedString, + size: LabelSize, color: LabelColor, highlight_indices: Vec, strikethrough: bool, @@ -121,12 +139,18 @@ impl HighlightedLabel { pub fn new(label: impl Into, highlight_indices: Vec) -> Self { Self { label: label.into(), + size: LabelSize::Default, color: LabelColor::Default, highlight_indices, strikethrough: false, } } + pub fn size(mut self, size: LabelSize) -> Self { + self.size = size; + self + } + pub fn color(mut self, color: LabelColor) -> Self { self.color = color; self @@ -186,6 +210,10 @@ impl HighlightedLabel { .bg(LabelColor::Hidden.hsla(cx)), ) }) + .map(|this| match self.size { + LabelSize::Default => this.text_ui(), + LabelSize::Small => this.text_ui_sm(), + }) .child(Text::styled(self.label, runs)) } } diff --git a/crates/ui2/src/components/tooltip.rs b/crates/ui2/src/components/tooltip.rs index 8f31d77b67..536bb22ba0 100644 --- a/crates/ui2/src/components/tooltip.rs +++ b/crates/ui2/src/components/tooltip.rs @@ -1,8 +1,8 @@ use gpui::{Div, Render}; use theme2::ActiveTheme; -use crate::prelude::*; use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor, StyledExt}; +use crate::{prelude::*, LabelSize}; pub struct TextTooltip { title: SharedString, @@ -49,7 +49,11 @@ impl Render for TextTooltip { }), ) .when_some(self.meta.clone(), |this, meta| { - this.child(Label::new(meta).color(LabelColor::Muted)) + this.child( + Label::new(meta) + .size(LabelSize::Small) + .color(LabelColor::Muted), + ) }) } }