image: Reorganize into several sub-modules
This commit is contained in:
parent
cfed1d3d63
commit
3ab4d82d36
13 changed files with 1846 additions and 1597 deletions
49
src/widgets/image/pan.rs
Normal file
49
src/widgets/image/pan.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (c) 2023 Sophie Herold
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use super::*;
|
||||
|
||||
impl LpImage {
|
||||
/// Stepwise scrolls inside an image when zoomed in
|
||||
pub fn pan(&self, direction: >k::PanDirection) {
|
||||
let sign = match direction {
|
||||
gtk::PanDirection::Left | gtk::PanDirection::Up => -1.,
|
||||
gtk::PanDirection::Right | gtk::PanDirection::Down => 1.,
|
||||
_ => {
|
||||
log::error!("Unknown pan direction {direction:?}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let (adjustment, max) = match direction {
|
||||
gtk::PanDirection::Left | gtk::PanDirection::Right => {
|
||||
(self.hadjustment(), self.max_hadjustment_value())
|
||||
}
|
||||
gtk::PanDirection::Up | gtk::PanDirection::Down => {
|
||||
(self.vadjustment(), self.max_vadjustment_value())
|
||||
}
|
||||
_ => {
|
||||
log::error!("Unknown pan direction {direction:?}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let value = (adjustment.value() + sign * adjustment.step_increment()).clamp(0., max);
|
||||
|
||||
adjustment.set_value(value);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue