Skip to main content

libsurfer/
state_util.rs

1//! Utility functions, typically inlined, for more readable code
2
3use ecolor::Color32;
4use egui::Modifiers;
5
6use crate::{
7    SystemState,
8    clock_highlighting::ClockHighlightType,
9    config::{ArrowKeyBindings, AutoLoad, PrimaryMouseDrag, TransitionValue},
10    displayed_item::DisplayedItem,
11    hierarchy::{HierarchyStyle, ParameterDisplayLocation},
12};
13
14impl SystemState {
15    #[inline]
16    pub fn get_item_text_color(&self, item: &DisplayedItem) -> Color32 {
17        item.color()
18            .and_then(|color| self.user.config.theme.get_color(color))
19            .unwrap_or(self.user.config.theme.primary_ui_color.foreground)
20    }
21
22    #[inline]
23    pub fn show_statusbar(&self) -> bool {
24        self.user.show_statusbar.unwrap_or_else(|| {
25            (self.user.waves.is_some() || self.progress_tracker.is_some())
26                && self.user.config.layout.show_statusbar()
27        })
28    }
29
30    #[inline]
31    pub fn show_toolbar(&self) -> bool {
32        self.user
33            .show_toolbar
34            .unwrap_or_else(|| self.user.config.layout.show_toolbar())
35    }
36
37    #[inline]
38    pub fn show_overview(&self) -> bool {
39        self.user
40            .show_overview
41            .unwrap_or_else(|| self.user.config.layout.show_overview())
42    }
43
44    #[inline]
45    pub fn show_hierarchy(&self) -> bool {
46        self.user
47            .show_hierarchy
48            .unwrap_or_else(|| self.user.config.layout.show_hierarchy())
49    }
50
51    #[inline]
52    pub fn show_tooltip(&self) -> bool {
53        self.user
54            .show_tooltip
55            .unwrap_or_else(|| self.user.config.layout.show_tooltip())
56    }
57
58    #[inline]
59    pub fn show_scope_tooltip(&self) -> bool {
60        self.user
61            .show_scope_tooltip
62            .unwrap_or_else(|| self.user.config.layout.show_scope_tooltip())
63    }
64
65    #[inline]
66    pub fn show_ticks(&self) -> bool {
67        self.user
68            .show_ticks
69            .unwrap_or_else(|| self.user.config.layout.show_ticks())
70    }
71
72    #[inline]
73    pub fn show_menu(&self) -> bool {
74        self.user
75            .show_menu
76            .unwrap_or_else(|| self.user.config.layout.show_menu())
77    }
78
79    #[inline]
80    pub fn show_variable_indices(&self) -> bool {
81        self.user
82            .show_variable_indices
83            .unwrap_or_else(|| self.user.config.layout.show_variable_indices())
84    }
85
86    #[inline]
87    pub fn show_variable_direction(&self) -> bool {
88        self.user
89            .show_variable_direction
90            .unwrap_or_else(|| self.user.config.layout.show_variable_direction())
91    }
92
93    #[inline]
94    pub fn ui_zoom_factor(&self) -> f32 {
95        self.user
96            .ui_zoom_factor
97            .unwrap_or_else(|| self.user.config.layout.default_zoom_factor())
98    }
99
100    #[inline]
101    pub fn show_empty_scopes(&self) -> bool {
102        self.user
103            .show_empty_scopes
104            .unwrap_or_else(|| self.user.config.layout.show_empty_scopes())
105    }
106
107    #[inline]
108    pub fn show_hierarchy_icons(&self) -> bool {
109        self.user
110            .show_hierarchy_icons
111            .unwrap_or_else(|| self.user.config.layout.show_hierarchy_icons())
112    }
113
114    #[inline]
115    pub fn show_default_timeline(&self) -> bool {
116        self.user
117            .show_default_timeline
118            .unwrap_or_else(|| self.user.config.layout.show_default_timeline())
119    }
120
121    #[inline]
122    pub fn highlight_focused(&self) -> bool {
123        self.user
124            .highlight_focused
125            .unwrap_or_else(|| self.user.config.layout.highlight_focused())
126    }
127
128    #[inline]
129    pub fn fill_high_values(&self) -> bool {
130        self.user
131            .fill_high_values
132            .unwrap_or_else(|| self.user.config.layout.fill_high_values())
133    }
134
135    #[inline]
136    pub fn animation_enabled(&self) -> bool {
137        self.user
138            .animation_enabled
139            .unwrap_or_else(|| self.user.config.animation_enabled())
140    }
141
142    #[inline]
143    pub fn show_divider_text(&self) -> bool {
144        self.user.config.show_divider_text()
145    }
146
147    #[inline]
148    pub fn primary_button_drag_behavior(&self) -> PrimaryMouseDrag {
149        self.user
150            .primary_button_drag_behavior
151            .unwrap_or_else(|| self.user.config.behavior.primary_button_drag_behavior())
152    }
153
154    #[inline]
155    /// Return true if the combination of `primary_button_drag_behavior` and
156    /// `modifiers` results in a measure, false otherwise.
157    pub fn do_measure(&self, modifiers: &Modifiers) -> bool {
158        let drag_behavior = self.primary_button_drag_behavior();
159        (drag_behavior == PrimaryMouseDrag::Measure && !modifiers.shift)
160            || (drag_behavior == PrimaryMouseDrag::Cursor && modifiers.shift)
161    }
162
163    #[inline]
164    pub fn arrow_key_bindings(&self) -> ArrowKeyBindings {
165        self.user
166            .arrow_key_bindings
167            .unwrap_or_else(|| self.user.config.behavior.arrow_key_bindings())
168    }
169
170    #[inline]
171    pub fn clock_highlight_type(&self) -> ClockHighlightType {
172        self.user
173            .clock_highlight_type
174            .unwrap_or_else(|| self.user.config.default_clock_highlight_type())
175    }
176
177    #[inline]
178    pub fn hierarchy_style(&self) -> HierarchyStyle {
179        self.user
180            .hierarchy_style
181            .unwrap_or_else(|| self.user.config.layout.hierarchy_style())
182    }
183
184    #[inline]
185    pub fn autoreload_files(&self) -> AutoLoad {
186        self.user
187            .autoreload_files
188            .unwrap_or_else(|| self.user.config.autoreload_files())
189    }
190
191    #[inline]
192    pub fn autoload_sibling_state_files(&self) -> AutoLoad {
193        self.user
194            .autoload_sibling_state_files
195            .unwrap_or_else(|| self.user.config.autoload_sibling_state_files())
196    }
197
198    #[inline]
199    pub fn parameter_display_location(&self) -> ParameterDisplayLocation {
200        self.user
201            .parameter_display_location
202            .unwrap_or_else(|| self.user.config.layout.parameter_display_location())
203    }
204
205    #[inline]
206    pub fn use_dinotrace_style(&self) -> bool {
207        self.user
208            .use_dinotrace_style
209            .unwrap_or_else(|| self.user.config.layout.use_dinotrace_style())
210    }
211
212    #[inline]
213    pub fn transition_value(&self) -> TransitionValue {
214        self.user
215            .transition_value
216            .unwrap_or_else(|| self.user.config.layout.transition_value())
217    }
218
219    #[inline]
220    pub fn align_names_right(&self) -> bool {
221        self.user
222            .align_names_right
223            .unwrap_or_else(|| self.user.config.layout.align_names_right())
224    }
225}