diff --git a/Cargo.toml b/Cargo.toml index 5517e4c6..db49801b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ log = "0.4" open = "5.0" pico-args = "0.5" rand = "0.8" -resvg = "0.37" +resvg = "0.38" serde = { version = "1.0.159", features = ["derive"] } sys-info = "0.9" thiserror = "1.0" @@ -71,7 +71,7 @@ tiny-skia = "0.11" toml = "0.8" trash = { version = "3.0", default-features = false } typed-builder = "0.18" -usvg = "0.37" +usvg = "0.38" winit = "0.28" [dependencies.libavif-image] diff --git a/src/configuration.rs b/src/configuration.rs index 676f1ff9..060a0d95 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -1,11 +1,14 @@ +use std::{collections::BTreeMap, fs, path::PathBuf}; + use directories::ProjectDirs; use serde::{Deserialize, Serialize}; -use std::{collections::BTreeMap, fs, path::PathBuf}; /// Application name for project directories const APPLICATION: &str = "Alloy"; -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[derive( + Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize, +)] pub enum WindowMode { #[default] Normal, @@ -13,7 +16,9 @@ pub enum WindowMode { Fullscreen, } -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[derive( + Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize, +)] pub enum Theme { #[default] Light, @@ -29,7 +34,9 @@ impl Theme { } } -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[derive( + Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize, +)] pub enum ScalingMode { #[default] Fixed, @@ -37,7 +44,9 @@ pub enum ScalingMode { FitMin, } -#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] +#[derive( + Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize, +)] pub enum Antialias { #[default] Auto, @@ -101,7 +110,10 @@ impl Configuration { } pub fn scaling(&self) -> ScalingMode { - self.image.as_ref().and_then(|i| i.scaling).unwrap_or_default() + self.image + .as_ref() + .and_then(|i| i.scaling) + .unwrap_or_default() } pub fn set_scaling(&mut self, scaling: ScalingMode) { @@ -114,7 +126,10 @@ impl Configuration { } pub fn antialiasing(&self) -> Antialias { - self.image.as_ref().and_then(|i| i.antialiasing).unwrap_or_default() + self.image + .as_ref() + .and_then(|i| i.antialiasing) + .unwrap_or_default() } pub fn set_antialiasing(&mut self, antialias: Antialias) { @@ -127,15 +142,24 @@ impl Configuration { } pub fn title_folders(&self) -> u32 { - self.window.as_ref().and_then(|w| w.title_folders).unwrap_or_default() + self.window + .as_ref() + .and_then(|w| w.title_folders) + .unwrap_or_default() } pub fn window_mode(&self) -> WindowMode { - self.window.as_ref().and_then(|w| w.mode).unwrap_or_default() + self.window + .as_ref() + .and_then(|w| w.mode) + .unwrap_or_default() } pub fn theme(&self) -> Theme { - self.window.as_ref().and_then(|w| w.theme).unwrap_or_default() + self.window + .as_ref() + .and_then(|w| w.theme) + .unwrap_or_default() } pub fn set_theme(&mut self, theme: Theme) { diff --git a/src/gelatin/button.rs b/src/gelatin/button.rs index a680ed6e..7dc6522b 100644 --- a/src/gelatin/button.rs +++ b/src/gelatin/button.rs @@ -6,12 +6,17 @@ use glium::{ uniform, Frame, Surface, }; -use crate::add_common_widget_functions; -use crate::gelatin::{ - misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement}, - picture::Picture, - window::RenderValidity, - DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, WidgetError, +use crate::{ + add_common_widget_functions, + gelatin::{ + misc::{ + Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement, + }, + picture::Picture, + window::RenderValidity, + DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, + WidgetError, + }, }; struct ButtonData { diff --git a/src/gelatin/label.rs b/src/gelatin/label.rs index e0a4a787..9a60fb35 100644 --- a/src/gelatin/label.rs +++ b/src/gelatin/label.rs @@ -3,12 +3,16 @@ use std::{cell::RefCell, rc::Rc}; use cgmath::{Matrix4, Vector3}; use glium::{uniform, Frame, Surface}; -use crate::add_common_widget_functions; -use crate::gelatin::{ - misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement}, - picture::Picture, - window::RenderValidity, - DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, +use crate::{ + add_common_widget_functions, + gelatin::{ + misc::{ + Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement, + }, + picture::Picture, + window::RenderValidity, + DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, + }, }; struct LabelData { diff --git a/src/gelatin/line_layout_container.rs b/src/gelatin/line_layout_container.rs index fe8e4057..b936cf09 100644 --- a/src/gelatin/line_layout_container.rs +++ b/src/gelatin/line_layout_container.rs @@ -2,15 +2,17 @@ use std::{cell::RefCell, rc::Rc}; use glium::Frame; -use crate::add_common_widget_functions; -use crate::gelatin::{ - misc::{ - Alignment, HorDim, Length, LogicalRect, LogicalVector, PickDimension, - VerDim, WidgetPlacement, +use crate::{ + add_common_widget_functions, + gelatin::{ + misc::{ + Alignment, HorDim, Length, LogicalRect, LogicalVector, + PickDimension, VerDim, WidgetPlacement, + }, + widget_data_ptr, + window::{RenderValidity, Window}, + DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, }, - widget_data_ptr, - window::{RenderValidity, Window}, - DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, }; pub type HorizontalLayoutContainer = LineLayoutContainer; diff --git a/src/gelatin/mod.rs b/src/gelatin/mod.rs index 9deee58f..a532a497 100644 --- a/src/gelatin/mod.rs +++ b/src/gelatin/mod.rs @@ -1,8 +1,7 @@ //! Idk man use std::{ - any::Any, error::Error, fmt, path::PathBuf, rc::Rc, - time::Instant, vec::Vec, + any::Any, error::Error, fmt, path::PathBuf, rc::Rc, time::Instant, vec::Vec, }; pub use cgmath; diff --git a/src/gelatin/picture.rs b/src/gelatin/picture.rs index f53d2b21..2e7773f7 100644 --- a/src/gelatin/picture.rs +++ b/src/gelatin/picture.rs @@ -4,8 +4,10 @@ use std::{ path, }; -use glium::texture::{MipmapsOption, RawImage2d, SrgbTexture2d}; -use glium::Display; +use glium::{ + texture::{MipmapsOption, RawImage2d, SrgbTexture2d}, + Display, +}; use image::{error::ImageError, RgbaImage}; pub struct PictureTextureRef<'a> { @@ -109,10 +111,7 @@ impl Picture { } } - fn upload_to_texture( - &self, - display: &Display, - ) -> Result<(), ImageError> { + fn upload_to_texture(&self, display: &Display) -> Result<(), ImageError> { let mut borrowed = self.data.borrow_mut(); let mut tmp_picture = PictureData::Path("".into()); std::mem::swap(&mut *borrowed, &mut tmp_picture); @@ -142,10 +141,7 @@ impl Picture { Ok(()) } - fn cpu_to_texture( - img: RgbaImage, - display: &Display, - ) -> SrgbTexture2d { + fn cpu_to_texture(img: RgbaImage, display: &Display) -> SrgbTexture2d { let image_dimensions = img.dimensions(); let image = RawImage2d::from_raw_rgba(img.into_raw(), image_dimensions); SrgbTexture2d::with_mipmaps( diff --git a/src/gelatin/slider.rs b/src/gelatin/slider.rs index a4a61632..6c94d4e6 100644 --- a/src/gelatin/slider.rs +++ b/src/gelatin/slider.rs @@ -1,17 +1,22 @@ use std::{cell::RefCell, rc::Rc}; use cgmath::{Matrix4, Vector3}; -use crate::add_common_widget_functions; -use crate::gelatin::{ - misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement}, - window::RenderValidity, - DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, WidgetError, -}; use glium::{ glutin::event::{ElementState, MouseButton}, - DrawParameters, - Blend, BlendingFunction, LinearBlendingFactor, - uniform, Frame, Surface, + uniform, Blend, BlendingFunction, DrawParameters, Frame, + LinearBlendingFactor, Surface, +}; + +use crate::{ + add_common_widget_functions, + gelatin::{ + misc::{ + Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement, + }, + window::RenderValidity, + DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, + WidgetError, + }, }; struct SliderData { diff --git a/src/gelatin/window.rs b/src/gelatin/window.rs index 683d9edc..9a2be9b9 100644 --- a/src/gelatin/window.rs +++ b/src/gelatin/window.rs @@ -8,23 +8,25 @@ use std::{ use cgmath::{ortho, Matrix4, Vector3}; use glium::{ - index::PrimitiveType, glutin::{ self, dpi::{PhysicalPosition, PhysicalSize}, event::WindowEvent, window::{CursorIcon, Icon, WindowId}, }, - program, uniform, Blend, BlendingFunction, Display, DrawParameters, Frame, IndexBuffer, - Program, Rect, Surface, VertexBuffer, + index::PrimitiveType, + program, uniform, Blend, BlendingFunction, Display, DrawParameters, Frame, + IndexBuffer, Program, Rect, Surface, VertexBuffer, }; use typed_builder::TypedBuilder; -use crate::VerticalLayoutContainer; -use crate::gelatin::{ - application::Application, - misc::{FromPhysical, LogicalRect, LogicalVector}, - shaders, DrawContext, Event, EventKind, NextUpdate, Vertex, Widget, +use crate::{ + gelatin::{ + application::Application, + misc::{FromPhysical, LogicalRect, LogicalVector}, + shaders, DrawContext, Event, EventKind, NextUpdate, Vertex, Widget, + }, + VerticalLayoutContainer, }; const EVENT_UPDATE_DELTA: std::time::Duration = @@ -146,8 +148,7 @@ impl Window { .with_gl_profile(glutin::GlProfile::Core) .with_vsync(true); let display = - Display::new(window, context, &application.event_loop) - .unwrap(); + Display::new(window, context, &application.event_loop).unwrap(); if let Some(pos) = desc.position { display.gl_window().window().set_outer_position(pos); @@ -243,9 +244,7 @@ impl Window { render_validity: RenderValidity { validity: Rc::new(Cell::new(false)), }, - root_widget: Rc::new( - VerticalLayoutContainer::new(), - ), + root_widget: Rc::new(VerticalLayoutContainer::new()), bg_color: [0.85, 0.85, 0.85, 1.0], global_event_handlers: Vec::new(), diff --git a/src/image_cache/directory.rs b/src/image_cache/directory.rs index 794a1a2c..87f27fbb 100644 --- a/src/image_cache/directory.rs +++ b/src/image_cache/directory.rs @@ -338,7 +338,9 @@ impl Directory { } fn set_image_index_from_file_index(&mut self) { - if let Some(Some(img_idx)) = self.file_i_to_img_i.get(self.curr_file_idx) { + if let Some(Some(img_idx)) = + self.file_i_to_img_i.get(self.curr_file_idx) + { self.curr_image_idx = *img_idx; } } diff --git a/src/image_cache/image_loader.rs b/src/image_cache/image_loader.rs index 1c8637b6..8efbfefa 100644 --- a/src/image_cache/image_loader.rs +++ b/src/image_cache/image_loader.rs @@ -18,11 +18,11 @@ use image::{ use resvg::{ tiny_skia::{Pixmap, Transform}, usvg::{self, TreeParsing}, - Tree, }; pub mod errors { use std::io; + use glium::texture; pub type Result = std::result::Result; @@ -181,7 +181,6 @@ pub fn load_svg(path: &std::path::Path) -> Result { let opt = usvg::Options::default(); let data = std::fs::read(path)?; let tree = usvg::Tree::from_data(&data, &opt)?; - let tree = Tree::from_usvg(&tree); let size = tree.size; let (width, height) = (size.width(), size.height()); // Scale to fit 4096 @@ -190,7 +189,11 @@ pub fn load_svg(path: &std::path::Path) -> Result { // These unwrapped Options are fine as long as the dimensions are correct let mut pixmap = Pixmap::new(width, height).unwrap(); - tree.render(Transform::from_scale(zoom, zoom), &mut pixmap.as_mut()); + resvg::render( + &tree, + Transform::from_scale(zoom, zoom), + &mut pixmap.as_mut(), + ); Ok(image::RgbaImage::from_raw(width, height, pixmap.take()).unwrap()) } diff --git a/src/image_cache/mod.rs b/src/image_cache/mod.rs index f51210f1..488706f5 100644 --- a/src/image_cache/mod.rs +++ b/src/image_cache/mod.rs @@ -28,7 +28,9 @@ use self::{ pub mod errors { use std::io; + use glium::texture; + use crate::image_cache::image_loader; pub type Result = std::result::Result; diff --git a/src/input_handling.rs b/src/input_handling.rs index 9d7e0077..348f25bb 100644 --- a/src/input_handling.rs +++ b/src/input_handling.rs @@ -1,5 +1,8 @@ -use std::{collections::HashMap, process::Command}; -use std::sync::{Arc, Mutex}; +use std::{ + collections::HashMap, + process::Command, + sync::{Arc, Mutex}, +}; use glium::glutin::event::ModifiersState; use lazy_static::lazy_static; diff --git a/src/main.rs b/src/main.rs index 4c43f052..9b75365a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use crate::{ configuration::{Configuration, Theme, WindowMode}, gelatin::{ application::*, - glium::glutin::{window::Icon}, + glium::glutin::window::Icon, image, label::*, line_layout_container::*, @@ -61,9 +61,8 @@ fn main() { let mut application = Application::new(); let window: Rc = { let cfg = &mut config.lock().unwrap(); - let window_desc = WindowDescriptor::builder() - .icon(Some(make_icon())) - .build(); + let window_desc = + WindowDescriptor::builder().icon(Some(make_icon())).build(); let window = Window::new(&mut application, window_desc); match cfg.window_mode() { diff --git a/src/playback_manager.rs b/src/playback_manager.rs index 839842cc..b22115d5 100644 --- a/src/playback_manager.rs +++ b/src/playback_manager.rs @@ -7,11 +7,13 @@ use std::{ time::{Duration, Instant}, }; -use crate::gelatin::{NextUpdate, glium::Display, window::Window}; use log::{debug, trace}; use rand::{seq::SliceRandom, thread_rng}; -use crate::image_cache::{self, AnimationFrameTexture, ImageCache}; +use crate::{ + gelatin::{glium::Display, window::Window, NextUpdate}, + image_cache::{self, AnimationFrameTexture, ImageCache}, +}; const NANOS_PER_SEC: u64 = 1_000_000_000; @@ -415,8 +417,7 @@ impl ImgSequencePlayer

