From 0945d780ebb8d828d8c77e566236a247b63d49ba Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 18 Oct 2023 00:37:50 +0800 Subject: [PATCH] feat: make the manager offset customizable --- config/preset/theme.toml | 4 ++++ config/src/manager/layout.rs | 28 ++++++++++++++-------------- config/src/manager/mod.rs | 5 ----- config/src/theme/theme.rs | 4 ++++ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/config/preset/theme.toml b/config/preset/theme.toml index cd0ec343..616f16b5 100644 --- a/config/preset/theme.toml +++ b/config/preset/theme.toml @@ -27,6 +27,10 @@ tab_width = 1 border_symbol = "│" border_style = { fg = "gray" } +# Offset +folder_offset = [ 1, 0, 1, 0 ] +preview_offset = [ 1, 1, 1, 1 ] + # Highlighting syntect_theme = "" diff --git a/config/src/manager/layout.rs b/config/src/manager/layout.rs index 96730b02..3e95d3cb 100644 --- a/config/src/manager/layout.rs +++ b/config/src/manager/layout.rs @@ -1,10 +1,10 @@ use anyhow::bail; use crossterm::terminal::WindowSize; -use ratatui::prelude::Rect; +use ratatui::{prelude::Rect, widgets::{Block, Padding}}; use serde::{Deserialize, Serialize}; use shared::Term; -use super::{FOLDER_MARGIN, PREVIEW_BORDER, PREVIEW_MARGIN}; +use crate::THEME; #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] #[serde(try_from = "Vec")] @@ -42,14 +42,13 @@ impl ManagerLayout { let width = (columns as u32 * 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 x = columns.saturating_sub(width); - - Rect { - x: x.saturating_add(PREVIEW_BORDER / 2), - y: PREVIEW_MARGIN / 2, - width: width.saturating_sub(PREVIEW_BORDER), - height: rows.saturating_sub(PREVIEW_MARGIN), - } + let offset = THEME.manager.preview_offset; + Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect { + x: columns.saturating_sub(width), + y: 0, + width, + height: rows, + }) } #[inline] @@ -58,12 +57,13 @@ impl ManagerLayout { pub fn folder_rect(&self) -> Rect { let WindowSize { columns, rows, .. } = Term::size(); - Rect { + 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, - y: FOLDER_MARGIN / 2, + y: 0, width: (columns as u32 * self.current / self.all) as u16, - height: rows.saturating_sub(FOLDER_MARGIN), - } + height: rows, + }) } #[inline] diff --git a/config/src/manager/mod.rs b/config/src/manager/mod.rs index 4e72e379..08394cbf 100644 --- a/config/src/manager/mod.rs +++ b/config/src/manager/mod.rs @@ -5,8 +5,3 @@ mod sorting; pub use layout::*; pub use manager::*; pub use sorting::*; - -const FOLDER_MARGIN: u16 = 2; - -const PREVIEW_BORDER: u16 = 2; -const PREVIEW_MARGIN: u16 = 2; diff --git a/config/src/theme/theme.rs b/config/src/theme/theme.rs index 9ca1ee28..f439e1ec 100644 --- a/config/src/theme/theme.rs +++ b/config/src/theme/theme.rs @@ -34,6 +34,10 @@ pub struct Manager { pub border_symbol: String, pub border_style: Style, + // Offset + pub(crate) folder_offset: (u16, u16, u16, u16), + pub(crate) preview_offset: (u16, u16, u16, u16), + // Highlighting pub syntect_theme: PathBuf, }