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