feat: make the manager offset customizable

This commit is contained in:
sxyazi 2023-10-18 00:37:50 +08:00
parent d04f8acaf8
commit 0945d780eb
No known key found for this signature in database
4 changed files with 22 additions and 19 deletions

View file

@ -27,6 +27,10 @@ tab_width = 1
border_symbol = "│" border_symbol = "│"
border_style = { fg = "gray" } border_style = { fg = "gray" }
# Offset
folder_offset = [ 1, 0, 1, 0 ]
preview_offset = [ 1, 1, 1, 1 ]
# Highlighting # Highlighting
syntect_theme = "" syntect_theme = ""

View file

@ -1,10 +1,10 @@
use anyhow::bail; use anyhow::bail;
use crossterm::terminal::WindowSize; use crossterm::terminal::WindowSize;
use ratatui::prelude::Rect; use ratatui::{prelude::Rect, widgets::{Block, Padding}};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use shared::Term; use shared::Term;
use super::{FOLDER_MARGIN, PREVIEW_BORDER, PREVIEW_MARGIN}; use crate::THEME;
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
#[serde(try_from = "Vec<u32>")] #[serde(try_from = "Vec<u32>")]
@ -42,14 +42,13 @@ impl ManagerLayout {
let width = (columns as u32 * self.preview) as f64 / self.all as f64; 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 width = if width.fract() > 0.5 { width.ceil() as u16 } else { width.floor() as u16 };
let x = columns.saturating_sub(width); let offset = THEME.manager.preview_offset;
Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect {
Rect { x: columns.saturating_sub(width),
x: x.saturating_add(PREVIEW_BORDER / 2), y: 0,
y: PREVIEW_MARGIN / 2, width,
width: width.saturating_sub(PREVIEW_BORDER), height: rows,
height: rows.saturating_sub(PREVIEW_MARGIN), })
}
} }
#[inline] #[inline]
@ -58,12 +57,13 @@ impl ManagerLayout {
pub fn folder_rect(&self) -> Rect { pub fn folder_rect(&self) -> Rect {
let WindowSize { columns, rows, .. } = Term::size(); 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, 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, width: (columns as u32 * self.current / self.all) as u16,
height: rows.saturating_sub(FOLDER_MARGIN), height: rows,
} })
} }
#[inline] #[inline]

View file

@ -5,8 +5,3 @@ mod sorting;
pub use layout::*; pub use layout::*;
pub use manager::*; pub use manager::*;
pub use sorting::*; pub use sorting::*;
const FOLDER_MARGIN: u16 = 2;
const PREVIEW_BORDER: u16 = 2;
const PREVIEW_MARGIN: u16 = 2;

View file

@ -34,6 +34,10 @@ pub struct Manager {
pub border_symbol: String, pub border_symbol: String,
pub border_style: Style, pub border_style: Style,
// Offset
pub(crate) folder_offset: (u16, u16, u16, u16),
pub(crate) preview_offset: (u16, u16, u16, u16),
// Highlighting // Highlighting
pub syntect_theme: PathBuf, pub syntect_theme: PathBuf,
} }