diff --git a/crates/gpui3/src/styled.rs b/crates/gpui3/src/styled.rs index d511198c650717e59ccdd516ad7a855806415166..00a68753b67c21ac13670d6e94427aa0059fe540 100644 --- a/crates/gpui3/src/styled.rs +++ b/crates/gpui3/src/styled.rs @@ -1,6 +1,6 @@ use crate::{ - self as gpui3, hsla, point, px, relative, rems, AlignItems, Display, Fill, FlexDirection, Hsla, - JustifyContent, Length, Position, Rems, SharedString, StyleRefinement, + self as gpui3, hsla, point, px, relative, rems, AlignItems, DefiniteLength, Display, Fill, + FlexDirection, Hsla, JustifyContent, Length, Position, Rems, SharedString, StyleRefinement, }; use crate::{BoxShadow, TextStyleRefinement}; use smallvec::smallvec; @@ -529,4 +529,14 @@ pub trait Styled { .font_family = Some(family_name.into()); self } + + fn line_height(mut self, line_height: impl Into) -> Self + where + Self: Sized, + { + self.text_style() + .get_or_insert_with(Default::default) + .line_height = Some(line_height.into()); + self + } } diff --git a/crates/ui2/src/components/title_bar.rs b/crates/ui2/src/components/title_bar.rs index f1d7d427117b3dbd170776e5b59daf10c9a63d67..7cf9e6cd16d7b84b41125400259bd00028fd2f9b 100644 --- a/crates/ui2/src/components/title_bar.rs +++ b/crates/ui2/src/components/title_bar.rs @@ -112,6 +112,7 @@ impl TitleBar { .justify_between() .w_full() .bg(color.background) + .py_1() .child( div() .flex() @@ -132,7 +133,7 @@ impl TitleBar { .child(Button::new("zed")) .child(Button::new("nate/gpui2-ui-components")), ) - .children(player_list.map(|p| PlayerStack::new(p))) + // .children(player_list.map(|p| PlayerStack::new(p))) .child(IconButton::new(Icon::Plus)), ) .child( @@ -146,7 +147,7 @@ impl TitleBar { .items_center() .gap_1() .child(IconButton::new(Icon::FolderX)) - .child(IconButton::new(Icon::Close)), + .child(IconButton::new(Icon::Exit)), ) .child(ToolDivider::new()) .child( diff --git a/crates/ui2/src/elements/button.rs b/crates/ui2/src/elements/button.rs index 66dcb3f46e9631cf713d8120d605b7906a13a99a..3491352116a6aff076f111e67f8391aaaa78e44e 100644 --- a/crates/ui2/src/elements/button.rs +++ b/crates/ui2/src/elements/button.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use gpui3::{DefiniteLength, Hsla, Interactive, MouseButton, WindowContext}; -use crate::prelude::*; use crate::settings::user_settings; use crate::{h_stack, Icon, IconColor, IconElement, Label, LabelColor}; +use crate::{prelude::*, LineHeightStyle}; #[derive(Default, PartialEq, Clone, Copy)] pub enum IconPosition { @@ -137,7 +137,9 @@ impl Button { } fn render_label(&self) -> Label { - Label::new(self.label.clone()).color(self.label_color()) + Label::new(self.label.clone()) + .color(self.label_color()) + .line_height_style(LineHeightStyle::UILabel) } fn render_icon(&self, icon_color: IconColor) -> Option> { diff --git a/crates/ui2/src/elements/icon.rs b/crates/ui2/src/elements/icon.rs index 56df8ee680f48802a8562157b36ed9bd2f3687b4..00c22432d47110dce99dac7df785b6638125c6e5 100644 --- a/crates/ui2/src/elements/icon.rs +++ b/crates/ui2/src/elements/icon.rs @@ -11,7 +11,7 @@ use crate::theme::{theme, Theme}; pub enum IconSize { Small, #[default] - Large, + Medium, } #[derive(Default, PartialEq, Copy, Clone)] @@ -58,6 +58,7 @@ pub enum Icon { ChevronRight, ChevronUp, Close, + Exit, ExclamationTriangle, File, FileGeneric, @@ -109,6 +110,7 @@ impl Icon { Icon::ChevronRight => "icons/chevron_right.svg", Icon::ChevronUp => "icons/chevron_up.svg", Icon::Close => "icons/x.svg", + Icon::Exit => "icons/exit.svg", Icon::ExclamationTriangle => "icons/warning.svg", Icon::File => "icons/file.svg", Icon::FileGeneric => "icons/file_icons/file.svg", @@ -177,13 +179,13 @@ impl IconElement { fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); let fill = self.color.color(theme); - - let sized_svg = match self.size { - IconSize::Small => svg().size_3p5(), - IconSize::Large => svg().size_4(), + let svg_size = match self.size { + IconSize::Small => ui_size(12. / 14.), + IconSize::Medium => ui_size(15. / 14.), }; - sized_svg + svg() + .size(svg_size) .flex_none() .path(self.icon.path()) .text_color(fill) diff --git a/crates/ui2/src/elements/label.rs b/crates/ui2/src/elements/label.rs index 5a34746f7bbb2947ca0810264c13e0b4a940ee2d..37cabc553490e3e70def4a014999bed779020e70 100644 --- a/crates/ui2/src/elements/label.rs +++ b/crates/ui2/src/elements/label.rs @@ -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 { state_type: PhantomData, label: SharedString, + line_height_style: LineHeightStyle, color: LabelColor, strikethrough: bool, } @@ -51,6 +60,7 @@ impl Label { Self { state_type: PhantomData, label: label.into(), + line_height_style: LineHeightStyle::default(), color: LabelColor::Default, strikethrough: false, } @@ -61,6 +71,11 @@ impl Label { 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 Label { ) }) .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()) } diff --git a/crates/ui2/src/settings.rs b/crates/ui2/src/settings.rs index a387b8ddd9200dd0e1aec316157642f5b7e66cd0..e91ff4a961cfdf1e5e04cfb01ffcd3e057849540 100644 --- a/crates/ui2/src/settings.rs +++ b/crates/ui2/src/settings.rs @@ -8,6 +8,7 @@ use crate::DisclosureControlStyle; pub fn user_settings() -> Settings { let mut settings = Settings::default(); settings.list_indent_depth = SettingValue::UserDefined(rems(0.5).into()); + // settings.ui_scale = SettingValue::UserDefined(2.); settings }