Skip to content

Commit baf6181

Browse files
committed
Bind zoom to settings
1 parent 732dc90 commit baf6181

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

data/com.ranfdev.Geopard.gschema.xml.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@
1313
<default>false</default>
1414
<summary>Window maximized state</summary>
1515
</key>
16+
<key name="zoom" type="d">
17+
<default>1.0</default>
18+
<summary>Zoom</summary>
19+
</key>
1620
</schema>
1721
</schemalist>

src/widgets/window.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use adw::prelude::*;
22
use adw::subclass::application_window::AdwApplicationWindowImpl;
33
use anyhow::Context;
4+
use config::APP_ID;
45
use futures::prelude::*;
56
use glib::{clone, Properties};
67
use gtk::gdk;
@@ -20,12 +21,12 @@ use crate::config;
2021
use crate::self_action;
2122
use crate::widgets::tab::{HistoryStatus, Tab};
2223

23-
const ZOOM_CHANGE_FACTOR: f32 = 1.15;
24-
const ZOOM_MAX_FACTOR: f32 = 5.0;
24+
const ZOOM_CHANGE_FACTOR: f64 = 1.15;
25+
const ZOOM_MAX_FACTOR: f64 = 5.0;
2526

2627
#[derive(Debug, Clone, Default)]
2728
pub(crate) struct Zoom {
28-
value: f32,
29+
value: f64,
2930
provider: gtk::CssProvider,
3031
}
3132

@@ -62,8 +63,9 @@ pub mod imp {
6263
pub(crate) action_previous: RefCell<Option<gio::SimpleAction>>,
6364
pub(crate) action_next: RefCell<Option<gio::SimpleAction>>,
6465
pub(crate) style_provider: RefCell<gtk::CssProvider>,
65-
#[property(get, set = Self::set_zoom, type = f32, member = value)]
66+
#[property(get, set = Self::set_zoom, type = f64, member = value)]
6667
pub(crate) zoom: RefCell<Zoom>,
68+
pub(crate) settings: RefCell<Option<gio::Settings>>, // TODO: May use ConstructCell
6769
}
6870

6971
impl Window {
@@ -96,7 +98,7 @@ pub mod imp {
9698
animation.play();
9799
self.progress_animation.replace(Some(animation));
98100
}
99-
fn set_zoom(&self, v: f32) {
101+
fn set_zoom(&self, v: f64) {
100102
let Zoom { value, provider } = &mut *self.zoom.borrow_mut();
101103
*value = v.clamp(1.0 / ZOOM_MAX_FACTOR, ZOOM_MAX_FACTOR);
102104
provider.load_from_data(
@@ -194,7 +196,7 @@ impl Window {
194196
value_btn.set_hexpand(true);
195197
this.bind_property("zoom", &value_btn, "label")
196198
.transform_to(|_, v| {
197-
let zoom: f32 = v.get().unwrap();
199+
let zoom: f64 = v.get().unwrap();
198200
Some(format!("{:3}%", (zoom * 100.0) as usize).to_value())
199201
})
200202
.build();
@@ -213,6 +215,10 @@ impl Window {
213215
);
214216
popover.add_child(&zoom_box, "zoom");
215217

218+
let settings = gio::Settings::new(APP_ID);
219+
settings.bind("zoom", &this, "zoom").build();
220+
imp.settings.replace(Some(settings));
221+
216222
this.squeezer_changed();
217223
this.setup_actions_signals();
218224
this.open_in_new_tab(bookmarks_url().as_str());

0 commit comments

Comments
 (0)