mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 08:54:04 +00:00
Add LabelSize
This commit is contained in:
parent
9d31523cf3
commit
dc56a7b12b
2 changed files with 35 additions and 3 deletions
|
@ -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<SharedString>) -> 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<usize>,
|
||||
strikethrough: bool,
|
||||
|
@ -121,12 +139,18 @@ impl HighlightedLabel {
|
|||
pub fn new(label: impl Into<SharedString>, highlight_indices: Vec<usize>) -> 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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue