diff --git a/Cargo.lock b/Cargo.lock
index 4d5a393..ac45f3c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index 2ef8c1d..00f3ba1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"] }
diff --git a/de.frajul.music-reader.gschema.xml b/de.frajul.music-reader.gschema.xml
index a23894b..20b998a 100644
--- a/de.frajul.music-reader.gschema.xml
+++ b/de.frajul.music-reader.gschema.xml
@@ -6,5 +6,9 @@
false
Whether the application is in fullscreen mode
+
+ 'Normal'
+ The color mode used to render the pdf pages
+
diff --git a/src/color_mode.rs b/src/color_mode.rs
index 45e6359..8ec852f 100644
--- a/src/color_mode.rs
+++ b/src/color_mode.rs
@@ -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)
diff --git a/src/ui.rs b/src/ui.rs
index 9a3e0d6..baba565 100644
--- a/src/ui.rs
+++ b/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>, 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() {