From f038391ef5712f281f6fb65f0fe063a152e0a347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Wed, 15 Nov 2023 08:51:11 +0800 Subject: [PATCH] refactor: use more reasonable numeric field types for configs (#368) --- yazi-adaptor/src/ueberzug.rs | 8 ++++---- yazi-config/src/manager/layout.rs | 20 ++++++++++---------- yazi-config/src/preview/preview.rs | 12 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/yazi-adaptor/src/ueberzug.rs b/yazi-adaptor/src/ueberzug.rs index 15e90c4f..c7b414f2 100644 --- a/yazi-adaptor/src/ueberzug.rs +++ b/yazi-adaptor/src/ueberzug.rs @@ -48,10 +48,10 @@ impl Ueberzug { let scale = PREVIEW.ueberzug_scale; let (x, y, w, h) = PREVIEW.ueberzug_offset; - rect.x = 0f64.max(rect.x as f64 * scale + x) as u16; - rect.y = 0f64.max(rect.y as f64 * scale + y) as u16; - rect.width = 0f64.max(rect.width as f64 * scale + w) as u16; - rect.height = 0f64.max(rect.height as f64 * scale + h) as u16; + rect.x = 0f32.max(rect.x as f32 * scale + x) as u16; + rect.y = 0f32.max(rect.y as f32 * scale + y) as u16; + rect.width = 0f32.max(rect.width as f32 * scale + w) as u16; + rect.height = 0f32.max(rect.height as f32 * scale + h) as u16; rect } diff --git a/yazi-config/src/manager/layout.rs b/yazi-config/src/manager/layout.rs index 5e5a1e41..14616505 100644 --- a/yazi-config/src/manager/layout.rs +++ b/yazi-config/src/manager/layout.rs @@ -7,18 +7,18 @@ use yazi_shared::Term; use crate::THEME; #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] -#[serde(try_from = "Vec")] +#[serde(try_from = "Vec")] pub struct ManagerLayout { - pub parent: u32, - pub current: u32, - pub preview: u32, - pub all: u32, + pub parent: u16, + pub current: u16, + pub preview: u16, + pub all: u16, } -impl TryFrom> for ManagerLayout { +impl TryFrom> for ManagerLayout { type Error = anyhow::Error; - fn try_from(ratio: Vec) -> Result { + fn try_from(ratio: Vec) -> Result { if ratio.len() != 3 { bail!("invalid layout ratio: {:?}", ratio); } @@ -39,7 +39,7 @@ impl ManagerLayout { pub fn preview_rect(&self) -> Rect { let WindowSize { columns, rows, .. } = Term::size(); - let width = (columns as u32 * self.preview) as f64 / self.all as f64; + let width = (columns * self.preview) as f64 / self.all as f64; let width = if width.fract() > 0.5 { width.ceil() as u16 } else { width.floor() as u16 }; let offset = THEME.manager.preview_offset; @@ -59,9 +59,9 @@ impl ManagerLayout { let offset = THEME.manager.folder_offset; Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect { - x: (columns as u32 * self.parent / self.all) as u16, + x: columns * self.parent / self.all, y: 0, - width: (columns as u32 * self.current / self.all) as u16, + width: columns * self.current / self.all, height: rows, }) } diff --git a/yazi-config/src/preview/preview.rs b/yazi-config/src/preview/preview.rs index ca5d2287..fd83cc3d 100644 --- a/yazi-config/src/preview/preview.rs +++ b/yazi-config/src/preview/preview.rs @@ -8,14 +8,14 @@ use crate::{xdg::Xdg, MERGED_YAZI}; #[derive(Debug)] pub struct Preview { - pub tab_size: u32, + pub tab_size: u8, pub max_width: u32, pub max_height: u32, pub cache_dir: PathBuf, - pub ueberzug_scale: f64, - pub ueberzug_offset: (f64, f64, f64, f64), + pub ueberzug_scale: f32, + pub ueberzug_offset: (f32, f32, f32, f32), } impl Default for Preview { @@ -26,14 +26,14 @@ impl Default for Preview { } #[derive(Deserialize)] struct Shadow { - tab_size: u32, + tab_size: u8, max_width: u32, max_height: u32, cache_dir: Option, - ueberzug_scale: f64, - ueberzug_offset: (f64, f64, f64, f64), + ueberzug_scale: f32, + ueberzug_offset: (f32, f32, f32, f32), } let preview = toml::from_str::(&MERGED_YAZI).unwrap().preview;