Skip to content

Commit

Permalink
Resvg 0.38
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Jan 31, 2024
1 parent a2749b7 commit d610885
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 118 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ 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"
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]
Expand Down
44 changes: 34 additions & 10 deletions src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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,
Maximized,
Fullscreen,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum Theme {
#[default]
Light,
Expand All @@ -29,15 +34,19 @@ 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,
FitStretch,
FitMin,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[derive(
Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize,
)]
pub enum Antialias {
#[default]
Auto,
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
17 changes: 11 additions & 6 deletions src/gelatin/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions src/gelatin/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions src/gelatin/line_layout_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HorDim>;
Expand Down
3 changes: 1 addition & 2 deletions src/gelatin/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
16 changes: 6 additions & 10 deletions src/gelatin/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 14 additions & 9 deletions src/gelatin/slider.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
25 changes: 12 additions & 13 deletions src/gelatin/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion src/image_cache/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/image_cache/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = (), E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -181,7 +181,6 @@ pub fn load_svg(path: &std::path::Path) -> Result<image::RgbaImage> {
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
Expand All @@ -190,7 +189,11 @@ pub fn load_svg(path: &std::path::Path) -> Result<image::RgbaImage> {
// 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())
}
Expand Down
2 changes: 2 additions & 0 deletions src/image_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use self::{

pub mod errors {
use std::io;

use glium::texture;

use crate::image_cache::image_loader;

pub type Result<T = (), E = Error> = std::result::Result<T, E>;
Expand Down
7 changes: 5 additions & 2 deletions src/input_handling.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading

0 comments on commit d610885

Please sign in to comment.