Skip to main content

egui_charts/ui/drawing_toolbar/utilities/
zoom.rs

1//! Zoom in/out btns.
2//!
3//! Zoom tools for chart navigation:
4//! - Zoom In: Click and drag to zoom to a specific area
5//! - Zoom Out: Restore previous zoom level from history
6
7use crate::icons::icons;
8use crate::ui::drawing_toolbar::DrawingToolbarAction;
9use crate::ui::drawing_toolbar::components::draw_tool_button;
10use egui::Ui;
11
12/// Zoom In button component.
13pub struct ZoomInButton;
14
15impl ZoomInButton {
16    /// Render the zoom in button and return any action.
17    pub fn show(ui: &mut Ui, is_active: bool) -> Option<DrawingToolbarAction> {
18        let response = draw_tool_button(ui, &icons::ZOOM_IN, "Zoom in", is_active);
19
20        if response.clicked() {
21            Some(DrawingToolbarAction::ZoomIn)
22        } else {
23            None
24        }
25    }
26}
27
28/// Zoom Out button component.
29pub struct ZoomOutButton;
30
31impl ZoomOutButton {
32    /// Render the zoom out button and return any action.
33    pub fn show(ui: &mut Ui) -> Option<DrawingToolbarAction> {
34        let response = draw_tool_button(ui, &icons::ZOOM_OUT, "Zoom out", false);
35
36        if response.clicked() {
37            Some(DrawingToolbarAction::ZoomOut)
38        } else {
39            None
40        }
41    }
42}