aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/zoom.rs
blob: 59a54a74b95a9c479dbca8ee2b9890e9f34b96b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Map, wardley map editor for linux
// Copyright (C) 2026 Rubén Beltrán del Río

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.

// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
use relm4::prelude::*;

use crate::AppModel;
use crate::constants;
use crate::components::footer::FooterAction;

/// Sets the zoom level and updates the rendered image.
pub fn zoom(model: &mut AppModel, level: f64) {
    model.zoom = level;
    model.update_image();
    model.footer.emit(FooterAction::SetZoom(level));
}

/// Decreases zoom by one step if above minimum.
pub fn zoom_out(model: &mut AppModel) {
    let new_zoom = model.zoom - constants::ZOOM_STEP;
    if new_zoom >= constants::MIN_ZOOM {
        zoom(model, new_zoom);
    }
}

/// Increases zoom by one step if below maximum.
pub fn zoom_in(model: &mut AppModel) {
    if model.zoom < constants::MAX_ZOOM {
        zoom(model, model.zoom + constants::ZOOM_STEP);
    }
}