fix: centralize chrome segment spacing

This commit is contained in:
2026-10-18 01:52:43 +02:00
parent d8cfd27ee6
commit a28444a9f2
5 changed files with 87 additions and 75 deletions
+4 -23
View File
@@ -102,7 +102,7 @@ pub struct ChromeLine {
pub segments: BTreeMap<String, SegmentConfig>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct SegmentConfig {
pub title: String,
pub padding: usize,
@@ -112,19 +112,6 @@ pub struct SegmentConfig {
pub first_leading_edge: Option<String>,
}
impl Default for SegmentConfig {
fn default() -> Self {
Self {
title: String::new(),
padding: 1,
margin: [0; 2],
leading_edge: String::new(),
trailing_edge: String::new(),
first_leading_edge: None,
}
}
}
impl ChromeLine {
pub fn top() -> Self {
Self {
@@ -149,13 +136,7 @@ impl ChromeLine {
right: vec!["language".into(), "lsp".into(), "position".into()],
segments: DEFAULT_BOTTOM_SEGMENTS
.iter()
.map(|name| {
let mut segment = default_segment(name);
if *name == "position" {
segment.margin[0] = 1;
}
((*name).into(), segment)
})
.map(|name| ((*name).into(), default_segment(name)))
.collect(),
}
}
@@ -219,8 +200,8 @@ fn default_segment(name: &str) -> SegmentConfig {
if matches!(name, "tabs" | "mode" | "shell") {
segment.trailing_edge = "▓░".into();
}
if name == "shell" {
segment.margin[1] = 1;
if matches!(name, "tabs" | "mode" | "position" | "battery" | "shell") {
segment.padding = 1;
}
if name == "tabs" {
segment.title = "{index} {view}{name}{modified}".into();
+5 -3
View File
@@ -1833,7 +1833,7 @@ fn chrome_items<'a>(
}
fn chrome_group_width(items: &[ChromeItem<'_>]) -> usize {
items.iter().map(|item| item.width).sum()
items.iter().map(|item| item.width).sum::<usize>() + items.len().saturating_sub(1)
}
fn chrome_fits([left, center, right]: [usize; 3], width: usize) -> bool {
@@ -1904,13 +1904,15 @@ fn draw_chrome(frame: &mut Frame, mut groups: [Vec<ChromeItem<'_>>; 3], area: Re
}
break;
};
widths[group] -= groups[group].remove(index).width;
groups[group].remove(index);
widths[group] = chrome_group_width(&groups[group]);
}
let widths = widths.map(|cells| cells.min(width));
let starts = [0, (width - widths[1]) / 2, width - widths[2]];
for (items, start) in groups.iter().zip(starts) {
let mut x = start;
for item in items {
for (index, item) in items.iter().enumerate() {
x += usize::from(index > 0);
if x >= width {
break;
}