Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rfd = "0.15.0"
imagesize = "0.13.0"
eframe = { version = "0.29.1", features = ["default"] }
egui_extras = { version = "0.29.1", features = ["all_loaders"]}
image = {version = "0.25.5", features = ["jpeg", "png"]}
image = {version = "0.25.5"}
egui_animation = "0.6.0"
simple-easing = "1.0.1"
log = "0.4.22"
Expand All @@ -32,6 +32,7 @@ serde = {version = "1.0.215", features = ["derive"]}
serde_derive = "1.0.215"
dirs = "5.0.1"
toml = "0.8.19"
rayon = "1.10.0"

[profile.dev.package."*"]
opt-level = 3
57 changes: 31 additions & 26 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use cirrus_theming::v1::Theme;
use eframe::egui::{self, Align, Color32, Context, CursorIcon, Frame, ImageSource, Layout, Margin, Rect, Shadow, Stroke, Style, TextStyle, Vec2};
use egui_notify::ToastLevel;


use crate::{config::config::Config, files, image::Image, image_loader::ImageLoader, info_box::InfoBox, magnification_panel::MagnificationPanel, toasts::ToastsManager, window_scaling::WindowScaling, zoom_pan::ZoomPan};
use crate::{config::config::Config, files, image::image::Image, image_loader::ImageLoader, info_box::InfoBox, magnification_panel::MagnificationPanel, notifier::NotifierAPI, window_scaling::WindowScaling, zoom_pan::ZoomPan};

pub struct Roseate {
theme: Theme,
image: Option<Image>,
zoom_pan: ZoomPan,
info_box: InfoBox,
toasts: ToastsManager,
notifier: NotifierAPI,
magnification_panel: MagnificationPanel,
window_scaling: WindowScaling,
last_window_rect: Rect,
Expand All @@ -21,21 +20,25 @@ pub struct Roseate {
}

impl Roseate {
pub fn new(image: Option<Image>, theme: Theme, mut toasts: ToastsManager, config: Config) -> Self {
pub fn new(image: Option<Image>, theme: Theme, mut notifier: NotifierAPI, config: Config) -> Self {
let mut image_loader = ImageLoader::new();

if image.is_some() {
image_loader.load_image(&mut image.clone().unwrap(), config.image.loading.initial.lazy_loading);
image_loader.load_image(
&mut image.clone().unwrap(),
config.image.loading.initial.lazy_loading,
&mut notifier
);
}

let zoom_pan = ZoomPan::new(&config, &mut toasts);
let info_box = InfoBox::new(&config, &mut toasts);
let magnification_panel = MagnificationPanel::new(&config, &mut toasts);
let zoom_pan = ZoomPan::new(&config, &mut notifier);
let info_box = InfoBox::new(&config, &mut notifier);
let magnification_panel = MagnificationPanel::new(&config, &mut notifier);

Self {
image,
theme,
toasts,
notifier,
zoom_pan,
info_box,
magnification_panel,
Expand Down Expand Up @@ -118,7 +121,7 @@ impl eframe::App for Roseate {
}
}

self.toasts.update(ctx);
self.notifier.update(ctx);

if self.image.is_none() {
// Collect dropped files.
Expand All @@ -134,7 +137,7 @@ impl eframe::App for Roseate {
let mut image = Image::from_path(path);

self.image = Some(image.clone());
self.image_loader.load_image(&mut image, true);
self.image_loader.load_image(&mut image, true, &mut self.notifier);
}
});

Expand Down Expand Up @@ -176,10 +179,10 @@ impl eframe::App for Roseate {
Ok(mut image) => {
self.image = Some(image.clone());

self.image_loader.load_image(&mut image, self.config.image.loading.gui.lazy_loading);
self.image_loader.load_image(&mut image, self.config.image.loading.gui.lazy_loading, &mut self.notifier);
},
Err(error) => {
self.toasts.toast_and_log(error.into(), ToastLevel::Error)
self.notifier.toasts.lock().unwrap().toast_and_log(error.into(), ToastLevel::Error)
.duration(Some(Duration::from_secs(5)));
},
}
Expand Down Expand Up @@ -210,7 +213,7 @@ impl eframe::App for Roseate {

self.info_box.update(ctx);
self.zoom_pan.update(ctx);
self.image_loader.update(&mut self.toasts);
self.image_loader.update();
self.magnification_panel.update(ctx, &mut self.zoom_pan);

let image = self.image.clone().unwrap();
Expand Down Expand Up @@ -275,18 +278,20 @@ impl eframe::App for Roseate {
Frame::none()
.outer_margin(Margin {left: 10.0, bottom: 7.0, ..Default::default()})
).show(ctx, |ui| {
if let Some(loading) = &self.image_loader.image_loading {
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
ui.add(
egui::Spinner::new()
.color(Color32::from_hex("#e05f78").unwrap()) // NOTE: This should be the default accent colour.
.size(20.0)
);

if let Some(message) = &loading.message {
ui.label(message);
}
});
if let Ok(loading_status) = self.notifier.loading_status.try_read() {
if let Some(loading) = loading_status.as_ref() {
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
ui.add(
egui::Spinner::new()
.color(Color32::from_hex("#e05f78").unwrap()) // NOTE: This should be the default accent colour.
.size(20.0)
);

if let Some(message) = &loading.message {
ui.label(message);
}
});
}
}
}
);
Expand Down
14 changes: 10 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::{self, Display, Formatter}, path::PathBuf};

#[derive(Debug, Clone)]
pub enum Error {
FileNotFound(PathBuf),
FileNotFound(PathBuf, Option<String>),
NoFileSelected,
FailedToApplyOptimizations(String),
ImageFormatNotSupported(String),
Expand All @@ -19,9 +19,15 @@ impl Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Error::FileNotFound(path) => write!(
f, "The file path given '{}' does not exist!", path.to_string_lossy()
),
Error::FileNotFound(path, error) => {
let mut msg = format!("The file path given '{}' does not exist!", path.to_string_lossy());

if let Some(error_msg) = error {
msg += &format!("Error: {}", error_msg);
}

write!(f, "{}", msg)
},
Error::NoFileSelected => write!(
f, "No file was selected in the file dialogue!"
),
Expand Down
4 changes: 2 additions & 2 deletions src/files.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rfd::FileDialog;

use crate::error::Error;
use crate::image::Image;
use crate::image::image::Image;

pub fn select_image() -> Result<Image, Error> {
let image_path = FileDialog::new()
Expand All @@ -11,7 +11,7 @@ pub fn select_image() -> Result<Image, Error> {
let image_or_error = match image_path {
Some(path) => {
if !path.exists() {
Err(Error::FileNotFound(path))
Err(Error::FileNotFound(path, None))
} else {
Ok(Image::from_path(&path))
}
Expand Down
Loading