{ match load_request { LoadRequest::Jump(0) => { // Waiting on current image to be loaded. - next_update = - NextUpdate::WaitUntil(few_millisecs_from_now); + next_update = NextUpdate::WaitUntil(few_millisecs_from_now); } _ => { image_cache.prefetch_neighbors(); @@ -499,8 +500,7 @@ impl ImgSequencePlayer

{ } } } else { - next_update = - NextUpdate::WaitUntil(few_millisecs_from_now); + next_update = NextUpdate::WaitUntil(few_millisecs_from_now); } match load_request { LoadRequest::None | LoadRequest::FilePath(..) => (), @@ -538,8 +538,7 @@ impl ImgSequencePlayer

{ // Set the load request to jump in place so that // next time we attempt to load this again. self.load_request = LoadRequest::Jump(0); - next_update = - NextUpdate::WaitUntil(few_millisecs_from_now); + next_update = NextUpdate::WaitUntil(few_millisecs_from_now); } Err(err) => { self.image_texture = None; diff --git a/src/widgets/bottom_bar.rs b/src/widgets/bottom_bar.rs index 79cefa06..6074b2f0 100644 --- a/src/widgets/bottom_bar.rs +++ b/src/widgets/bottom_bar.rs @@ -1,13 +1,15 @@ use std::{f32, rc::Rc}; -use crate::gelatin::{ - button::Button, - line_layout_container::HorizontalLayoutContainer, - misc::{Alignment, Length}, - picture::Picture, - slider::Slider, +use crate::{ + configuration::{ScalingMode, Theme}, + gelatin::{ + button::Button, + line_layout_container::HorizontalLayoutContainer, + misc::{Alignment, Length}, + picture::Picture, + slider::Slider, + }, }; -use crate::configuration::{ScalingMode, Theme}; static MOON: &[u8] = include_bytes!("../../resource/moon.png"); static LIGHT: &[u8] = include_bytes!("../../resource/light.png"); diff --git a/src/widgets/copy_notification.rs b/src/widgets/copy_notification.rs index 5f323da0..926a6a94 100644 --- a/src/widgets/copy_notification.rs +++ b/src/widgets/copy_notification.rs @@ -3,7 +3,9 @@ use std::{ time::{Duration, Instant}, }; -use crate::gelatin::{label::Label, misc::*, picture::Picture, NextUpdate, Widget}; +use crate::gelatin::{ + label::Label, misc::*, picture::Picture, NextUpdate, Widget, +}; static COPY_STARTED: &[u8] = include_bytes!("../../resource/copy-started.png"); static COPY_READY: &[u8] = include_bytes!("../../resource/copy-ready.png"); diff --git a/src/widgets/help_screen.rs b/src/widgets/help_screen.rs index 1b8972dc..50ff9c54 100644 --- a/src/widgets/help_screen.rs +++ b/src/widgets/help_screen.rs @@ -1,14 +1,18 @@ use std::{cell::RefCell, rc::Rc}; -use crate::add_common_widget_functions; -use crate::gelatin::{ - glium, - cgmath::{Matrix4, Vector3}, - glium::{uniform, Frame, Surface}, - misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement}, - picture::Picture, - window::RenderValidity, - DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, +use crate::{ + add_common_widget_functions, + gelatin::{ + cgmath::{Matrix4, Vector3}, + glium, + glium::{uniform, Frame, Surface}, + misc::{ + Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement, + }, + picture::Picture, + window::RenderValidity, + DrawContext, Event, NextUpdate, Widget, WidgetData, WidgetError, + }, }; struct HelpScreenData { @@ -133,15 +137,9 @@ impl Widget for HelpScreen { let texture = borrowed.usage_image.texture(context.display)?; let sampler = texture .sampled() - .wrap_function( - glium::uniforms::SamplerWrapFunction::Clamp, - ) - .minify_filter( - glium::uniforms::MinifySamplerFilter::Linear, - ) - .magnify_filter( - glium::uniforms::MagnifySamplerFilter::Linear, - ); + .wrap_function(glium::uniforms::SamplerWrapFunction::Clamp) + .minify_filter(glium::uniforms::MinifySamplerFilter::Linear) + .magnify_filter(glium::uniforms::MagnifySamplerFilter::Linear); let uniforms = uniform! { matrix: Into::<[[f32; 4]; 4]>::into(transform), tex: sampler, diff --git a/src/widgets/picture_widget.rs b/src/widgets/picture_widget.rs index 0f2cd1ee..5a1976db 100644 --- a/src/widgets/picture_widget.rs +++ b/src/widgets/picture_widget.rs @@ -13,12 +13,7 @@ use glium::{ uniforms::MagnifySamplerFilter, Display, Frame, Program, Surface, }; -use crate::gelatin::{ - application::request_exit, - misc::{Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement}, - window::{RenderValidity, Window}, - DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, WidgetError, -}; + use super::{ bottom_bar::BottomBar, copy_notification::CopyNotifications, help_screen::HelpScreen, @@ -27,6 +22,15 @@ use crate::{ add_common_widget_functions, clipboard_handler::ClipboardHandler, configuration::{Antialias, Configuration, ScalingMode}, + gelatin::{ + application::request_exit, + misc::{ + Alignment, Length, LogicalRect, LogicalVector, WidgetPlacement, + }, + window::{RenderValidity, Window}, + DrawContext, Event, EventKind, NextUpdate, Widget, WidgetData, + WidgetError, + }, image_cache::{image_loader::Orientation, AnimationFrameTexture}, input_handling::*, playback_manager::*, @@ -433,7 +437,10 @@ impl PictureWidgetData { pub fn set_automatic_antialias(&mut self) { self.antialiasing = Antialias::Auto; - self.config.lock().unwrap().set_antialiasing(Antialias::Auto); + self.config + .lock() + .unwrap() + .set_antialiasing(Antialias::Auto); self.render_validity.invalidate(); } @@ -1166,7 +1173,9 @@ fn draw_tex_grid( let sampler = cell_tex .tex .sampled() - .minify_filter(glium::uniforms::MinifySamplerFilter::LinearMipmapLinear) + .minify_filter( + glium::uniforms::MinifySamplerFilter::LinearMipmapLinear, + ) .wrap_function(glium::uniforms::SamplerWrapFunction::Clamp); let filter = match data.antialiasing {