egui_charts/ui/top_toolbar/config.rs
1//! Top toolbar dimensions and spacing.
2//!
3//! Use [`TopToolbarConfig`] to size controls; colors come from egui visuals and
4//! the active theme.
5
6// =============================================================================
7// Fixed Desktop Constants (exact dimensions)
8// =============================================================================
9
10/// Default top toolbar height in egui logical points.
11pub const TOOLBAR_HEIGHT: f32 = 38.0;
12
13/// Default button side length in egui logical points.
14pub const BUTTON_SIZE: f32 = 34.0;
15
16/// Default icon side length in egui logical points.
17pub const ICON_SIZE: f32 = 24.0;
18
19/// Default padding in egui logical points.
20pub const PADDING: f32 = 4.0;
21
22/// Default corner radius in egui logical points.
23pub const ROUNDING: f32 = 4.0;
24
25// =============================================================================
26// Config Struct
27// =============================================================================
28
29/// Dimensions for the top toolbar in egui logical points.
30#[derive(Clone, Debug)]
31pub struct TopToolbarConfig {
32 /// Toolbar height.
33 pub height: f32,
34 /// Icon side length.
35 pub small_icon_size: f32,
36 /// Button side length.
37 pub btn_size: f32,
38 /// Padding between button content.
39 pub padding: f32,
40 /// Button corner radius.
41 pub rounding: f32,
42 // Legacy fields kept for compatibility
43 /// Retained for source compatibility; rendering uses `height`.
44 pub base_height: f32,
45 /// Retained for source compatibility; rendering uses `small_icon_size`.
46 pub base_icon_size: f32,
47 /// Retained for source compatibility; rendering uses `btn_size`.
48 pub base_btn_size: f32,
49 /// Retained for source compatibility; rendering uses `padding`.
50 pub base_padding: f32,
51}
52
53impl Default for TopToolbarConfig {
54 fn default() -> Self {
55 Self {
56 // Fixed desktop values
57 height: TOOLBAR_HEIGHT,
58 small_icon_size: ICON_SIZE,
59 btn_size: BUTTON_SIZE,
60 padding: PADDING,
61 rounding: ROUNDING,
62 // Legacy fields (same as primary values)
63 base_height: TOOLBAR_HEIGHT,
64 base_icon_size: ICON_SIZE,
65 base_btn_size: BUTTON_SIZE,
66 base_padding: PADDING,
67 }
68 }
69}
70
71impl TopToolbarConfig {
72 /// Create new config with defaults
73 pub fn new() -> Self {
74 Self::default()
75 }
76
77 /// Builder: set toolbar height
78 pub fn with_height(mut self, height: f32) -> Self {
79 self.height = height;
80 self.base_height = height;
81 self
82 }
83
84 /// Builder: set icon size
85 pub fn with_icon_size(mut self, size: f32) -> Self {
86 self.small_icon_size = size;
87 self.base_icon_size = size;
88 self
89 }
90
91 /// Builder: set button size
92 pub fn with_button_size(mut self, size: f32) -> Self {
93 self.btn_size = size;
94 self.base_btn_size = size;
95 self
96 }
97}