From b56d6500860917b9feb5e90e37afaf54a89170ea Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Wed, 29 Nov 2023 21:15:36 +0100 Subject: [PATCH] code: Reformat with new rules --- .rustfmt.toml | 3 +++ src/application.rs | 1 + src/decoder/mod.rs | 1 + src/decoder/tiling.rs | 10 +++++----- src/file_model.rs | 7 ++++--- src/main.rs | 3 ++- src/util/mod.rs | 3 ++- src/widgets/image.rs | 32 +++++++++++++++++++------------- src/widgets/image_page.rs | 4 ++-- src/widgets/image_view.rs | 19 ++++++++++--------- src/widgets/print.rs | 5 +++-- src/widgets/properties_view.rs | 4 +++- src/widgets/sliding_view.rs | 4 ++-- src/window.rs | 17 +++++++++++------ 14 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..ad0a8a0 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,3 @@ +format_code_in_doc_comments = true +imports_granularity = "Module" +wrap_comments = true diff --git a/src/application.rs b/src/application.rs index cb80d4b..6f40d63 100644 --- a/src/application.rs +++ b/src/application.rs @@ -1,6 +1,7 @@ // Copyright (c) 2020-2023 Christopher Davis // Copyright (c) 2022-2023 Sophie Herold // Copyright (c) 2022-2023 Sabri Ünal +// Copyright (c) 2023 Julian Hofer // Copyright (c) 2023 Huan Nguyen // // This program is free software: you can redistribute it and/or modify diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index a3c94e7..d17aeaf 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -1,4 +1,5 @@ // Copyright (c) 2023 Sophie Herold +// Copyright (c) 2023 Julian Hofer // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/src/decoder/tiling.rs b/src/decoder/tiling.rs index 8fab42e..e5d861c 100644 --- a/src/decoder/tiling.rs +++ b/src/decoder/tiling.rs @@ -32,8 +32,7 @@ use crate::deps::*; use arc_swap::ArcSwap; use gtk::prelude::*; -use std::collections::BTreeMap; -use std::collections::VecDeque; +use std::collections::{BTreeMap, VecDeque}; use std::sync::Arc; use std::time::Duration; @@ -335,8 +334,8 @@ impl TiledImage { /// Viewport within zoom coordinates /// - /// preserve_area: Slightly larger than the viewport, area for which we want tiles - /// TODO: This is the most buggy function ever + /// preserve_area: Slightly larger than the viewport, area for which we want + /// tiles TODO: This is the most buggy function ever pub fn cleanup(&mut self, zoom: f64, preserve_area: graphene::Rect) { let zoom = zoom_normalize(zoom); let mut kept_tiles = Self::default(); @@ -584,7 +583,8 @@ pub trait FrameBufferExt { fn push_frame(&self, tile: Tile, dimensions: Coordinates, delay: Duration); fn reset(&self); fn get_layer_tiling_or_default(&self, zoom: f64, viewport: graphene::Rect) -> Tiling; - /// Return true if the next frame should be shown and removes the outdated frame + /// Return true if the next frame should be shown and removes the outdated + /// frame fn frame_timeout(&self, elapsed: Duration) -> bool; /// Returns the number of currently buffered frames fn n_frames(&self) -> usize; diff --git a/src/file_model.rs b/src/file_model.rs index 7b36d72..194da07 100644 --- a/src/file_model.rs +++ b/src/file_model.rs @@ -36,8 +36,8 @@ mod imp { #[derive(Debug, Default)] pub struct LpFileModel { - /// Use and IndexMap such that we can put the elements into an arbitrary order - /// while still having fast hash access via file URI. + /// Use and IndexMap such that we can put the elements into an arbitrary + /// order while still having fast hash access via file URI. pub(super) files: RefCell>, pub(super) directory: OnceCell, /// Track file changes. @@ -150,7 +150,8 @@ impl LpFileModel { let mut new_files = new_files?; { - // Here we use a nested scope so that the mutable borrow only lasts as long as we need it + // Here we use a nested scope so that the mutable borrow only lasts as long as + // we need it let mut files = self.imp().files.borrow_mut(); for (uri, file) in files.iter() { diff --git a/src/main.rs b/src/main.rs index 41196c2..20bd7ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,8 @@ Simplified widget arrangement including the most important widgets. */ use gettextrs::*; -use gtk::gio::{self, prelude::*}; +use gtk::gio::prelude::*; +use gtk::gio::{self}; mod about; mod application; diff --git a/src/util/mod.rs b/src/util/mod.rs index 72f0412..c254b41 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -32,7 +32,8 @@ use std::path::{Path, PathBuf}; pub fn datetime_fmt(datetime: &glib::DateTime) -> Option { // Translators: This is the date and time format we use in metadata output etc. // The format has to follow - // The default is already translated. Don't change if you are not sure what to use. + // The default is already translated. Don't change if you are not sure what to + // use. let datetime_format = gettext("%x %X"); let local_datetime = datetime.to_local(); diff --git a/src/widgets/image.rs b/src/widgets/image.rs index 8434b6f..540cf4e 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -1,6 +1,7 @@ // Copyright (c) 2021-2023 Christopher Davis // Copyright (c) 2022-2023 Sophie Herold // Copyright (c) 2022 Maximiliano Sandoval R +// Copyright (c) 2023 Julian Hofer // Copyright (c) 2023 Lubosz Sarnecki // // This program is free software: you can redistribute it and/or modify @@ -36,7 +37,8 @@ use crate::decoder::{self, tiling, Decoder, DecoderUpdate}; use crate::image_metadata::LpImageMetadata; use crate::util::Gesture; -use adw::{prelude::*, subclass::prelude::*}; +use adw::prelude::*; +use adw::subclass::prelude::*; use arc_swap::ArcSwap; use futures::prelude::*; use once_cell::sync::Lazy; @@ -49,8 +51,8 @@ use std::sync::Arc; /// `#242424` static BACKGROUND_COLOR_DEFAULT: Lazy = Lazy::new(|| gdk::RGBA::new(36. / 255., 36. / 255., 36. / 255., 1.)); -/// Background color if the default does not give enough contrast for transparent images -/// `#e8e7e6` +/// Background color if the default does not give enough contrast for +/// transparent images `#e8e7e6` static BACKGROUND_COLOR_ALTERNATE: Lazy = Lazy::new(|| gdk::RGBA::new(232. / 255., 231. / 255., 230. / 255., 1.)); @@ -61,7 +63,8 @@ static BACKGROUND_COLOR_ALTERNATE_LIGHT_MODE: Lazy = /// Consider 3.5:1 contrast and worse to be bad contrast for a pixel static BACKGROUND_GUESS_LOW_CONTRAST_RATIO: f32 = 3.5; -/// Consider transparent images with more than 90% pixels bad contrast as bad contrast +/// Consider transparent images with more than 90% pixels bad contrast as bad +/// contrast /// /// Bad contrast image will use the `BACKGROUND_COLOR_ALTERNATE`. static BACKGROUND_GUESS_LOW_CONTRAST_TRHESHOLD: f64 = 0.90; @@ -145,7 +148,8 @@ mod imp { #[property(get, set = Self::set_zoom, explicit_notify)] pub(super) zoom: Cell, pub(super) zoom_animation: OnceCell, - /// Targeted zoom level, might differ from `zoom` when animation is running + /// Targeted zoom level, might differ from `zoom` when animation is + /// running pub(super) zoom_target: Cell, /// Current animation is transitioning from having horizontal scrollbars /// to not having them or vice versa. @@ -730,10 +734,10 @@ mod imp { let hidpi_scale = self.obj().scale_factor() as f64; let monitor_geometry = monitor.geometry(); - // TODO: Per documentation those dimensions should not be physical pixels. - // But on Wayland they are physical pixels and on X11 not. - // Taking the version that works on Wayland for now. - // + // TODO: Per documentation those dimensions should not be physical + // pixels. But on Wayland they are physical + // pixels and on X11 not. Taking the version + // that works on Wayland for now. let monitor_width = monitor_geometry.width() as f64 - 40.; let monitor_height = monitor_geometry.height() as f64 - 60.; @@ -749,8 +753,8 @@ mod imp { 0.3 }; - // factor for width and height that will achieve the desired area occupation - // derived from: + // factor for width and height that will achieve the desired area + // occupation derived from: // monitor_area * occupy_area_factor == // (image_width * size_scale) * (image_height * size_scale) let size_scale = @@ -1684,9 +1688,11 @@ impl LpImage { } } - /// Returns a background color that should give suitable contrast with transparent images + /// Returns a background color that should give suitable contrast with + /// transparent images /// - /// For non-transparent images this always returns `BACKGROUND_COLOR_DEFAULT` + /// For non-transparent images this always returns + /// `BACKGROUND_COLOR_DEFAULT` pub async fn background_color_guess(&self) -> Option { // Shortcut for formats that don't support transparency if !self diff --git a/src/widgets/image_page.rs b/src/widgets/image_page.rs index 560d41e..a1079ef 100644 --- a/src/widgets/image_page.rs +++ b/src/widgets/image_page.rs @@ -1,5 +1,6 @@ // Copyright (c) 2022-2023 Sophie Herold // Copyright (c) 2022 Christopher Davis +// Copyright (c) 2023 Julian Hofer // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -24,8 +25,7 @@ use crate::deps::*; use crate::widgets::LpImage; use adw::subclass::prelude::*; -use glib::clone; -use glib::Properties; +use glib::{clone, Properties}; use gtk::prelude::*; use gtk::CompositeTemplate; diff --git a/src/widgets/image_view.rs b/src/widgets/image_view.rs index 3f47830..bed208f 100644 --- a/src/widgets/image_view.rs +++ b/src/widgets/image_view.rs @@ -1,7 +1,8 @@ // Copyright (c) 2020-2023 Christopher Davis // Copyright (c) 2022-2023 Sophie Herold -// Copyright (c) 2022 Elton A Rodrigues // Copyright (c) 2022 Maximiliano Sandoval R +// Copyright (c) 2023 Julian Hofer +// Copyright (c) 2023 Starccy // Copyright (c) 2023 FineFindus // Copyright (c) 2023 Huan Nguyen // Copyright (c) 2023 Philipp Kiemle @@ -39,15 +40,13 @@ use adw::prelude::*; use adw::subclass::prelude::*; use anyhow::Context; use ashpd::desktop::{wallpaper, ResponseError}; -use ashpd::Error; -use ashpd::WindowIdentifier; -use glib::clone; +use ashpd::{Error, WindowIdentifier}; use glib::translate::IntoGlib; -use glib::Properties; +use glib::{clone, Properties}; use gtk::CompositeTemplate; -use std::cell::{Cell, RefCell}; -use std::{cell::OnceCell, marker::PhantomData}; +use std::cell::{Cell, OnceCell, RefCell}; +use std::marker::PhantomData; // The number of pages we want to buffer // on either side of the current page. @@ -208,7 +207,8 @@ mod imp { } impl WidgetImpl for LpImageView { - /// This manual implementation makes sure left an right overlay both fit into the window + /// This manual implementation makes sure left an right overlay both fit + /// into the window fn measure(&self, orientation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) { // Measure child of AdwBin let (child_min, child_natural, _, _) = self.bin_child.measure(orientation, for_size); @@ -670,7 +670,8 @@ impl LpImageView { "win.show-toast", Some( &( - // Translators: This is a toast notification, informing the user that an image has been set as background. + // Translators: This is a toast notification, informing the user that + // an image has been set as background. gettext("Set as background."), adw::ToastPriority::High.into_glib(), ) diff --git a/src/widgets/print.rs b/src/widgets/print.rs index 9979640..c3c5127 100644 --- a/src/widgets/print.rs +++ b/src/widgets/print.rs @@ -1,4 +1,5 @@ // Copyright (c) 2023 Sophie Herold +// Copyright (c) 2023 Julian Hofer // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -63,8 +64,8 @@ enum Status { /// Scope guard for non user ui changes /// -/// Creates a context in which other signals know that changes are not user input. -/// This avoids things like loops between value change signals. +/// Creates a context in which other signals know that changes are not user +/// input. This avoids things like loops between value change signals. #[derive(Default, Clone, Debug)] struct UiUpdates { disabled: Rc>, diff --git a/src/widgets/properties_view.rs b/src/widgets/properties_view.rs index 72353ba..7473faa 100644 --- a/src/widgets/properties_view.rs +++ b/src/widgets/properties_view.rs @@ -1,5 +1,6 @@ // Copyright (c) 2022-2023 Sophie Herold // Copyright (c) 2022-2023 Christopher Davis +// Copyright (c) 2023 Julian Hofer // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -297,7 +298,8 @@ impl LpPropertiesView { fn folder_name(&self, file: Option) -> String { file.and_then(|f| f.parent()) // If the file exists, get the parent .and_then(|p| util::get_file_display_name(&p)) // if that exists, the display name - .unwrap_or_else(|| FALLBACK.to_owned()) // and if we get nothing, use `FALLBACK` + .unwrap_or_else(|| FALLBACK.to_owned()) // and if we get nothing, + // use `FALLBACK` } #[template_callback] diff --git a/src/widgets/sliding_view.rs b/src/widgets/sliding_view.rs index 725c9e0..5efed5b 100644 --- a/src/widgets/sliding_view.rs +++ b/src/widgets/sliding_view.rs @@ -457,8 +457,8 @@ impl LpSlidingView { /// Sets position shift to correct page insert or removal /// - /// Takes the old position of the current page and calculates and sets the shift - /// to keep the current page optically at the same position. + /// Takes the old position of the current page and calculates and sets the + /// shift to keep the current page optically at the same position. fn shift_position(&self, old_index: Option) { if let (Some(old_index), Some(new_index)) = (old_index, self.current_index()) { let shift = new_index as f64 - old_index as f64; diff --git a/src/window.rs b/src/window.rs index badccbb..7eace35 100644 --- a/src/window.rs +++ b/src/window.rs @@ -2,6 +2,7 @@ // Copyright (c) 2022-2023 Sophie Herold // Copyright (c) 2022 Elton A Rodrigues // Copyright (c) 2022 Maximiliano Sandoval R +// Copyright (c) 2023 Julian Hofer // Copyright (c) 2023 FineFindus // Copyright (c) 2023 qwel // Copyright (c) 2023 Huan Thieu Nguyen @@ -819,7 +820,8 @@ impl LpWindow { }) } - /// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` of inactivity + /// Queue a fade animation to play after `HIDE_CONTROLS_IDLE_TIMEOUT` of + /// inactivity fn queue_hide_controls(&self) { self.dequeue_hide_controls(); @@ -895,7 +897,9 @@ impl LpWindow { .image_view .current_file() .and_then(|f| util::get_file_display_name(&f)) // If the file exists, get display name - .unwrap_or_else(|| gettext("Image Viewer")) // Return that or the default if there's nothing + .unwrap_or_else(|| gettext("Image Viewer")) // Return that or + // the default if + // there's nothing } } @@ -912,9 +916,9 @@ impl LpWindow { fn on_motion(&self, pointer_position: (f64, f64)) { let imp = self.imp(); - // Check if position really changed since swipe gesture sends change event with same position. - // Also, don't connect this to "leave" because swipe also sends fake "leave" events when - // the widget under the cursor changes. + // Check if position really changed since swipe gesture sends change event with + // same position. Also, don't connect this to "leave" because swipe also + // sends fake "leave" events when the widget under the cursor changes. if imp.pointer_position.get() == pointer_position { return; } @@ -929,7 +933,8 @@ impl LpWindow { } } - /// Only hide controls if cursor not over controls and there is an image shown + /// Only hide controls if cursor not over controls and there is an image + /// shown fn can_hide_controls(&self) -> bool { !self .image_view()