History

Update line heights, buttons to respond to UI scale

Nate Butler committed 3 years ago

Commit 7cb00ae1 parent 7b2782c6 files · +47 −13Browse files

Unified · Split

6 files
  1. crates/gpui3/src/styled.rs +12 −2
  2. crates/ui2/src/components/title_bar.rs +3 −2
  3. crates/ui2/src/elements/button.rs +4 −2
  4. crates/ui2/src/elements/icon.rs +8 −6
  5. crates/ui2/src/elements/label.rs +19 −1
  6. crates/ui2/src/settings.rs +1 −0
crates/gpui3/src/styled.rs+12−2
@@ -1,6 +1,6 @@
11 use crate::{
2− self as gpui3, hsla, point, px, relative, rems, AlignItems, Display, Fill, FlexDirection, Hsla,
3− JustifyContent, Length, Position, Rems, SharedString, StyleRefinement,
2+ self as gpui3, hsla, point, px, relative, rems, AlignItems, DefiniteLength, Display, Fill,
3+ FlexDirection, Hsla, JustifyContent, Length, Position, Rems, SharedString, StyleRefinement,
44 };
55 use crate::{BoxShadow, TextStyleRefinement};
66 use smallvec::smallvec;
@@ -529,4 +529,14 @@ pub trait Styled { · 522 unmodified lines
529529 .font_family = Some(family_name.into());
530530 self
531531 }
532+
533+ fn line_height(mut self, line_height: impl Into<DefiniteLength>) -> Self
534+ where
535+ Self: Sized,
536+ {
537+ self.text_style()
538+ .get_or_insert_with(Default::default)
539+ .line_height = Some(line_height.into());
540+ self
541+ }
532542 }
crates/ui2/src/components/title_bar.rs+3−2
@@ -112,6 +112,7 @@ impl TitleBar { · 111 unmodified lines
112112 .justify_between()
113113 .w_full()
114114 .bg(color.background)
115+ .py_1()
115116 .child(
116117 div()
117118 .flex()
@@ -132,7 +133,7 @@ impl TitleBar { · 14 unmodified lines
132133 .child(Button::new("zed"))
133134 .child(Button::new("nate/gpui2-ui-components")),
134135 )
135− .children(player_list.map(|p| PlayerStack::new(p)))
136+ // .children(player_list.map(|p| PlayerStack::new(p)))
136137 .child(IconButton::new(Icon::Plus)),
137138 )
138139 .child(
@@ -146,7 +147,7 @@ impl TitleBar { · 7 unmodified lines
146147 .items_center()
147148 .gap_1()
148149 .child(IconButton::new(Icon::FolderX))
149− .child(IconButton::new(Icon::Close)),
150+ .child(IconButton::new(Icon::Exit)),
150151 )
151152 .child(ToolDivider::new())
152153 .child(
crates/ui2/src/elements/button.rs+4−2
@@ -3,9 +3,9 @@ use std::sync::Arc; · 2 unmodified lines
33
44 use gpui3::{DefiniteLength, Hsla, Interactive, MouseButton, WindowContext};
55
6−use crate::prelude::*;
76 use crate::settings::user_settings;
87 use crate::{h_stack, Icon, IconColor, IconElement, Label, LabelColor};
8+use crate::{prelude::*, LineHeightStyle};
99
1010 #[derive(Default, PartialEq, Clone, Copy)]
1111 pub enum IconPosition {
@@ -137,7 +137,9 @@ impl<S: 'static + Send + Sync + Clone> Button<S> { · 125 unmodified lines
137137 }
138138
139139 fn render_label(&self) -> Label<S> {
140− Label::new(self.label.clone()).color(self.label_color())
140+ Label::new(self.label.clone())
141+ .color(self.label_color())
142+ .line_height_style(LineHeightStyle::UILabel)
141143 }
142144
143145 fn render_icon(&self, icon_color: IconColor) -> Option<IconElement<S>> {
crates/ui2/src/elements/icon.rs+8−6
@@ -11,7 +11,7 @@ use crate::theme::{theme, Theme}; · 10 unmodified lines
1111 pub enum IconSize {
1212 Small,
1313 #[default]
14− Large,
14+ Medium,
1515 }
1616
1717 #[derive(Default, PartialEq, Copy, Clone)]
@@ -58,6 +58,7 @@ pub enum Icon { · 40 unmodified lines
5858 ChevronRight,
5959 ChevronUp,
6060 Close,
61+ Exit,
6162 ExclamationTriangle,
6263 File,
6364 FileGeneric,
@@ -109,6 +110,7 @@ impl Icon { · 45 unmodified lines
109110 Icon::ChevronRight => "icons/chevron_right.svg",
110111 Icon::ChevronUp => "icons/chevron_up.svg",
111112 Icon::Close => "icons/x.svg",
113+ Icon::Exit => "icons/exit.svg",
112114 Icon::ExclamationTriangle => "icons/warning.svg",
113115 Icon::File => "icons/file.svg",
114116 Icon::FileGeneric => "icons/file_icons/file.svg",
@@ -177,13 +179,13 @@ impl<S: 'static + Send + Sync> IconElement<S> { · 62 unmodified lines
177179 fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
178180 let theme = theme(cx);
179181 let fill = self.color.color(theme);
180−
181− let sized_svg = match self.size {
182− IconSize::Small => svg().size_3p5(),
183− IconSize::Large => svg().size_4(),
182+ let svg_size = match self.size {
183+ IconSize::Small => ui_size(12. / 14.),
184+ IconSize::Medium => ui_size(15. / 14.),
184185 };
185186
186− sized_svg
187+ svg()
188+ .size(svg_size)
187189 .flex_none()
188190 .path(self.icon.path())
189191 .text_color(fill)
crates/ui2/src/elements/label.rs+19−1
@@ -1,6 +1,6 @@
11 use std::marker::PhantomData;
22
3−use gpui3::{Hsla, WindowContext};
3+use gpui3::{relative, Hsla, WindowContext};
44 use smallvec::SmallVec;
55
66 use crate::prelude::*;
@@ -38,10 +38,19 @@ impl LabelColor { · 31 unmodified lines
3838 }
3939 }
4040
41+#[derive(Default, PartialEq, Copy, Clone)]
42+pub enum LineHeightStyle {
43+ #[default]
44+ TextLabel,
45+ /// Sets the line height to 1
46+ UILabel,
47+}
48+
4149 #[derive(Element, Clone)]
4250 pub struct Label<S: 'static + Send + Sync + Clone> {
4351 state_type: PhantomData<S>,
4452 label: SharedString,
53+ line_height_style: LineHeightStyle,
4554 color: LabelColor,
4655 strikethrough: bool,
4756 }
@@ -51,6 +60,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> { · 3 unmodified lines
5160 Self {
5261 state_type: PhantomData,
5362 label: label.into(),
63+ line_height_style: LineHeightStyle::default(),
5464 color: LabelColor::Default,
5565 strikethrough: false,
5666 }
@@ -61,6 +71,11 @@ impl<S: 'static + Send + Sync + Clone> Label<S> { · 4 unmodified lines
6171 self
6272 }
6373
74+ pub fn line_height_style(mut self, line_height_style: LineHeightStyle) -> Self {
75+ self.line_height_style = line_height_style;
76+ self
77+ }
78+
6479 pub fn set_strikethrough(mut self, strikethrough: bool) -> Self {
6580 self.strikethrough = strikethrough;
6681 self
@@ -82,6 +97,9 @@ impl<S: 'static + Send + Sync + Clone> Label<S> { · 15 unmodified lines
8297 )
8398 })
8499 .text_size(ui_size(1.))
100+ .when(self.line_height_style == LineHeightStyle::UILabel, |this| {
101+ this.line_height(relative(1.))
102+ })
85103 .text_color(self.color.hsla(cx))
86104 .child(self.label.clone())
87105 }
crates/ui2/src/settings.rs+1−0
@@ -8,6 +8,7 @@ use crate::DisclosureControlStyle; · 7 unmodified lines
88 pub fn user_settings() -> Settings {
99 let mut settings = Settings::default();
1010 settings.list_indent_depth = SettingValue::UserDefined(rems(0.5).into());
11+ // settings.ui_scale = SettingValue::UserDefined(2.);
1112 settings
1213 }
1314

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t