Skip to main content

egui_charts/ui/drawing_toolbar/utilities/
lock.rs

1//! Lock all drawings button.
2//!
3//! Locks all drawings on the chart to prevent accidental
4//! modification or deletion.
5
6use crate::icons::icons;
7use crate::ui::drawing_toolbar::DrawingToolbarAction;
8use crate::ui::drawing_toolbar::components::draw_tool_button;
9use egui::Ui;
10
11/// Lock All Drawings button.
12pub struct LockButton;
13
14impl LockButton {
15    /// Render the lock button and return any action. While `is_active` (all drawings are
16    /// locked) it is filled, shows the closed padlock and offers to unlock.
17    pub fn show(ui: &mut Ui, is_active: bool) -> Option<DrawingToolbarAction> {
18        let (icon, tooltip) = if is_active {
19            (&icons::LOCK, "Unlock all drawings")
20        } else {
21            (&icons::UNLOCK, "Lock all drawings")
22        };
23        let response = draw_tool_button(ui, icon, tooltip, is_active);
24
25        if response.clicked() {
26            log::info!("Lock all drawings clicked");
27            Some(DrawingToolbarAction::LockAllDrawings)
28        } else {
29            None
30        }
31    }
32}