Replace rem size literals with constant (#11272)
This PR replaces the rem size literals with the `BASE_REM_SIZE_IN_PX` constant. This way we can retain our source of truth for the rem size that we're designing against. Release Notes: - N/A
This commit is contained in:
parent
a194c0aa6e
commit
4f5312804d
1 changed files with 28 additions and 28 deletions
|
@ -1,7 +1,9 @@
|
||||||
use gpui::*;
|
use gpui::{px, rems, Pixels, Rems, WindowContext};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
use theme::{ThemeSettings, UiDensity};
|
use theme::{ThemeSettings, UiDensity};
|
||||||
|
|
||||||
|
use crate::{rems_from_px, BASE_REM_SIZE_IN_PX};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum Spacing {
|
pub enum Spacing {
|
||||||
/// No spacing
|
/// No spacing
|
||||||
|
@ -33,36 +35,34 @@ impl Spacing {
|
||||||
pub fn spacing_ratio(self, cx: &WindowContext) -> f32 {
|
pub fn spacing_ratio(self, cx: &WindowContext) -> f32 {
|
||||||
match ThemeSettings::get_global(cx).ui_density {
|
match ThemeSettings::get_global(cx).ui_density {
|
||||||
UiDensity::Compact => match self {
|
UiDensity::Compact => match self {
|
||||||
Spacing::None => 0.0,
|
Spacing::None => 0.,
|
||||||
Spacing::XXSmall => 1. / 16.,
|
Spacing::XXSmall => 1. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XSmall => 1. / 16.,
|
Spacing::XSmall => 1. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Small => 2. / 16.,
|
Spacing::Small => 2. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Medium => 3. / 16.,
|
Spacing::Medium => 3. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Large => 4. / 16.,
|
Spacing::Large => 4. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XLarge => 8. / 16.,
|
Spacing::XLarge => 8. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XXLarge => 12. / 16.,
|
Spacing::XXLarge => 12. / BASE_REM_SIZE_IN_PX,
|
||||||
},
|
},
|
||||||
UiDensity::Default => match self {
|
UiDensity::Default => match self {
|
||||||
Spacing::None => 0.0,
|
Spacing::None => 0.,
|
||||||
Spacing::XXSmall => 1. / 16.,
|
Spacing::XXSmall => 1. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XSmall => 2. / 16.,
|
Spacing::XSmall => 2. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Small => 4. / 16.,
|
Spacing::Small => 4. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Medium => 6. / 16.,
|
Spacing::Medium => 6. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Large => 8. / 16.,
|
Spacing::Large => 8. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XLarge => 12. / 16.,
|
Spacing::XLarge => 12. / BASE_REM_SIZE_IN_PX,
|
||||||
#[allow(clippy::eq_op)]
|
Spacing::XXLarge => 16. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XXLarge => 16. / 16.,
|
|
||||||
},
|
},
|
||||||
UiDensity::Comfortable => match self {
|
UiDensity::Comfortable => match self {
|
||||||
Spacing::None => 0.0,
|
Spacing::None => 0.,
|
||||||
Spacing::XXSmall => 2. / 16.,
|
Spacing::XXSmall => 2. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XSmall => 3. / 16.,
|
Spacing::XSmall => 3. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Small => 6. / 16.,
|
Spacing::Small => 6. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Medium => 8. / 16.,
|
Spacing::Medium => 8. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::Large => 10. / 16.,
|
Spacing::Large => 10. / BASE_REM_SIZE_IN_PX,
|
||||||
#[allow(clippy::eq_op)]
|
Spacing::XLarge => 16. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XLarge => 16. / 16.,
|
Spacing::XXLarge => 20. / BASE_REM_SIZE_IN_PX,
|
||||||
Spacing::XXLarge => 20. / 16.,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,5 +83,5 @@ pub fn user_spacing_style(cx: &WindowContext) -> UiDensity {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn custom_spacing(cx: &WindowContext, size: f32) -> Rems {
|
pub fn custom_spacing(cx: &WindowContext, size: f32) -> Rems {
|
||||||
crate::rems_from_px(size * user_spacing_style(cx).spacing_ratio())
|
rems_from_px(size * user_spacing_style(cx).spacing_ratio())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue