libsurfer/
state_util.rs

1//! Utility functions, typically inlined, for more readable code
2
3use ecolor::Color32;
4use egui::Modifiers;
5
6use crate::{
7    clock_highlighting::ClockHighlightType,
8    config::{ArrowKeyBindings, AutoLoad, PrimaryMouseDrag},
9    displayed_item::DisplayedItem,
10    hierarchy::HierarchyStyle,
11    SystemState,
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_parameters_in_scopes(&self) -> bool {
109        self.user
110            .show_parameters_in_scopes
111            .unwrap_or_else(|| self.user.config.layout.show_parameters_in_scopes())
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 primary_button_drag_behavior(&self) -> PrimaryMouseDrag {
137        self.user
138            .primary_button_drag_behavior
139            .unwrap_or_else(|| self.user.config.behavior.primary_button_drag_behavior())
140    }
141
142    #[inline]
143    /// Return true if the combination of `primary_button_drag_behavior` and
144    /// `modifiers` results in a measure, false otherwise.
145    pub fn do_measure(&self, modifiers: &Modifiers) -> bool {
146        let drag_behavior = self.primary_button_drag_behavior();
147        (drag_behavior == PrimaryMouseDrag::Measure && !modifiers.shift)
148            || (drag_behavior == PrimaryMouseDrag::Cursor && modifiers.shift)
149    }
150
151    #[inline]
152    pub fn arrow_key_bindings(&self) -> ArrowKeyBindings {
153        self.user
154            .arrow_key_bindings
155            .unwrap_or_else(|| self.user.config.behavior.arrow_key_bindings())
156    }
157
158    #[inline]
159    pub fn clock_highlight_type(&self) -> ClockHighlightType {
160        self.user
161            .clock_highlight_type
162            .unwrap_or_else(|| self.user.config.default_clock_highlight_type())
163    }
164
165    #[inline]
166    pub fn hierarchy_style(&self) -> HierarchyStyle {
167        self.user
168            .hierarchy_style
169            .unwrap_or_else(|| self.user.config.layout.hierarchy_style())
170    }
171
172    #[inline]
173    pub fn autoreload_files(&self) -> AutoLoad {
174        self.user
175            .autoreload_files
176            .unwrap_or_else(|| self.user.config.autoreload_files())
177    }
178
179    #[inline]
180    pub fn autoload_sibling_state_files(&self) -> AutoLoad {
181        self.user
182            .autoload_sibling_state_files
183            .unwrap_or_else(|| self.user.config.autoload_sibling_state_files())
184    }
185}