Skip to main content

egui_charts/ui/dialogs/indicator_dialog/
actions.rs

1//! Actions emitted by the indicator dialog
2
3use crate::studies::Indicator;
4
5/// Actions emitted by the indicator dialog
6#[derive(Clone)]
7#[non_exhaustive]
8pub enum IndicatorDialogAction {
9    /// No action
10    None,
11    /// Add this study, created through the dialog's factory with its default inputs and any
12    /// source the dialog was opened with
13    AddIndicator(Box<dyn Indicator>),
14    /// Toggle favorite status
15    ToggleFavorite(String),
16    /// Dialog closed
17    Close,
18}
19
20impl std::fmt::Debug for IndicatorDialogAction {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            Self::None => f.write_str("None"),
24            Self::AddIndicator(study) => {
25                f.debug_tuple("AddIndicator").field(&study.name()).finish()
26            }
27            Self::ToggleFavorite(name) => f.debug_tuple("ToggleFavorite").field(name).finish(),
28            Self::Close => f.write_str("Close"),
29        }
30    }
31}
32
33impl IndicatorDialogAction {
34    /// Check if this action is adding an indicator
35    pub fn is_add(&self) -> bool {
36        matches!(self, IndicatorDialogAction::AddIndicator(_))
37    }
38}