Implement ZoomIn/ZoomOut/ZoomReset with configurable step

Implements #14.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-01-01 12:27:51 +03:00 committed by Jeremy Soller
parent 1e0ce2b7e7
commit 1c8a058e82
3 changed files with 92 additions and 1 deletions

View file

@ -31,6 +31,8 @@ pub struct Config {
pub app_theme: AppTheme,
pub font_name: String,
pub font_size: u16,
pub font_size_zoom_adj: i8,
pub font_size_zoom_step_mul_100: u16,
pub show_headerbar: bool,
pub syntax_theme_dark: String,
pub syntax_theme_light: String,
@ -42,6 +44,8 @@ impl Default for Config {
app_theme: AppTheme::System,
font_name: "Fira Mono".to_string(),
font_size: 14,
font_size_zoom_adj: 0,
font_size_zoom_step_mul_100: 100,
show_headerbar: true,
syntax_theme_dark: "COSMIC Dark".to_string(),
syntax_theme_light: "COSMIC Light".to_string(),
@ -50,9 +54,16 @@ impl Default for Config {
}
impl Config {
fn font_size_adjusted(&self) -> f32 {
let font_size = f32::from(self.font_size).max(1.0);
let adj = f32::from(self.font_size_zoom_adj);
let adj_step = f32::from(self.font_size_zoom_step_mul_100) / 100.0;
(font_size + adj*adj_step).max(1.0)
}
// Calculate metrics from font size
pub fn metrics(&self) -> Metrics {
let font_size = self.font_size.max(1) as f32;
let font_size = self.font_size_adjusted();
let line_height = (font_size * 1.4).ceil();
Metrics::new(font_size, line_height)
}