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::prelude::*;
|
||||||
use crate::styled_ext::StyledExt;
|
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)]
|
#[derive(Default, PartialEq, Copy, Clone)]
|
||||||
pub enum LabelColor {
|
pub enum LabelColor {
|
||||||
#[default]
|
#[default]
|
||||||
|
@ -56,6 +63,7 @@ pub enum LineHeightStyle {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
|
size: LabelSize,
|
||||||
line_height_style: LineHeightStyle,
|
line_height_style: LineHeightStyle,
|
||||||
color: LabelColor,
|
color: LabelColor,
|
||||||
strikethrough: bool,
|
strikethrough: bool,
|
||||||
|
@ -65,12 +73,18 @@ impl Label {
|
||||||
pub fn new(label: impl Into<SharedString>) -> Self {
|
pub fn new(label: impl Into<SharedString>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
|
size: LabelSize::Default,
|
||||||
line_height_style: LineHeightStyle::default(),
|
line_height_style: LineHeightStyle::default(),
|
||||||
color: LabelColor::Default,
|
color: LabelColor::Default,
|
||||||
strikethrough: false,
|
strikethrough: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn size(mut self, size: LabelSize) -> Self {
|
||||||
|
self.size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color(mut self, color: LabelColor) -> Self {
|
pub fn color(mut self, color: LabelColor) -> Self {
|
||||||
self.color = color;
|
self.color = color;
|
||||||
self
|
self
|
||||||
|
@ -98,7 +112,10 @@ impl Label {
|
||||||
.bg(LabelColor::Hidden.hsla(cx)),
|
.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| {
|
.when(self.line_height_style == LineHeightStyle::UILabel, |this| {
|
||||||
this.line_height(relative(1.))
|
this.line_height(relative(1.))
|
||||||
})
|
})
|
||||||
|
@ -110,6 +127,7 @@ impl Label {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct HighlightedLabel {
|
pub struct HighlightedLabel {
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
|
size: LabelSize,
|
||||||
color: LabelColor,
|
color: LabelColor,
|
||||||
highlight_indices: Vec<usize>,
|
highlight_indices: Vec<usize>,
|
||||||
strikethrough: bool,
|
strikethrough: bool,
|
||||||
|
@ -121,12 +139,18 @@ impl HighlightedLabel {
|
||||||
pub fn new(label: impl Into<SharedString>, highlight_indices: Vec<usize>) -> Self {
|
pub fn new(label: impl Into<SharedString>, highlight_indices: Vec<usize>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
label: label.into(),
|
label: label.into(),
|
||||||
|
size: LabelSize::Default,
|
||||||
color: LabelColor::Default,
|
color: LabelColor::Default,
|
||||||
highlight_indices,
|
highlight_indices,
|
||||||
strikethrough: false,
|
strikethrough: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn size(mut self, size: LabelSize) -> Self {
|
||||||
|
self.size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color(mut self, color: LabelColor) -> Self {
|
pub fn color(mut self, color: LabelColor) -> Self {
|
||||||
self.color = color;
|
self.color = color;
|
||||||
self
|
self
|
||||||
|
@ -186,6 +210,10 @@ impl HighlightedLabel {
|
||||||
.bg(LabelColor::Hidden.hsla(cx)),
|
.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))
|
.child(Text::styled(self.label, runs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use gpui::{Div, Render};
|
use gpui::{Div, Render};
|
||||||
use theme2::ActiveTheme;
|
use theme2::ActiveTheme;
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor, StyledExt};
|
use crate::{h_stack, v_stack, KeyBinding, Label, LabelColor, StyledExt};
|
||||||
|
use crate::{prelude::*, LabelSize};
|
||||||
|
|
||||||
pub struct TextTooltip {
|
pub struct TextTooltip {
|
||||||
title: SharedString,
|
title: SharedString,
|
||||||
|
@ -49,7 +49,11 @@ impl Render for TextTooltip {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.when_some(self.meta.clone(), |this, meta| {
|
.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…
Add table
Add a link
Reference in a new issue