Update line heights, buttons to respond to UI scale

Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler 2023-10-18 17:55:17 -04:00
parent 7b2782c0f6
commit 7cb00aeb34
6 changed files with 47 additions and 13 deletions

View file

@ -1,6 +1,6 @@
use std::marker::PhantomData;
use gpui3::{Hsla, WindowContext};
use gpui3::{relative, Hsla, WindowContext};
use smallvec::SmallVec;
use crate::prelude::*;
@ -38,10 +38,19 @@ impl LabelColor {
}
}
#[derive(Default, PartialEq, Copy, Clone)]
pub enum LineHeightStyle {
#[default]
TextLabel,
/// Sets the line height to 1
UILabel,
}
#[derive(Element, Clone)]
pub struct Label<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
label: SharedString,
line_height_style: LineHeightStyle,
color: LabelColor,
strikethrough: bool,
}
@ -51,6 +60,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
Self {
state_type: PhantomData,
label: label.into(),
line_height_style: LineHeightStyle::default(),
color: LabelColor::Default,
strikethrough: false,
}
@ -61,6 +71,11 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
self
}
pub fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self {
self.line_height_style = line_height_style;
self
}
pub fn set_strikethrough(mut self, strikethrough: bool) -> Self {
self.strikethrough = strikethrough;
self
@ -82,6 +97,9 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
)
})
.text_size(ui_size(1.))
.when(self.line_height_style == LineHeightStyle::UILabel, |this| {
this.line_height(relative(1.))
})
.text_color(self.color.hsla(cx))
.child(self.label.clone())
}