Skip to main content

egui_charts/ui/dialogs/indicator_dialog/
config.rs

1//! Study browser layout dimensions.
2//!
3//! Use [`IndicatorDialogConfig`] when the host needs to override the dialog size.
4
5use crate::theme::Theme;
6use egui::Color32;
7
8/// Configuration for the indicator dialog
9///
10/// Each colour left `Color32::TRANSPARENT`, as in the default, follows the theme passed to
11/// [`IndicatorDialog::show`](super::IndicatorDialog::show).
12#[derive(Debug, Clone)]
13pub struct IndicatorDialogConfig {
14    /// Outer width of the dialog
15    pub width: f32,
16    /// Minimum outer height of the dialog, clamped to the window
17    pub height: f32,
18    /// Indicator names
19    pub text_color: Color32,
20    /// Indicator descriptions, badges and notes
21    pub muted_color: Color32,
22    /// Fill of the row under the pointer
23    pub hover_color: Color32,
24    /// Star of a favourite indicator
25    pub favorite_color: Color32,
26}
27
28impl IndicatorDialogConfig {
29    /// Create config from `theme`
30    ///
31    /// Sets every colour from `theme`, so they no longer follow a theme change; start from
32    /// `default()` to follow the theme.
33    pub fn from_theme(theme: &Theme) -> Self {
34        let ui = &theme.ui;
35        Self {
36            text_color: ui.text,
37            muted_color: ui.text_secondary,
38            hover_color: ui.btn_bg_hover,
39            favorite_color: ui.warning,
40            ..Self::default()
41        }
42    }
43
44    /// This configuration with each `TRANSPARENT` colour taken from `theme`.
45    pub(super) fn resolved(&self, theme: &Theme) -> Self {
46        let themed = Self::from_theme(theme);
47        let or = |color: Color32, theme: Color32| {
48            if color == Color32::TRANSPARENT {
49                theme
50            } else {
51                color
52            }
53        };
54        Self {
55            text_color: or(self.text_color, themed.text_color),
56            muted_color: or(self.muted_color, themed.muted_color),
57            hover_color: or(self.hover_color, themed.hover_color),
58            favorite_color: or(self.favorite_color, themed.favorite_color),
59            ..self.clone()
60        }
61    }
62}
63
64impl Default for IndicatorDialogConfig {
65    fn default() -> Self {
66        Self {
67            width: 840.0,
68            height: 640.0,
69            text_color: Color32::TRANSPARENT,
70            muted_color: Color32::TRANSPARENT,
71            hover_color: Color32::TRANSPARENT,
72            favorite_color: Color32::TRANSPARENT,
73        }
74    }
75}