libsurfer/
state_util.rs

1//! Utility functions, typically inlined, for more readable code
2
3use ecolor::Color32;
4use egui::Modifiers;
5
6use crate::{config::PrimaryMouseDrag, displayed_item::DisplayedItem, SystemState};
7
8impl SystemState {
9    #[inline]
10    pub fn get_item_text_color(&self, item: &DisplayedItem) -> &Color32 {
11        item.color()
12            .and_then(|color| self.user.config.theme.get_color(color))
13            .unwrap_or(&self.user.config.theme.primary_ui_color.foreground)
14    }
15
16    #[inline]
17    pub fn show_statusbar(&self) -> bool {
18        self.user.show_statusbar.unwrap_or_else(|| {
19            (self.user.waves.is_some() || self.progress_tracker.is_some())
20                && self.user.config.layout.show_statusbar()
21        })
22    }
23
24    #[inline]
25    pub fn show_toolbar(&self) -> bool {
26        self.user
27            .show_toolbar
28            .unwrap_or_else(|| self.user.config.layout.show_toolbar())
29    }
30
31    #[inline]
32    pub fn show_overview(&self) -> bool {
33        self.user
34            .show_overview
35            .unwrap_or_else(|| self.user.config.layout.show_overview())
36    }
37
38    #[inline]
39    pub fn show_hierarchy(&self) -> bool {
40        self.user
41            .show_hierarchy
42            .unwrap_or_else(|| self.user.config.layout.show_hierarchy())
43    }
44
45    #[inline]
46    pub fn show_tooltip(&self) -> bool {
47        self.user
48            .show_tooltip
49            .unwrap_or_else(|| self.user.config.layout.show_tooltip())
50    }
51
52    #[inline]
53    pub fn show_scope_tooltip(&self) -> bool {
54        self.user
55            .show_scope_tooltip
56            .unwrap_or_else(|| self.user.config.layout.show_scope_tooltip())
57    }
58
59    #[inline]
60    pub fn show_ticks(&self) -> bool {
61        self.user
62            .show_ticks
63            .unwrap_or_else(|| self.user.config.layout.show_ticks())
64    }
65
66    #[inline]
67    pub fn show_menu(&self) -> bool {
68        self.user
69            .show_menu
70            .unwrap_or_else(|| self.user.config.layout.show_menu())
71    }
72
73    #[inline]
74    pub fn show_variable_indices(&self) -> bool {
75        self.user
76            .show_variable_indices
77            .unwrap_or_else(|| self.user.config.layout.show_variable_indices())
78    }
79
80    #[inline]
81    pub fn show_variable_direction(&self) -> bool {
82        self.user
83            .show_variable_direction
84            .unwrap_or_else(|| self.user.config.layout.show_variable_direction())
85    }
86
87    #[inline]
88    pub fn ui_zoom_factor(&self) -> f32 {
89        self.user
90            .ui_zoom_factor
91            .unwrap_or_else(|| self.user.config.layout.default_zoom_factor())
92    }
93
94    #[inline]
95    pub fn show_empty_scopes(&self) -> bool {
96        self.user
97            .show_empty_scopes
98            .unwrap_or_else(|| self.user.config.layout.show_empty_scopes())
99    }
100
101    #[inline]
102    pub fn show_parameters_in_scopes(&self) -> bool {
103        self.user
104            .show_parameters_in_scopes
105            .unwrap_or_else(|| self.user.config.layout.show_parameters_in_scopes())
106    }
107
108    #[inline]
109    pub fn show_default_timeline(&self) -> bool {
110        self.user
111            .show_default_timeline
112            .unwrap_or_else(|| self.user.config.layout.show_default_timeline())
113    }
114
115    #[inline]
116    pub fn highlight_focused(&self) -> bool {
117        self.user
118            .highlight_focused
119            .unwrap_or_else(|| self.user.config.layout.highlight_focused())
120    }
121
122    #[inline]
123    pub fn fill_high_values(&self) -> bool {
124        self.user
125            .fill_high_values
126            .unwrap_or_else(|| self.user.config.layout.fill_high_values())
127    }
128
129    #[inline]
130    pub fn primary_button_drag_behavior(&self) -> PrimaryMouseDrag {
131        self.user
132            .primary_button_drag_behavior
133            .unwrap_or_else(|| self.user.config.behavior.primary_button_drag_behavior())
134    }
135
136    #[inline]
137    /// Return true if the combination of `primary_button_drag_behavior` and
138    /// `modifiers` results in a measure, false otherwise.
139    pub fn do_measure(&self, modifiers: &Modifiers) -> bool {
140        let drag_behavior = self.primary_button_drag_behavior();
141        (drag_behavior == PrimaryMouseDrag::Measure && !modifiers.shift)
142            || (drag_behavior == PrimaryMouseDrag::Cursor && modifiers.shift)
143    }
144}