spacing.rs

 1use gpui::{App, Pixels, Rems, px, rems};
 2use theme::UiDensity;
 3use ui_macros::derive_dynamic_spacing;
 4
 5// Derives [DynamicSpacing]. See [ui_macros::derive_dynamic_spacing].
 6//
 7// There are 3 UI density settings: Compact, Default, and Comfortable.
 8//
 9// When a tuple of three values is provided, the values are used directly.
10//
11// Example: (1, 2, 4) => Compact: 1px, Default: 2px, Comfortable: 4px
12//
13// When a single value is provided, the standard spacing formula is
14// used to derive the of spacing values. This formula can be found in
15// the macro.
16//
17// Example:
18//
19// Assuming the standard formula is (n-4, n, n+4)
20//
21// 24 => Compact: 20px, Default: 24px, Comfortable: 28px
22//
23// The [DynamicSpacing] enum variants use a BaseXX format,
24// where XX = the pixel value @ default rem size and the default UI density.
25//
26// Example:
27//
28// DynamicSpacing::Base16 would return 16px at the default UI scale & density.
29derive_dynamic_spacing![
30    (0, 0, 0),
31    (1, 1, 2),
32    (1, 2, 4),
33    (2, 3, 4),
34    (2, 4, 6),
35    (3, 6, 8),
36    (4, 8, 10),
37    (10, 12, 14),
38    (14, 16, 18),
39    (18, 20, 22),
40    24,
41    32,
42    40,
43    48
44];
45
46/// Returns the current [`UiDensity`] setting. Use this to
47/// modify or show something in the UI other than spacing.
48///
49/// Do not use this to calculate spacing values.
50///
51/// Always use [DynamicSpacing] for spacing values.
52pub fn ui_density(cx: &mut App) -> UiDensity {
53    theme::theme_settings(cx).ui_density(cx)
54}