Skip to content

Commit fc1cb79

Browse files
committed
Add zoom shortcuts hints, reset zoom, zoom range
1 parent bee2016 commit fc1cb79

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

data/resources/ui/shortcuts.blp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ Gtk.ShortcutsWindow help_overlay {
6666
action-name: "win.show-bookmarks";
6767
}
6868
}
69+
Gtk.ShortcutsGroup {
70+
title: C_("shortcut window", "Zoom");
71+
72+
Gtk.ShortcutsShortcut {
73+
title: C_("shortcut window", "Zoom In");
74+
action-name: "win.zoom-in";
75+
}
76+
Gtk.ShortcutsShortcut {
77+
title: C_("shortcut window", "Zoom Out");
78+
action-name: "win.zoom-out";
79+
}
80+
Gtk.ShortcutsShortcut {
81+
title: C_("shortcut window", "Reset Zoom");
82+
action-name: "win.reset-zoom";
83+
}
84+
}
6985
}
7086
}
7187

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn main() {
9797
application.set_accels_for_action("win.focus-url-bar", &["F6"]);
9898
application.set_accels_for_action("win.zoom-in", &["<Ctrl>plus"]);
9999
application.set_accels_for_action("win.zoom-out", &["<Ctrl>minus"]);
100+
application.set_accels_for_action("win.reset-zoom", &["<Ctrl>0"]);
100101
// Sadly Tab doesn't work as an accelerator in gtk...
101102
application.set_accels_for_action("win.focus-next-tab", &["<Ctrl>Tab"]);
102103
application.set_accels_for_action("win.focus-previous-tab", &["<Ctrl><Shift>Tab"]);

src/widgets/window.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use crate::self_action;
2121
use crate::widgets::tab::{HistoryStatus, Tab};
2222

2323
const ZOOM_CHANGE_FACTOR: f32 = 1.15;
24+
const ZOOM_MAX_FACTOR: f32 = 5.0;
25+
2426
#[derive(Debug, Clone, Default)]
2527
pub(crate) struct Zoom {
2628
value: f32,
@@ -58,7 +60,6 @@ pub mod imp {
5860
pub(crate) action_previous: RefCell<Option<gio::SimpleAction>>,
5961
pub(crate) action_next: RefCell<Option<gio::SimpleAction>>,
6062
pub(crate) style_provider: RefCell<gtk::CssProvider>,
61-
6263
#[property(get = Self::zoom, set = Self::set_zoom, type = f32, member = value)]
6364
pub(crate) zoom: RefCell<Zoom>,
6465
}
@@ -98,7 +99,7 @@ pub mod imp {
9899
}
99100
fn set_zoom(&self, v: f32) {
100101
let Zoom { value, provider } = &mut *self.zoom.borrow_mut();
101-
*value = v;
102+
*value = v.clamp(1.0 / ZOOM_MAX_FACTOR, ZOOM_MAX_FACTOR);
102103
provider.load_from_data(
103104
format!(
104105
"textview {{
@@ -200,6 +201,7 @@ impl Window {
200201
self_action!(self, "donate", donate);
201202
self_action!(self, "zoom-in", zoom_in);
202203
self_action!(self, "zoom-out", zoom_out);
204+
self_action!(self, "reset-zoom", reset_zoom);
203205

204206
let act_open_page = gio::SimpleAction::new("open-omni", Some(glib::VariantTy::STRING));
205207
act_open_page.connect_activate(
@@ -227,6 +229,7 @@ impl Window {
227229
);
228230
self.add_action(&act_set_clipboard);
229231

232+
// Signals
230233
self.add_controller(&imp.scroll_ctrl);
231234
imp.scroll_ctrl
232235
.set_propagation_phase(gtk::PropagationPhase::Capture);
@@ -516,4 +519,7 @@ impl Window {
516519
fn zoom_out(&self) {
517520
self.set_zoom(&(self.zoom() * 1.0 / ZOOM_CHANGE_FACTOR));
518521
}
522+
fn reset_zoom(&self) {
523+
self.set_zoom(&1.0);
524+
}
519525
}

0 commit comments

Comments
 (0)