Commit fbabd1e8 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

MediaViewer: Adjust zoom buttons sensitivity

This allows to adjust the zoom buttons sensitivity when the user is
not supposed to be able to zoom in or out.

See https://gitlab.gnome.org/World/fractal/issues/265
parent 58f479d6
......@@ -14,6 +14,8 @@ use widgets::image;
use types::Room;
const FLOATING_POINT_ERROR: f64 = 0.01;
#[derive(Clone)]
pub struct MediaViewer {
media_names: Vec<String>,
......@@ -90,6 +92,7 @@ impl AppOp {
});
self.set_nav_btn_sensitivity();
self.set_zoom_btn_sensitivity();
}
pub fn hide_media_viewer(&mut self) {
......@@ -146,6 +149,7 @@ impl AppOp {
}
self.set_nav_btn_sensitivity();
self.set_zoom_btn_sensitivity();
}
pub fn next_media(&mut self) {
......@@ -189,6 +193,7 @@ impl AppOp {
}
self.set_nav_btn_sensitivity();
self.set_zoom_btn_sensitivity();
}
pub fn set_nav_btn_sensitivity(&self) {
......@@ -228,6 +233,8 @@ impl AppOp {
mv.set_zoom_level(*new_zlvl);
}
}
self.set_zoom_btn_sensitivity();
}
pub fn zoom_in(&self) {
......@@ -243,6 +250,8 @@ impl AppOp {
mv.set_zoom_level(*new_zlvl);
}
}
self.set_zoom_btn_sensitivity();
}
pub fn change_zoom_level(&self) {
......@@ -258,6 +267,8 @@ impl AppOp {
},
}
}
self.set_zoom_btn_sensitivity();
}
pub fn enter_full_screen(&self) {
......@@ -287,6 +298,44 @@ impl AppOp {
self.save_file_as(mv.image.local_path.lock().unwrap().clone().unwrap_or_default(), mv.media_names[mv.current_media_index].clone());
}
}
pub fn set_zoom_btn_sensitivity(&self) {
if let Some(ref mv) = self.media_viewer {
let zoom_out_button = self.ui.builder
.get_object::<gtk::Button>("zoom_out_button")
.expect("Cant find zoom_out_button in ui file.");
let zoom_in_button = self.ui.builder
.get_object::<gtk::Button>("zoom_in_button")
.expect("Cant find zoom_in_button in ui file.");
gtk::timeout_add(10, clone!(mv => move || match *mv.image.zoom_level.lock().unwrap() {
None => Continue(true),
Some(zlvl) => {
let min_lvl = mv.zoom_levels.first();
let max_lvl = mv.zoom_levels.last();
if let Some(min_lvl) = min_lvl {
if zlvl <= *min_lvl + FLOATING_POINT_ERROR {
zoom_out_button.set_sensitive(false);
} else {
zoom_out_button.set_sensitive(true);
}
}
if let Some(max_lvl) = max_lvl {
if zlvl >= *max_lvl - FLOATING_POINT_ERROR {
zoom_in_button.set_sensitive(false);
} else {
zoom_in_button.set_sensitive(true);
}
}
Continue(false)
},
}));
}
}
}
fn update_zoom_entry(ui: &uibuilder::UI, zoom_level: f64) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment