gpui_kit_material/tokens/
layout.rs1use super::typography::rem;
3use gpui::{Pixels, Rems, Window, px};
4
5pub const CONTROL_HEIGHT: Rems = rem(40.);
7pub const ITEM_INSET: Rems = rem(20.);
9pub const ICON_SLOT: Rems = rem(20.);
11pub const ICON_GAP: Rems = rem(8.);
12pub const LABEL_INSET: Rems = rem(20. + 8.);
14pub const SECTION_TITLE_SPACE: Rems = rem(10.);
17pub const SECTION_TITLE_GAP: Pixels = px(10.);
20pub const APP_BAR_BLOCK_PADDING: Rems = rem(8.);
22
23pub const COMPACT_WINDOW: f32 = 960.;
26
27pub fn design_width(window: &Window) -> f32 {
29 f32::from(window.bounds().size.width) * super::typography::BASE_PX
30 / f32::from(window.rem_size())
31}
32
33pub fn is_compact(window: &Window) -> bool {
34 design_width(window) < COMPACT_WINDOW
35}
36
37pub fn app_bar_height(window: &Window) -> Pixels {
40 app_bar_height_at(window.rem_size())
41}
42
43fn app_bar_height_at(rem_size: Pixels) -> Pixels {
44 (CONTROL_HEIGHT + APP_BAR_BLOCK_PADDING * 2.).to_pixels(rem_size)
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn app_bar_height_follows_the_text_scale() {
53 assert_eq!(app_bar_height_at(px(14.)), px(56.));
54 assert_eq!(app_bar_height_at(px(21.)), px(84.));
55 }
56
57 #[test]
58 fn section_title_space_matches_the_legacy_gap_at_100_percent() {
59 assert_eq!(SECTION_TITLE_SPACE.to_pixels(px(14.)), SECTION_TITLE_GAP);
60 }
61}