Skip to main content

egui_charts/ui/drawing_toolbar/utilities/
remove_menu.rs

1//! Remove objects dropdown menu.
2//!
3//! Provides options to permanently remove chart elements:
4//! - All Drawings
5//! - All Indicators
6//! - All drawings and indicators
7
8use crate::icons::icons;
9use crate::ui::drawing_toolbar::DrawingToolbarAction;
10use crate::ui::drawing_toolbar::components::draw_tool_button;
11use crate::ui::drawing_toolbar::submenu_builder::SubmenuBuilder;
12use egui::{Response, Ui};
13
14/// Remove objects dropdown menu component.
15pub struct RemoveMenu;
16
17impl RemoveMenu {
18    /// Render the remove button with trash icon. A click opens the dropdown.
19    pub fn show(ui: &mut Ui) -> Response {
20        draw_tool_button(ui, &icons::TRASH, "Remove objects", false)
21    }
22
23    /// Render the remove dropdown rows, in the error colour.
24    pub fn show_submenu(ui: &mut Ui) -> Option<DrawingToolbarAction> {
25        SubmenuBuilder::new(ui)
26            .add_text_item_with_action(
27                "Remove all drawings",
28                "Permanently delete all drawing tools from chart",
29                || Some(DrawingToolbarAction::RemoveAllDrawings),
30            )
31            .danger(&icons::TRASH)
32            .add_text_item_with_action(
33                "Remove all indicators",
34                "Remove all indicators from chart",
35                || Some(DrawingToolbarAction::RemoveAllIndicators),
36            )
37            .danger(&icons::TRASH)
38            .add_text_item_with_action(
39                "Remove drawings and indicators",
40                "Permanently delete all drawing tools and remove all indicators from chart",
41                || Some(DrawingToolbarAction::RemoveDrawingsAndIndicators),
42            )
43            .danger(&icons::TRASH)
44            .show()
45    }
46}