Use ui_size to set relative font sizes

Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler
2023-10-18 17:02:57 -04:00
co-authored by Marshall Bowers
parent 3f076eeda6
commit 7b2782c0f6
5 changed files with 31 additions and 81 deletions
+3 -13
View File
@@ -5,9 +5,7 @@ use gpui3::{div, Div};
use crate::prelude::*; use crate::prelude::*;
use crate::settings::user_settings; use crate::settings::user_settings;
use crate::theme::theme; use crate::theme::theme;
use crate::{ use crate::{h_stack, v_stack, Avatar, Icon, IconColor, IconElement, IconSize, Label, LabelColor};
h_stack, v_stack, Avatar, Icon, IconColor, IconElement, IconSize, Label, LabelColor, LabelSize,
};
#[derive(Clone, Copy, Default, Debug, PartialEq)] #[derive(Clone, Copy, Default, Debug, PartialEq)]
pub enum ListItemVariant { pub enum ListItemVariant {
@@ -129,11 +127,7 @@ impl<S: 'static + Send + Sync + Clone> ListHeader<S> {
.color(IconColor::Muted) .color(IconColor::Muted)
.size(IconSize::Small) .size(IconSize::Small)
})) }))
.child( .child(Label::new(self.label.clone()).color(LabelColor::Muted)),
Label::new(self.label.clone())
.color(LabelColor::Muted)
.size(LabelSize::Small),
),
) )
.child(disclosure_control), .child(disclosure_control),
) )
@@ -186,11 +180,7 @@ impl<S: 'static + Send + Sync + Clone> ListSubHeader<S> {
.color(IconColor::Muted) .color(IconColor::Muted)
.size(IconSize::Small) .size(IconSize::Small)
})) }))
.child( .child(Label::new(self.label.clone()).color(LabelColor::Muted)),
Label::new(self.label.clone())
.color(LabelColor::Muted)
.size(LabelSize::Small),
),
), ),
) )
} }
+2 -2
View File
@@ -1,7 +1,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::prelude::*; use crate::prelude::*;
use crate::{v_stack, Buffer, Icon, IconButton, Label, LabelSize}; use crate::{v_stack, Buffer, Icon, IconButton, Label};
#[derive(Element)] #[derive(Element)]
pub struct MultiBuffer<S: 'static + Send + Sync + Clone> { pub struct MultiBuffer<S: 'static + Send + Sync + Clone> {
@@ -33,7 +33,7 @@ impl<S: 'static + Send + Sync + Clone> MultiBuffer<S> {
.justify_between() .justify_between()
.p_4() .p_4()
.bg(theme.lowest.base.default.background) .bg(theme.lowest.base.default.background)
.child(Label::new("main.rs").size(LabelSize::Small)) .child(Label::new("main.rs"))
.child(IconButton::new(Icon::ArrowUpRight)), .child(IconButton::new(Icon::ArrowUpRight)),
) )
.child(buffer) .child(buffer)
+13 -33
View File
@@ -5,7 +5,7 @@ use gpui3::{DefiniteLength, Hsla, Interactive, MouseButton, WindowContext};
use crate::prelude::*; use crate::prelude::*;
use crate::settings::user_settings; use crate::settings::user_settings;
use crate::{h_stack, Icon, IconColor, IconElement, Label, LabelColor, LabelSize}; use crate::{h_stack, Icon, IconColor, IconElement, Label, LabelColor};
#[derive(Default, PartialEq, Clone, Copy)] #[derive(Default, PartialEq, Clone, Copy)]
pub enum IconPosition { pub enum IconPosition {
@@ -137,9 +137,7 @@ impl<S: 'static + Send + Sync + Clone> Button<S> {
} }
fn render_label(&self) -> Label<S> { fn render_label(&self) -> Label<S> {
Label::new(self.label.clone()) Label::new(self.label.clone()).color(self.label_color())
.size(LabelSize::Small)
.color(self.label_color())
} }
fn render_icon(&self, icon_color: IconColor) -> Option<IconElement<S>> { fn render_icon(&self, icon_color: IconColor) -> Option<IconElement<S>> {
@@ -153,7 +151,7 @@ impl<S: 'static + Send + Sync + Clone> Button<S> {
let mut el = h_stack() let mut el = h_stack()
.p_1() .p_1()
.text_size(ui_size(1.125)) .text_size(ui_size(1.))
.rounded_md() .rounded_md()
.border() .border()
.border_color(border_color) .border_color(border_color)
@@ -205,7 +203,7 @@ mod stories {
use gpui3::rems; use gpui3::rems;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use crate::{h_stack, v_stack, LabelColor, LabelSize, Story}; use crate::{h_stack, v_stack, LabelColor, Story};
use super::*; use super::*;
@@ -241,9 +239,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -256,9 +252,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -273,9 +267,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -293,9 +285,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -308,9 +298,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -325,9 +313,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -345,9 +331,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -361,9 +345,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
@@ -379,9 +361,7 @@ mod stories {
v_stack() v_stack()
.gap_1() .gap_1()
.child( .child(
Label::new(state.to_string()) Label::new(state.to_string()).color(LabelColor::Muted),
.color(LabelColor::Muted)
.size(LabelSize::Small),
) )
.child( .child(
Button::new("Label") Button::new("Label")
+5 -32
View File
@@ -38,19 +38,11 @@ impl LabelColor {
} }
} }
#[derive(Default, PartialEq, Copy, Clone)]
pub enum LabelSize {
#[default]
Default,
Small,
}
#[derive(Element, Clone)] #[derive(Element, Clone)]
pub struct Label<S: 'static + Send + Sync + Clone> { pub struct Label<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
color: LabelColor, color: LabelColor,
size: LabelSize,
strikethrough: bool, strikethrough: bool,
} }
@@ -60,7 +52,6 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
state_type: PhantomData, state_type: PhantomData,
label: label.into(), label: label.into(),
color: LabelColor::Default, color: LabelColor::Default,
size: LabelSize::Default,
strikethrough: false, strikethrough: false,
} }
} }
@@ -70,11 +61,6 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
self self
} }
pub fn size(mut self, size: LabelSize) -> Self {
self.size = size;
self
}
pub fn set_strikethrough(mut self, strikethrough: bool) -> Self { pub fn set_strikethrough(mut self, strikethrough: bool) -> Self {
self.strikethrough = strikethrough; self.strikethrough = strikethrough;
self self
@@ -95,6 +81,7 @@ impl<S: 'static + Send + Sync + Clone> Label<S> {
.bg(LabelColor::Hidden.hsla(cx)), .bg(LabelColor::Hidden.hsla(cx)),
) )
}) })
.text_size(ui_size(1.))
.text_color(self.color.hsla(cx)) .text_color(self.color.hsla(cx))
.child(self.label.clone()) .child(self.label.clone())
} }
@@ -105,7 +92,6 @@ pub struct HighlightedLabel<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>, state_type: PhantomData<S>,
label: SharedString, label: SharedString,
color: LabelColor, color: LabelColor,
size: LabelSize,
highlight_indices: Vec<usize>, highlight_indices: Vec<usize>,
strikethrough: bool, strikethrough: bool,
} }
@@ -116,7 +102,6 @@ impl<S: 'static + Send + Sync + Clone> HighlightedLabel<S> {
state_type: PhantomData, state_type: PhantomData,
label: label.into(), label: label.into(),
color: LabelColor::Default, color: LabelColor::Default,
size: LabelSize::Default,
highlight_indices, highlight_indices,
strikethrough: false, strikethrough: false,
} }
@@ -127,11 +112,6 @@ impl<S: 'static + Send + Sync + Clone> HighlightedLabel<S> {
self self
} }
pub fn size(mut self, size: LabelSize) -> Self {
self.size = size;
self
}
pub fn set_strikethrough(mut self, strikethrough: bool) -> Self { pub fn set_strikethrough(mut self, strikethrough: bool) -> Self {
self.strikethrough = strikethrough; self.strikethrough = strikethrough;
self self
@@ -191,17 +171,10 @@ impl<S: 'static + Send + Sync + Clone> HighlightedLabel<S> {
.bg(LabelColor::Hidden.hsla(cx)), .bg(LabelColor::Hidden.hsla(cx)),
) )
}) })
.children(runs.into_iter().map(|run| { .children(
let mut div = div(); runs.into_iter()
.map(|run| div().text_color(run.color).child(run.text)),
if self.size == LabelSize::Small { )
div = div.text_xs();
} else {
div = div.text_sm();
}
div.text_color(run.color).child(run.text)
}))
} }
} }
+8 -1
View File
@@ -158,9 +158,16 @@ impl HighlightColor {
} }
pub fn ui_size(size: f32) -> Rems { pub fn ui_size(size: f32) -> Rems {
const UI_SCALE_RATIO: f32 = 0.875;
let setting = user_settings(); let setting = user_settings();
rems(*setting.ui_scale * size) let rems = rems(*setting.ui_scale * UI_SCALE_RATIO * size);
let px = rems * 16.0;
dbg!(rems, rems * 16.0);
rems
} }
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]