Compare commits
No commits in common. "02120b326386e423057350f2f45fe1f0c076bae4" and "b5239e14b63ce241fcbc8e7b1be6b88f6940f021" have entirely different histories.
02120b3263
...
b5239e14b6
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 0.4.1",
|
||||
"heck",
|
||||
"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 0.4.1",
|
||||
"heck",
|
||||
"proc-macro-crate 2.0.0",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
@ -528,12 +528,6 @@ 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"
|
||||
@ -614,7 +608,6 @@ dependencies = [
|
||||
"gtk4",
|
||||
"log",
|
||||
"poppler-rs",
|
||||
"strum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -805,12 +798,6 @@ 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"
|
||||
@ -867,28 +854,6 @@ 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"
|
||||
@ -918,7 +883,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30c2de8a4d8f4b823d634affc9cd2a74ec98c53a756f317e529a48046cbf71f3"
|
||||
dependencies = [
|
||||
"cfg-expr",
|
||||
"heck 0.4.1",
|
||||
"heck",
|
||||
"pkg-config",
|
||||
"toml",
|
||||
"version-compare",
|
||||
|
@ -14,4 +14,3 @@ 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"] }
|
||||
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- GTK settings schema / configuration. Deploy this e.g. to $HOME/.local/share/glib-2.0/schemas -->
|
||||
<schemalist>
|
||||
<schema id="de.frajul.music-reader" path="/de/frajul/music-reader/">
|
||||
<key name="fullscreen" type="b">
|
||||
<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>
|
11
flake.nix
11
flake.nix
@ -42,10 +42,6 @@
|
||||
|
||||
mkdir -p $out/share/icons
|
||||
cp ${./music-reader.png} $out/share/icons/music-reader.png
|
||||
|
||||
mkdir -p $out/share/glib-2.0/schemas
|
||||
cp ${./de.frajul.music-reader.gschema.xml} $out/share/glib-2.0/schemas/de.frajul.music-reader.gschema.xml
|
||||
glib-compile-schemas $out/share/glib-2.0/schemas/
|
||||
'';
|
||||
};
|
||||
devShell =
|
||||
@ -57,13 +53,6 @@
|
||||
rustfmt
|
||||
pre-commit
|
||||
rustPackages.clippy
|
||||
|
||||
gtk4
|
||||
cairo
|
||||
glib
|
||||
pkg-config
|
||||
poppler
|
||||
wrapGAppsHook
|
||||
];
|
||||
# Without inheriting nativeBuildinputs, cargo build will fail but that is good since we want to use only nix build
|
||||
# inherit nativeBuildInputs;
|
||||
|
@ -1,27 +1,12 @@
|
||||
use core::fmt;
|
||||
|
||||
use cairo::ImageSurface;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Clone, EnumString, Debug)]
|
||||
#[derive(Clone)]
|
||||
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)
|
||||
|
@ -5,9 +5,9 @@ mod ui;
|
||||
|
||||
use clap::Parser;
|
||||
use env_logger::Env;
|
||||
use gio::Settings;
|
||||
use gtk::prelude::*;
|
||||
use gtk::Application;
|
||||
use log::debug;
|
||||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
@ -27,8 +27,7 @@ fn main() {
|
||||
let app = Application::builder().application_id(APP_ID).build();
|
||||
|
||||
app.connect_activate(move |app| {
|
||||
let settings = Settings::new(APP_ID);
|
||||
let ui = build_ui(app, settings);
|
||||
let ui = build_ui(app);
|
||||
if let Some(file) = cli.file.as_ref() {
|
||||
ui::load_document(file, Rc::clone(&ui), 0);
|
||||
}
|
||||
@ -37,6 +36,6 @@ fn main() {
|
||||
app.run_with_args(&[] as &[&str]);
|
||||
}
|
||||
|
||||
fn build_ui(app: &Application, settings: Settings) -> Rc<RefCell<Ui>> {
|
||||
Ui::build(app, settings)
|
||||
fn build_ui(app: &Application) -> Rc<RefCell<Ui>> {
|
||||
Ui::build(app)
|
||||
}
|
||||
|
63
src/ui.rs
63
src/ui.rs
@ -2,11 +2,9 @@ use std::{
|
||||
cell::RefCell,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
str::FromStr,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use gio::Settings;
|
||||
use gtk::{
|
||||
glib, Application, ApplicationWindow, Box, Button, FileChooserAction, FileChooserDialog,
|
||||
HeaderBar, Label, Overlay, Picture, ResponseType, ToggleButton,
|
||||
@ -21,7 +19,6 @@ use glib::clone;
|
||||
use gtk::prelude::*;
|
||||
|
||||
pub struct Ui {
|
||||
settings: Settings,
|
||||
window: ApplicationWindow,
|
||||
bottom_bar: gtk::Box,
|
||||
header_bar: gtk::HeaderBar,
|
||||
@ -117,24 +114,22 @@ impl DocumentCanvas {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fullscreen(ui: &Ui, fullscreen: bool) {
|
||||
match fullscreen {
|
||||
pub fn toggle_fullscreen(ui: &Ui) {
|
||||
match !ui.window.is_fullscreen() {
|
||||
true => {
|
||||
ui.header_bar.hide();
|
||||
ui.bottom_bar.hide();
|
||||
ui.window.fullscreen();
|
||||
|
||||
let new_area_height = ui.image_container.height() + ui.header_bar.height();
|
||||
if ui.document_canvas.is_some() {
|
||||
ui.document_canvas
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.priority_cache_current_pages(new_area_height);
|
||||
ui.document_canvas
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.cache_surrounding_pages(new_area_height);
|
||||
}
|
||||
ui.document_canvas
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.priority_cache_current_pages(new_area_height);
|
||||
ui.document_canvas
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.cache_surrounding_pages(new_area_height);
|
||||
}
|
||||
false => {
|
||||
ui.header_bar.show();
|
||||
@ -142,11 +137,6 @@ pub fn set_fullscreen(ui: &Ui, fullscreen: bool) {
|
||||
ui.window.unfullscreen();
|
||||
}
|
||||
}
|
||||
ui.settings.set_boolean("fullscreen", fullscreen).unwrap();
|
||||
}
|
||||
|
||||
pub fn toggle_fullscreen(ui: &Ui) {
|
||||
set_fullscreen(ui, !ui.window.is_fullscreen());
|
||||
}
|
||||
|
||||
fn update_page_status(ui: &Ui) {
|
||||
@ -223,11 +213,10 @@ fn process_left_click(ui: &mut Ui, x: f64, y: f64) {
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn build(app: &Application, settings: Settings) -> Rc<RefCell<Ui>> {
|
||||
pub fn build(app: &Application) -> Rc<RefCell<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").build();
|
||||
let normal_color_mode_button = ToggleButton::builder().label("Std").active(true).build();
|
||||
let dark_color_mode_button = ToggleButton::builder()
|
||||
.label("Dark")
|
||||
.group(&normal_color_mode_button)
|
||||
@ -238,7 +227,7 @@ impl Ui {
|
||||
.build();
|
||||
|
||||
let button_container = Box::builder()
|
||||
.spacing(10)
|
||||
.spacing(5)
|
||||
.hexpand(true)
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
@ -251,7 +240,6 @@ impl Ui {
|
||||
color_mode_button_container.append(&dark_color_mode_button);
|
||||
color_mode_button_container.append(&sepia_color_mode_button);
|
||||
button_container.append(&open_file_button);
|
||||
button_container.append(&fullscreen_button);
|
||||
button_container.append(&color_mode_button_container);
|
||||
|
||||
let image_container = Box::builder()
|
||||
@ -293,15 +281,7 @@ 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,
|
||||
app_wrapper,
|
||||
bottom_bar: Box::builder()
|
||||
@ -315,7 +295,7 @@ impl Ui {
|
||||
image_right,
|
||||
document_canvas: None,
|
||||
last_touch_time: None,
|
||||
color_mode,
|
||||
color_mode: ColorMode::Normal,
|
||||
};
|
||||
let ui = Rc::new(RefCell::new(ui));
|
||||
|
||||
@ -347,11 +327,6 @@ impl Ui {
|
||||
choose_file(Rc::clone(&ui), &ui.borrow().window);
|
||||
}),
|
||||
);
|
||||
fullscreen_button.connect_clicked(
|
||||
glib::clone!(@strong ui => @default-panic, move |_button| {
|
||||
toggle_fullscreen(&ui.borrow());
|
||||
}),
|
||||
);
|
||||
normal_color_mode_button.connect_clicked(
|
||||
glib::clone!(@strong ui => @default-panic, move |_button| {
|
||||
switch_color_mode(Rc::clone(&ui), ColorMode::Normal);
|
||||
@ -369,21 +344,11 @@ impl Ui {
|
||||
);
|
||||
|
||||
ui.borrow().window.present();
|
||||
|
||||
if ui.borrow().settings.boolean("fullscreen") {
|
||||
set_fullscreen(&ui.borrow(), true);
|
||||
}
|
||||
|
||||
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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user