From b7a469ee026dd59588b6bc3c29726f153644af9f Mon Sep 17 00:00:00 2001 From: Piyush Mishra Date: Fri, 14 Jan 2022 20:44:46 +0530 Subject: [PATCH] Design improvements --- reload.svg | 1 + src/config.rs | 2 +- src/config_window.rs | 6 +++--- src/crop_window.rs | 6 +++--- src/globals.rs | 12 ++++++++++-- src/main.rs | 8 +------- src/main_window.rs | 22 +++++++++++++++------- 7 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 reload.svg diff --git a/reload.svg b/reload.svg new file mode 100644 index 0000000..7d9e4c1 --- /dev/null +++ b/reload.svg @@ -0,0 +1 @@ + diff --git a/src/config.rs b/src/config.rs index 4ae0417..0a018cc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,7 @@ pub(crate) struct Args { } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ArgEnum)] -pub(crate) enum Themes { +pub enum Themes { Classic, /// Windows 7 Aero, diff --git a/src/config_window.rs b/src/config_window.rs index c68054b..b6918a9 100644 --- a/src/config_window.rs +++ b/src/config_window.rs @@ -40,9 +40,9 @@ pub(crate) struct ConfigWindow { impl ConfigWindow { pub(crate) fn new() -> Self { let mut win = Window::new(0, 0, 500, 300, "Config").center_screen(); - if let Ok(image) = SvgImage::from_data(&globals::ICON) { - win.set_icon(Some(image)); - } + win.set_icon(Some( + SvgImage::from_data(globals::ICON.to_str().unwrap()).unwrap(), + )); let mut col = Flex::default().with_size(490, 290).with_pos(5, 5).column(); diff --git a/src/crop_window.rs b/src/crop_window.rs index 1188d88..502f945 100644 --- a/src/crop_window.rs +++ b/src/crop_window.rs @@ -32,9 +32,9 @@ pub(crate) struct Page { impl CropWindow { pub(crate) fn new() -> Self { let mut win = Window::new(0, 0, 500, 600, "Crop").center_screen(); - if let Ok(image) = SvgImage::from_data(&globals::ICON) { - win.set_icon(Some(image)); - } + win.set_icon(Some( + SvgImage::from_data(globals::ICON.to_str().unwrap()).unwrap(), + )); let mut main_flex = Flex::default().size_of_parent().column(); diff --git a/src/globals.rs b/src/globals.rs index 2944faa..1d1c999 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -1,9 +1,10 @@ use crate::config; use lazy_static::lazy_static; use rusttype::Font; -use std::{io::Read, sync::RwLock}; +use std::{ffi::OsString, io::Read, sync::RwLock}; lazy_static! { + pub static ref THEME: config::Themes = config::config().theme.unwrap_or(config::Themes::System); pub static ref CONFIG: RwLock = RwLock::new(config::ConfigFile::load()); pub static ref FONT_QUOTE: Font<'static> = { let mut buffer = Vec::new(); @@ -28,5 +29,12 @@ lazy_static! { } rusttype::Font::try_from_vec(include_bytes!("../Kalam-Regular.ttf").to_vec()).unwrap() }; - pub static ref ICON: &'static str = include_str!("../icon.svg"); + pub static ref ICON: OsString = include_str!("../icon.svg").into(); + pub static ref RELOAD_ICON: OsString = { + let img = include_str!("../reload.svg"); + if let config::Themes::Dark = *THEME { + return img.replace("fill=\"black\"", "fill=\"white\"").into(); + } + img.into() + }; } diff --git a/src/main.rs b/src/main.rs index 8a7dafb..b07786f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,13 +26,7 @@ pub(crate) enum AppMessage { fn main() { let app = App::default(); - WidgetTheme::new( - config::config() - .theme - .unwrap_or(config::Themes::System) - .into(), - ) - .apply(); + WidgetTheme::new(globals::THEME.clone().into()).apply(); let draw_buff: Arc>> = Arc::new(RwLock::new(vec![])); let (main_sender, main_receiver) = channel::(); diff --git a/src/main_window.rs b/src/main_window.rs index e459f3c..e604e05 100644 --- a/src/main_window.rs +++ b/src/main_window.rs @@ -65,9 +65,11 @@ impl MainWindow { draw_buff: Arc>>, ) -> Self { let mut win = Window::new(0, 0, 1000, 600, "Post Maker").center_screen(); - if let Ok(image) = SvgImage::from_data(&globals::ICON) { - win.set_icon(Some(image)); - } + win.set_icon(Some( + SvgImage::from_data(globals::ICON.to_str().unwrap()).unwrap(), + )); + + let reload_image = SvgImage::from_data(globals::RELOAD_ICON.to_str().unwrap()).unwrap(); let mut main_flex = Flex::default().size_of_parent().column(); let menubar = menu::SysMenuBar::default(); @@ -81,7 +83,8 @@ impl MainWindow { let save_btn = Button::default().with_label("Save"); toolbar_flex.set_size(&save_btn, 50); let file_choice = menu::Choice::default(); - let reset_file_choice = Button::default().with_label("@returnarrow"); + let mut reset_file_choice = Button::default(); + reset_file_choice.set_image(Some(reload_image.clone())); toolbar_flex.set_size(&reset_file_choice, 30); toolbar_flex.end(); main_flex.set_size(&toolbar_flex, 30); @@ -110,7 +113,8 @@ impl MainWindow { Frame::default() .with_label("Dark Layer (RGBA):") .with_align(enums::Align::Left | enums::Align::Inside); - let reset_darklayer_btn = Button::default().with_label("@returnarrow"); + let mut reset_darklayer_btn = Button::default(); + reset_darklayer_btn.set_image(Some(reload_image.clone())); darklayer_head_flex.set_size(&reset_darklayer_btn, 30); darklayer_head_flex.end(); controls_flex.set_size(&darklayer_head_flex, 30); @@ -141,13 +145,15 @@ impl MainWindow { .with_label("Quote Position:") .with_align(enums::Align::Left | enums::Align::Inside); let quote_position = fltk::misc::Spinner::default(); - let reset_quote_position_btn = Button::default().with_label("@returnarrow"); + let mut reset_quote_position_btn = Button::default(); + reset_quote_position_btn.set_image(Some(reload_image.clone())); quote_position_flex.set_size(&reset_quote_position_btn, 30); quote_position_flex.end(); controls_flex.set_size("e_position_flex, 30); let mut quote_position_slider = Slider::default().with_type(SliderType::HorizontalNice); quote_position_slider.set_step(1.0, 1); + quote_position_slider.set_frame(enums::FrameType::NoBox); controls_flex.set_size("e_position_slider, 30); let mut tag_position_flex = Flex::default().row(); @@ -155,13 +161,15 @@ impl MainWindow { .with_label("Tag Position:") .with_align(enums::Align::Left | enums::Align::Inside); let tag_position = fltk::misc::Spinner::default(); - let reset_tag_position_btn = Button::default().with_label("@returnarrow"); + let mut reset_tag_position_btn = Button::default(); + reset_tag_position_btn.set_image(Some(reload_image.clone())); tag_position_flex.set_size(&reset_tag_position_btn, 30); tag_position_flex.end(); controls_flex.set_size(&tag_position_flex, 30); let mut tag_position_slider = Slider::default().with_type(SliderType::HorizontalNice); tag_position_slider.set_step(1.0, 1); + tag_position_slider.set_frame(enums::FrameType::NoBox); controls_flex.set_size(&tag_position_slider, 30); let mut actions_flex = Flex::default().row();