diff --git a/.gitignore b/.gitignore index 2d6d3d7..24b9bed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /target +.fleet .idea flamegraph.svg perf.data -perf.data.old \ No newline at end of file +perf.data.old diff --git a/src/app/style/app.rs b/src/app/style/app.rs index ebafc2f..4d263fe 100644 --- a/src/app/style/app.rs +++ b/src/app/style/app.rs @@ -1,6 +1,7 @@ use crate::app::style::scrollable::scroller::ScrollerStyles; use crate::app::style::scrollable::RowContainerStyle; use crate::app::style::search::SearchContainerStyles; +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use iced_core::{Background, BorderRadius}; @@ -29,6 +30,18 @@ pub struct AppContainerStyles { pub scrollable: ScrollerStyles, } +impl Scale for AppContainerStyles { + fn scale(mut self, scale: f32) -> Self { + self.search = self.search.scale(scale); + self.padding = self.padding * scale; + self.rows = self.rows.scale(scale); + self.search = self.search.scale(scale); + self.scrollable = self.scrollable.scale(scale); + self.border_width = self.border_width.scale(scale); + self + } +} + impl StyleSheet for &AppContainerStyles { type Style = iced::Theme; diff --git a/src/app/style/mod.rs b/src/app/style/mod.rs index aea9e86..940cff2 100644 --- a/src/app/style/mod.rs +++ b/src/app/style/mod.rs @@ -6,9 +6,10 @@ use crate::app::style::search::SearchContainerStyles; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use crate::THEME_PATH; +use crate::THEME_SCALE; use iced::widget::container::Appearance; use iced::Background; -use iced_core::BorderRadius; +use iced_core::{BorderRadius, Length}; use tracing::{error, warn}; pub mod app; @@ -25,10 +26,19 @@ impl Theme { warn!("Failing back to default theme"); }; - theme.unwrap_or_default() + let mut theme = theme.unwrap_or_default(); + if let Some(scale) = THEME_SCALE.get() { + theme = theme.scale(*scale) + } + + theme } } +pub(crate) trait Scale { + fn scale(self, scale: f32) -> Self; +} + impl AsRef for Theme { fn as_ref(&self) -> &Theme { self @@ -57,6 +67,39 @@ pub struct Theme { pub app_container: AppContainerStyles, } +impl Scale for Theme { + fn scale(mut self, scale: f32) -> Self { + self.app_container = self.app_container.scale(scale); + self.icon_size = (self.icon_size as f32 * scale) as u16; + self.size.0 = (self.size.0 as f32 * scale) as u32; + self.size.1 = (self.size.1 as f32 * scale) as u32; + self.padding = self.padding * scale; + self.font_size = (self.font_size as f32 * scale) as u16; + self + } +} + +impl Scale for Length { + fn scale(self, scale: f32) -> Self { + match self { + Length::Fixed(size) => Length::Fixed(size * scale), + _ => self, + } + } +} + +impl Scale for u16 { + fn scale(self, scale: f32) -> Self { + (self as f32 * scale) as u16 + } +} + +impl Scale for f32 { + fn scale(self, scale: f32) -> Self { + self * scale + } +} + impl Theme { pub fn search(&self) -> &SearchContainerStyles { &self.app_container.search diff --git a/src/app/style/rows/generic.rs b/src/app/style/rows/generic.rs index 618a044..31948b2 100644 --- a/src/app/style/rows/generic.rs +++ b/src/app/style/rows/generic.rs @@ -1,3 +1,4 @@ +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use iced::alignment::{Horizontal, Vertical}; @@ -23,6 +24,16 @@ pub struct GenericContainerStyle { pub height: Length, } +impl Scale for GenericContainerStyle { + fn scale(mut self, scale: f32) -> Self { + self.height = self.height.scale(scale); + self.width = self.width.scale(scale); + self.font_size = self.font_size.scale(scale); + self.border_width = self.border_width.scale(scale); + self.padding = self.padding.scale(scale); + self + } +} impl Default for GenericContainerStyle { fn default() -> Self { GenericContainerStyle { diff --git a/src/app/style/rows/icon.rs b/src/app/style/rows/icon.rs index 9b08144..c2f17fd 100644 --- a/src/app/style/rows/icon.rs +++ b/src/app/style/rows/icon.rs @@ -1,3 +1,4 @@ +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use iced::alignment::{Horizontal, Vertical}; @@ -21,6 +22,17 @@ pub struct IconStyle { pub icon_size: u16, } +impl Scale for IconStyle { + fn scale(mut self, scale: f32) -> Self { + self.height = self.height.scale(scale); + self.width = self.width.scale(scale); + self.padding = self.padding.scale(scale); + self.border_width = self.border_width.scale(scale); + self.icon_size = self.icon_size.scale(scale); + self + } +} + impl Eq for IconStyle {} impl Default for IconStyle { diff --git a/src/app/style/rows/mod.rs b/src/app/style/rows/mod.rs index 9c8c423..0c50fe1 100644 --- a/src/app/style/rows/mod.rs +++ b/src/app/style/rows/mod.rs @@ -1,3 +1,4 @@ +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use generic::GenericContainerStyle; @@ -37,6 +38,19 @@ pub struct RowStyles { pub category_icon: IconStyle, } +impl Scale for RowStyles { + fn scale(mut self, scale: f32) -> Self { + self.height = self.height.scale(scale); + self.width = self.width.scale(scale); + self.spacing = self.spacing.scale(scale); + self.border_width = self.border_width.scale(scale); + self.title = self.title.scale(scale); + self.description = self.description.scale(scale); + self.icon = self.icon.scale(scale); + self.category_icon = self.category_icon.scale(scale); + self + } +} impl StyleSheet for &RowStyles { type Style = iced::Theme; diff --git a/src/app/style/scrollable/mod.rs b/src/app/style/scrollable/mod.rs index 00caee4..2420a88 100644 --- a/src/app/style/scrollable/mod.rs +++ b/src/app/style/scrollable/mod.rs @@ -1,4 +1,5 @@ use crate::app::style::rows::RowStyles; +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use iced::Length; @@ -26,6 +27,18 @@ pub struct RowContainerStyle { pub row_selected: RowStyles, } +impl Scale for RowContainerStyle { + fn scale(mut self, scale: f32) -> Self { + self.padding = self.padding.scale(scale); + self.border_width = self.border_width.scale(scale); + self.width = self.width.scale(scale); + self.height = self.height.scale(scale); + self.row = self.row.scale(scale); + self.row_selected = self.row_selected.scale(scale); + self + } +} + impl Eq for RowContainerStyle {} impl StyleSheet for &RowContainerStyle { diff --git a/src/app/style/scrollable/scroller.rs b/src/app/style/scrollable/scroller.rs index ae2b3b8..01c8578 100644 --- a/src/app/style/scrollable/scroller.rs +++ b/src/app/style/scrollable/scroller.rs @@ -1,3 +1,4 @@ +use crate::app::style::Scale; use crate::config::color::OnagreColor; use iced::widget::scrollable::Scrollbar; use iced::Background; @@ -20,6 +21,17 @@ pub struct ScrollerStyles { pub scroller_width: u16, } +impl Scale for ScrollerStyles { + fn scale(mut self, scale: f32) -> Self { + self.border_width = self.border_width.scale(scale); + self.scroller_border_width = self.scroller_border_width.scale(scale); + self.scrollbar_margin = self.scrollbar_margin.scale(scale); + self.scrollbar_width = self.scrollbar_width.scale(scale); + self.scroller_width = self.scroller_width.scale(scale); + self + } +} + impl Eq for ScrollerStyles {} impl Default for ScrollerStyles { diff --git a/src/app/style/search/input.rs b/src/app/style/search/input.rs index 6d03f29..d773aad 100644 --- a/src/app/style/search/input.rs +++ b/src/app/style/search/input.rs @@ -1,3 +1,4 @@ +use crate::app::style::Scale; use crate::config::color::OnagreColor; use crate::config::padding::OnagrePadding; use iced::alignment::{Horizontal, Vertical}; @@ -26,6 +27,17 @@ pub struct SearchInputStyles { pub padding: OnagrePadding, } +impl Scale for SearchInputStyles { + fn scale(mut self, scale: f32) -> Self { + self.height = self.height.scale(scale); + self.width = self.width.scale(scale); + self.padding = self.padding.scale(scale); + self.padding = self.padding.scale(scale); + self.padding = self.padding.scale(scale); + self + } +} + impl Eq for SearchInputStyles {} impl StyleSheet for &SearchInputStyles { diff --git a/src/app/style/search/mod.rs b/src/app/style/search/mod.rs index 042551b..a1098b1 100644 --- a/src/app/style/search/mod.rs +++ b/src/app/style/search/mod.rs @@ -1,12 +1,15 @@ -use crate::app::style::rows::generic::GenericContainerStyle; -use crate::config::color::OnagreColor; -use crate::config::padding::OnagrePadding; use iced::alignment::{Horizontal, Vertical}; use iced::Length; use iced_core::{Background, BorderRadius}; use iced_style::container::{Appearance, StyleSheet}; + use input::SearchInputStyles; +use crate::app::style::rows::generic::GenericContainerStyle; +use crate::app::style::Scale; +use crate::config::color::OnagreColor; +use crate::config::padding::OnagrePadding; + pub mod hint; pub mod input; @@ -32,6 +35,18 @@ pub struct SearchContainerStyles { pub plugin_hint: Option, } +impl Scale for SearchContainerStyles { + fn scale(mut self, scale: f32) -> Self { + self.padding = self.padding.scale(scale); + self.border_width = self.border_width.scale(scale); + self.spacing = self.spacing.scale(scale); + self.width = self.width.scale(scale); + self.height = self.height.scale(scale); + self.input = self.input.scale(scale); + self + } +} + impl Eq for SearchContainerStyles {} impl StyleSheet for &SearchContainerStyles { diff --git a/src/config/padding.rs b/src/config/padding.rs index 0637e5b..d3bbe0a 100644 --- a/src/config/padding.rs +++ b/src/config/padding.rs @@ -1,4 +1,6 @@ +use crate::app::style::Scale; use iced::Padding; +use std::ops::Mul; #[derive(Debug, PartialEq, Clone)] pub struct OnagrePadding { @@ -8,6 +10,25 @@ pub struct OnagrePadding { pub left: u16, } +impl Mul for OnagrePadding { + type Output = OnagrePadding; + + fn mul(self, rhs: f32) -> Self::Output { + OnagrePadding { + top: (self.top as f32 * rhs) as u16, + right: (self.right as f32 * rhs) as u16, + bottom: (self.bottom as f32 * rhs) as u16, + left: (self.left as f32 * rhs) as u16, + } + } +} + +impl Scale for OnagrePadding { + fn scale(self, scale: f32) -> Self { + self * scale + } +} + impl OnagrePadding { pub const ZERO: OnagrePadding = OnagrePadding { top: 0, diff --git a/src/main.rs b/src/main.rs index 0b05b03..8aa5788 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::sync::Mutex; use anyhow::anyhow; use clap::Parser; -use once_cell::sync::Lazy; +use once_cell::sync::{Lazy, OnceCell}; use tracing::{debug, info}; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -25,10 +25,12 @@ pub static THEME_PATH: Lazy> = Lazy::new(|| { ) }); +static THEME_SCALE: OnceCell = OnceCell::new(); + pub static THEME: Lazy = Lazy::new(Theme::load); #[derive(Parser)] -#[structopt(name = "onagre", author = "Paul D. ")] +#[command(name = "onagre", author = "Paul D. ")] struct Cli { #[arg( long = "theme", @@ -37,6 +39,9 @@ struct Cli { )] theme: Option, + #[arg(long = "scale", short = 's', help = "Change the scale of onagre theme")] + scale: Option, + #[arg(long = "mode", short = 'm', help = "The mode parameter as a string")] mode: Option, } @@ -51,6 +56,7 @@ pub fn main() -> iced::Result { info!("Starting onagre"); let cli = Cli::parse(); + // User defined theme config, $XDG_CONFIG_DIR/onagre/theme.toml otherwise if let Some(theme_path) = cli.theme { let path = theme_path.canonicalize(); @@ -61,6 +67,11 @@ pub fn main() -> iced::Result { info!("Using alternate theme : {:?}", THEME_PATH.lock().unwrap()); } + if let Some(scale) = cli.scale { + THEME_SCALE.get_or_init(|| scale); + info!("Using scale value : {:?}", scale); + } + if let Some(mode) = cli.mode { debug!("Mode parameter: {:?}", mode);