Skip to content

Commit

Permalink
feat: make the manager offset customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 17, 2023
1 parent d04f8ac commit 0945d78
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
4 changes: 4 additions & 0 deletions config/preset/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand Down
28 changes: 14 additions & 14 deletions config/src/manager/layout.rs
Original file line number Diff line number Diff line change
@@ -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<u32>")]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
5 changes: 0 additions & 5 deletions config/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions config/src/theme/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 0945d78

Please sign in to comment.