Save selected color_mode using glib settings
This commit is contained in:
41
Cargo.lock
generated
41
Cargo.lock
generated
@ -140,7 +140,7 @@ version = "4.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"heck 0.4.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.37",
|
||||
@ -379,7 +379,7 @@ version = "0.18.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72793962ceece3863c2965d7f10c8786323b17c7adea75a515809fa20ab799a5"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"heck 0.4.1",
|
||||
"proc-macro-crate 2.0.0",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
@ -528,6 +528,12 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.3"
|
||||
@ -608,6 +614,7 @@ dependencies = [
|
||||
"gtk4",
|
||||
"log",
|
||||
"poppler-rs",
|
||||
"strum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -798,6 +805,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.19"
|
||||
@ -854,6 +867,28 @@ version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "strum"
|
||||
version = "0.26.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06"
|
||||
dependencies = [
|
||||
"strum_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strum_macros"
|
||||
version = "0.26.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustversion",
|
||||
"syn 2.0.37",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@ -883,7 +918,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30c2de8a4d8f4b823d634affc9cd2a74ec98c53a756f317e529a48046cbf71f3"
|
||||
dependencies = [
|
||||
"cfg-expr",
|
||||
"heck",
|
||||
"heck 0.4.1",
|
||||
"pkg-config",
|
||||
"toml",
|
||||
"version-compare",
|
||||
|
@ -14,3 +14,4 @@ gtk = { version = "0.7.3", package = "gtk4", features = ["v4_8"] }
|
||||
anyhow = "1.0.75"
|
||||
log = "0.4.20"
|
||||
env_logger = "0.10.1"
|
||||
strum = { version = "0.26.3", features = ["derive"] }
|
||||
|
@ -6,5 +6,9 @@
|
||||
<default>false</default>
|
||||
<summary>Whether the application is in fullscreen mode</summary>
|
||||
</key>
|
||||
<key name="color-mode" type="s">
|
||||
<default>'Normal'</default>
|
||||
<summary>The color mode used to render the pdf pages</summary>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
@ -1,12 +1,27 @@
|
||||
use cairo::ImageSurface;
|
||||
use core::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
use cairo::ImageSurface;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Clone, EnumString, Debug)]
|
||||
pub enum ColorMode {
|
||||
Normal,
|
||||
Dark,
|
||||
Sepia,
|
||||
}
|
||||
|
||||
impl fmt::Display for ColorMode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ColorMode {
|
||||
fn default() -> Self {
|
||||
ColorMode::Normal
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorMode {
|
||||
fn transform_color(&self, r: u8, g: u8, b: u8) -> (u8, u8, u8) {
|
||||
// l of black is 0.13 (approx 0x22)
|
||||
|
17
src/ui.rs
17
src/ui.rs
@ -2,6 +2,7 @@ use std::{
|
||||
cell::RefCell,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
str::FromStr,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
@ -226,7 +227,7 @@ impl Ui {
|
||||
debug!("building ui");
|
||||
let open_file_button = Button::from_icon_name("document-open");
|
||||
let fullscreen_button = Button::from_icon_name("view-fullscreen");
|
||||
let normal_color_mode_button = ToggleButton::builder().label("Std").active(true).build();
|
||||
let normal_color_mode_button = ToggleButton::builder().label("Std").build();
|
||||
let dark_color_mode_button = ToggleButton::builder()
|
||||
.label("Dark")
|
||||
.group(&normal_color_mode_button)
|
||||
@ -292,6 +293,13 @@ impl Ui {
|
||||
.build();
|
||||
window.present();
|
||||
|
||||
let color_mode = ColorMode::from_str(&settings.string("color-mode")).unwrap_or_default();
|
||||
match color_mode {
|
||||
ColorMode::Normal => normal_color_mode_button.set_active(true),
|
||||
ColorMode::Dark => dark_color_mode_button.set_active(true),
|
||||
ColorMode::Sepia => sepia_color_mode_button.set_active(true),
|
||||
};
|
||||
|
||||
let ui = Ui {
|
||||
settings,
|
||||
window,
|
||||
@ -307,7 +315,7 @@ impl Ui {
|
||||
image_right,
|
||||
document_canvas: None,
|
||||
last_touch_time: None,
|
||||
color_mode: ColorMode::Normal,
|
||||
color_mode,
|
||||
};
|
||||
let ui = Rc::new(RefCell::new(ui));
|
||||
|
||||
@ -371,6 +379,11 @@ impl Ui {
|
||||
}
|
||||
|
||||
fn switch_color_mode(ui: Rc<RefCell<Ui>>, color_mode: ColorMode) {
|
||||
ui.borrow()
|
||||
.settings
|
||||
.set_string("color-mode", &color_mode.to_string())
|
||||
.unwrap();
|
||||
|
||||
ui.borrow_mut().color_mode = color_mode;
|
||||
|
||||
if ui.borrow().document_canvas.is_none() {
|
||||
|
Reference in New Issue
Block a user