Skip to main content

egui_charts/styles/
typography.rs

1//! Typography constants - font sizes
2//!
3//! Consistent text sizing across the UI.
4
5/// The font sizes in points that text is drawn at. The glyph rasterizer fails on larger text, and
6/// its memory grows with the square of the size; the drawing properties editor offers 8 to 32
7/// and glyphs 8 to 128.
8pub(crate) const FONT_SIZES: std::ops::RangeInclusive<f32> = 1.0..=256.0;
9
10/// `size` within [`FONT_SIZES`], with NaN at the smallest size.
11pub(crate) fn font_size(size: f32) -> f32 {
12    size.max(*FONT_SIZES.start()).min(*FONT_SIZES.end())
13}
14
15// =============================================================================
16// Font Size Scale
17// =============================================================================
18
19/// Micro text (8px) - badges, tiny labels
20pub const MICRO: f32 = 8.0;
21
22/// Tiny text (9px) - very small labels, markers
23pub const TINY: f32 = 9.0;
24
25/// Extra small text (10px) - labels, hints
26pub const XS: f32 = 10.0;
27
28/// Small text (11px) - secondary labels
29pub const SM: f32 = 11.0;
30
31/// Small-medium text (12px) - compact body text
32pub const SM_MD: f32 = 12.0;
33
34/// Medium text (13px) - body text, btns
35pub const MD: f32 = 13.0;
36
37/// Large text (14px) - emphasized text
38pub const LG: f32 = 14.0;
39
40/// Extra large text (15px) - headings
41pub const XL: f32 = 15.0;
42
43/// 2X large text (16px) - section titles
44pub const XXL: f32 = 16.0;
45
46/// Title text (18px) - dialog titles, large headings
47pub const TITLE: f32 = 18.0;
48
49/// Display text (20px) - large display elements
50pub const DISPLAY: f32 = 20.0;
51
52/// Hero text (22px) - hero/large display
53pub const HERO: f32 = 22.0;
54
55// =============================================================================
56// Semantic Aliases
57// =============================================================================
58
59/// In-pane chart title font size
60pub const CHART_TITLE: f32 = XXL;
61
62/// Toolbar label font size
63pub const TOOLBAR: f32 = LG;
64
65/// OHLC and supplementary legend row font size
66pub const OHLC: f32 = MD;
67
68/// Price and time axis label font size
69pub const AXIS: f32 = SM_MD;
70
71/// Price tag font size
72pub const PRICE_TAG: f32 = SM_MD;
73
74/// Bottom range and status bar font size
75pub const BOTTOM_BAR: f32 = LG;
76
77/// Button label font size
78pub const BUTTON: f32 = MD;
79
80/// Menu item font size
81pub const MENU_ITEM: f32 = LG;
82
83/// Tooltip font size
84pub const TOOLTIP: f32 = SM;
85
86/// Input field font size
87pub const INPUT: f32 = MD;
88
89/// Label font size
90pub const LABEL: f32 = SM;
91
92/// Symbol/ticker font size
93pub const SYMBOL: f32 = LG;
94
95/// Badge font size
96pub const BADGE: f32 = MICRO;
97
98/// Marker/annotation font size
99pub const MARKER: f32 = TINY;
100
101/// Compact text font size
102pub const COMPACT: f32 = SM_MD;
103
104/// Dialog title font size
105pub const DIALOG_TITLE: f32 = TITLE;
106
107/// Emoji display font size
108pub const EMOJI: f32 = DISPLAY;
109
110/// Large emoji display font size
111pub const EMOJI_ICON: f32 = HERO;
112
113/// Extra large icon font size (48px) - success/status icons
114pub const ICON_HERO: f32 = 48.0;