From 9b391d71ce7a55f0f255699a1cc296fbe82761f5 Mon Sep 17 00:00:00 2001 From: Pablo Ovelleiro Corral Date: Thu, 8 Aug 2024 01:27:17 +0200 Subject: [PATCH] make font size configurable --- client/src/component/divider.rs | 10 +++++++--- client/src/component/entry.rs | 22 +++++++++++++--------- client/src/component/plugin_header.rs | 14 ++++++++------ client/src/component/query_input.rs | 11 +++++++---- client/src/main.rs | 7 ++----- client/src/settings.rs | 7 +++++++ 6 files changed, 44 insertions(+), 27 deletions(-) diff --git a/client/src/component/divider.rs b/client/src/component/divider.rs index d3ee51d..a3cce62 100644 --- a/client/src/component/divider.rs +++ b/client/src/component/divider.rs @@ -1,14 +1,18 @@ +use crate::Settings; pub fn view() -> iced::Element<'static, crate::Message> { + + + let font_size = Settings::get_or_init().font.size; iced::widget::column![iced::widget::horizontal_rule(1)] .padding(iced::Padding::from([ - 1. * crate::REM, + 1. * font_size, 0., - 0.5 * crate::REM, + 0.5 * font_size, 0., ])) // We're fixing the height here to unify it // with the height of entries for a smooth // scrolling experience - .height(crate::ENTRY_HEIGHT) + .height(Settings::entry_height()) .into() } diff --git a/client/src/component/entry.rs b/client/src/component/entry.rs index 392d8f1..c1743c5 100644 --- a/client/src/component/entry.rs +++ b/client/src/component/entry.rs @@ -1,22 +1,27 @@ +use crate::Settings; + pub fn view(entry: &crate::model::Entry, active: bool) -> iced::Element<'static, crate::Message> { + let font_size = Settings::get_or_init().font.size; + return iced::widget::container( iced::widget::container( iced::widget::row![ iced::widget::text(clipped_title(entry.title.clone())) - .size(1. * crate::REM) + .size(1. * font_size) .width(iced::Length::Fill) .shaping(iced::widget::text::Shaping::Advanced), - iced::widget::text(if active { &entry.action } else { "" }).size(1. * crate::REM) + iced::widget::text(if active { &entry.action } else { "" }) + .size(1. * font_size) ] - .padding(0.5 * crate::REM), + .padding(0.5 * font_size), ) .style(style(active)), ) // We're fixing the height here to unify it // with the height of plugin headers for a smooth // scrolling experience - .height(crate::ENTRY_HEIGHT) - .padding(iced::Padding::from([0., 0.75 * crate::REM])) + .height(font_size) + .padding(iced::Padding::from([0., 0.75 * font_size])) .into(); } @@ -48,14 +53,13 @@ impl iced::widget::container::StyleSheet for Style { type Style = iced::Theme; fn appearance(&self, _style: &Self::Style) -> iced::widget::container::Appearance { - let color_settings = crate::settings::Settings::get_or_init(); - + let settings = crate::settings::Settings::get_or_init(); iced::widget::container::Appearance { background: None, border: iced::Border { - color: crate::settings::hexcolor(&color_settings.color.text), + color: crate::settings::hexcolor(&settings.color.text), width: 1.0, - radius: iced::border::Radius::from(0.1 * crate::REM), + radius: iced::border::Radius::from(0.1 * settings.font.size), }, text_color: None, shadow: iced::Shadow::default(), diff --git a/client/src/component/plugin_header.rs b/client/src/component/plugin_header.rs index c7b2bf9..d83b43f 100644 --- a/client/src/component/plugin_header.rs +++ b/client/src/component/plugin_header.rs @@ -1,4 +1,6 @@ +use crate::Settings; pub fn view(plugin: &crate::model::Plugin) -> iced::Element<'static, crate::Message> { + let font_size = Settings::get_or_init().font.size; iced::widget::row![iced::widget::text(&plugin.title) .font(iced::Font { family: iced::font::Family::Name("FiraCode Nerd Font"), @@ -6,16 +8,16 @@ pub fn view(plugin: &crate::model::Plugin) -> iced::Element<'static, crate::Mess stretch: iced::font::Stretch::Normal, style: iced::font::Style::default(), }) - .size(0.75 * crate::REM)] + .size(0.75 * font_size)] // We're fixing the height here to unify it // with the height of entries for a smooth // scrolling experience - .height(crate::ENTRY_HEIGHT) + .height(Settings::entry_height()) .padding(iced::Padding::from([ - 0.8 * crate::REM, - 1.25 * crate::REM, - 0.5 * crate::REM, - 1.25 * crate::REM, + 0.8 * font_size, + 1.25 * font_size, + 0.5 * font_size, + 1.25 * font_size, ])) .into() } diff --git a/client/src/component/query_input.rs b/client/src/component/query_input.rs index bd2fc29..5722313 100644 --- a/client/src/component/query_input.rs +++ b/client/src/component/query_input.rs @@ -1,17 +1,20 @@ +use crate::Settings; pub const SEARCH_INPUT_ID: &str = "search_input"; pub fn view(query: &str, add_horizontal_rule: bool) -> iced::Element<'static, crate::Message> { + + let font_size = Settings::get_or_init().font.size; let mut view = iced::widget::column![iced::widget::row![ - iced::widget::container(iced::widget::text("󰍉 ").size(1.3 * crate::REM)).padding( - iced::Padding::from([0.2 * crate::REM, -0.3 * crate::REM, 0., 0.]) + iced::widget::container(iced::widget::text("󰍉 ").size(1.3 * font_size)).padding( + iced::Padding::from([0.2 * font_size, -0.3 * font_size, 0., 0.]) ), iced::widget::text_input("Search", query) .id(iced::widget::text_input::Id::new(SEARCH_INPUT_ID)) .on_input(crate::Message::Search) - .size(1. * crate::REM) + .size(1. * font_size) .style(style()) ] - .padding(iced::Padding::from([0.8 * crate::REM, 1.2 * crate::REM])),] + .padding(iced::Padding::from([0.8 * font_size, 1.2 * font_size])),] .padding(iced::Padding::from([0., 0., 1., 0.])); if add_horizontal_rule { diff --git a/client/src/main.rs b/client/src/main.rs index eca6507..020bb5d 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -309,7 +309,7 @@ impl Application for Centerpiece { impl Centerpiece { fn settings(flags: crate::cli::CliArgs) -> iced::Settings { - let default_text_size = iced::Pixels(crate::REM); + let default_text_size = iced::Pixels(40.0); let default_font = iced::Font { family: iced::font::Family::Name(&Settings::get_or_init().font.default), @@ -509,9 +509,6 @@ impl Centerpiece { } } -pub const REM: f32 = 14.0; -pub const ENTRY_HEIGHT: f32 = 2.3 * crate::REM; - struct SandboxStyle {} impl iced::application::StyleSheet for SandboxStyle { type Style = iced::Theme; @@ -539,7 +536,7 @@ impl iced::widget::container::StyleSheet for ApplicationWrapperStyle { border: iced::Border { color: iced::Color::TRANSPARENT, width: 0., - radius: iced::border::Radius::from(0.25 * crate::REM), + radius: iced::border::Radius::from(0.25 * Settings::get_or_init().font.size), }, text_color: None, shadow: iced::Shadow::default(), diff --git a/client/src/settings.rs b/client/src/settings.rs index 744ffeb..c67b362 100644 --- a/client/src/settings.rs +++ b/client/src/settings.rs @@ -119,6 +119,7 @@ pub struct GitRepositoriesPluginSettings { #[derive(Debug, Deserialize)] pub struct FontSettings { pub default: String, + pub size: f32, } #[derive(Debug, Deserialize)] @@ -132,6 +133,7 @@ impl Default for FontSettings { fn default() -> Self { Self { default: "FiraCode Nerd Font".to_string(), + size: 14.0, } } } @@ -315,6 +317,7 @@ pub struct Settings { } impl Settings { + pub fn new() -> Self { let config_directory_result = crate::plugin::utils::centerpiece_config_directory(); if let Err(error) = config_directory_result { @@ -348,6 +351,10 @@ impl Settings { static SETTINGS: OnceLock = OnceLock::new(); SETTINGS.get_or_init(Self::new) } + + pub fn entry_height() -> f32 { + Self::get_or_init().font.size * 2.3 + } } impl std::convert::TryFrom for Settings {