aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/zoom.rs
blob: 575f5f9fe1b1cd0887c8d479152d245cdd30a269 (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
// 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 crate::AppModel;
use crate::constants;

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

/// 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 {
        model.zoom = new_zoom;
        model.update_image();
    }
}

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