Skip to content

Commit

Permalink
Merge pull request #234 from squidowl/feat/scale
Browse files Browse the repository at this point in the history
expose scale_factor from iced
  • Loading branch information
casperstorm authored Feb 25, 2024
2 parents 9bc18ca + 217ae93 commit 6c39210
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Added:

- Option to colorize nicks in the nick list (and an option to control it separately from in the buffer)
- Option to control application scale factor

Fixed:

Expand Down
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ font:
# - Default is 13
size: 13

# Scale factor
# A scale factor of 2.0 will make the UI twice as big, while a scale factor of 0.5 will shrink it to half its size.
# Default is 1.0.
scale_factor: 1.0

# Buffer settings
buffer:
# Nickname settings
Expand Down
10 changes: 10 additions & 0 deletions data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Config {
pub themes: Themes,
pub servers: ServerMap,
pub font: Font,
pub scale_factor: f64,
pub buffer: Buffer,
pub dashboard: Dashboard,
pub keys: Keys,
Expand Down Expand Up @@ -92,6 +93,8 @@ impl Config {
pub servers: ServerMap,
#[serde(default)]
pub font: Font,
#[serde(default = "default_scale_factor")]
pub scale_factor: f64,
#[serde(default, alias = "new_buffer")]
pub buffer: Buffer,
#[serde(default)]
Expand All @@ -109,6 +112,7 @@ impl Config {
theme,
servers,
font,
scale_factor,
buffer,
dashboard,
keys,
Expand All @@ -117,11 +121,13 @@ impl Config {
.map_err(|e| Error::Parse(e.to_string()))?;

let themes = Self::load_themes(&theme).unwrap_or_default();
let scale_factor = scale_factor.clamp(0.1, 3.0);

Ok(Config {
themes,
servers,
font,
scale_factor,
buffer,
dashboard,
keys,
Expand Down Expand Up @@ -204,6 +210,10 @@ pub fn create_themes_dir() {
}
}

fn default_scale_factor() -> f64 {
1.0
}

#[derive(Debug, Error, Clone)]
pub enum Error {
#[error("config could not be read: {0}")]
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ impl Application for Halloy {
self.theme.clone()
}

fn scale_factor(&self) -> f64 {
self.config.scale_factor
}

fn subscription(&self) -> Subscription<Message> {
let tick = iced::time::every(Duration::from_secs(1)).map(Message::Tick);

Expand Down

0 comments on commit 6c39210

Please sign in to comment.