Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose scale_factor from iced #234

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading