Skip to content

Commit

Permalink
make font size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pinpox committed Aug 7, 2024
1 parent 241af7c commit 9b391d7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
10 changes: 7 additions & 3 deletions client/src/component/divider.rs
Original file line number Diff line number Diff line change
@@ -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()
}
22 changes: 13 additions & 9 deletions client/src/component/entry.rs
Original file line number Diff line number Diff line change
@@ -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();
}

Expand Down Expand Up @@ -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(),
Expand Down
14 changes: 8 additions & 6 deletions client/src/component/plugin_header.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
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"),
weight: iced::font::Weight::Light,
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()
}
11 changes: 7 additions & 4 deletions client/src/component/query_input.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Application for Centerpiece {

impl Centerpiece {
fn settings(flags: crate::cli::CliArgs) -> iced::Settings<crate::cli::CliArgs> {
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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
7 changes: 7 additions & 0 deletions client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct GitRepositoriesPluginSettings {
#[derive(Debug, Deserialize)]
pub struct FontSettings {
pub default: String,
pub size: f32,
}

#[derive(Debug, Deserialize)]
Expand All @@ -132,6 +133,7 @@ impl Default for FontSettings {
fn default() -> Self {
Self {
default: "FiraCode Nerd Font".to_string(),
size: 14.0,
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -348,6 +351,10 @@ impl Settings {
static SETTINGS: OnceLock<Settings> = 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<crate::cli::CliArgs> for Settings {
Expand Down

0 comments on commit 9b391d7

Please sign in to comment.