From 3413a203f452875c7af07284c6ac080c22555b48 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Fri, 2 Aug 2024 15:32:30 +0300 Subject: [PATCH] config: add tags_margin --- README.md | 1 + src/bar.rs | 41 ++++++++++++++++++----------------------- src/config.rs | 2 ++ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0662680..4e50f1a 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ margin_right = 0 separator_width = 2.0 tags_r = 0.0 tags_padding = 25.0 +tags_margin = 0.0 blocks_r = 0.0 blocks_overlap = 0.0 diff --git a/src/bar.rs b/src/bar.rs index 16837ae..0fe5415 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -34,7 +34,7 @@ pub struct Bar { layout_name: Option, mode_name: Option, tags_btns: ButtonManager, - tags_computed: Vec<(ColorPair, ComputedText)>, + tags_computed: Vec<(u32, ColorPair, ComputedText)>, layout_name_computed: Option, mode_computed: Option, } @@ -208,8 +208,6 @@ impl Bar { // Compute tags if self.tags_computed.is_empty() { - let mut offset_left = 0.0; - self.tags_btns.clear(); for tag in &self.tags { let (bg, fg) = if tag.is_urgent { (ss.config.tag_urgent_bg, ss.config.tag_urgent_fg) @@ -223,38 +221,35 @@ impl Bar { continue; }; let comp = compute_tag_label(&tag.name, &ss.config); - self.tags_btns.push(offset_left, comp.width, tag.id); - offset_left += comp.width; - self.tags_computed.push((ColorPair { bg, fg }, comp)); + self.tags_computed + .push((tag.id, ColorPair { bg, fg }, comp)); } } // Display tags let mut offset_left = 0.0; - for (i, label) in self.tags_computed.iter().enumerate() { - label.1.render( + self.tags_btns.clear(); + for (i, (id, color, computed)) in self.tags_computed.iter().enumerate() { + let left_joined = i != 0 && self.tags_computed[i - 1].1 == *color; + let right_joined = + i + 1 != self.tags_computed.len() && self.tags_computed[i + 1].1 == *color; + if i != 0 && !left_joined { + offset_left += ss.config.tags_margin; + } + computed.render( &cairo_ctx, RenderOptions { x_offset: offset_left, bar_height: height_f, - fg_color: label.0.fg, - bg_color: Some(label.0.bg), - r_left: if i == 0 || self.tags_computed[i - 1].0 != label.0 { - ss.config.tags_r - } else { - 0.0 - }, - r_right: if i + 1 == self.tags_computed.len() - || self.tags_computed[i + 1].0 != label.0 - { - ss.config.tags_r - } else { - 0.0 - }, + fg_color: color.fg, + bg_color: Some(color.bg), + r_left: if left_joined { 0.0 } else { ss.config.tags_r }, + r_right: if right_joined { 0.0 } else { ss.config.tags_r }, overlap: 0.0, }, ); - offset_left += label.1.width; + self.tags_btns.push(offset_left, computed.width, *id); + offset_left += computed.width; } // Display layout name diff --git a/src/config.rs b/src/config.rs index a75ee17..72ebd5f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,6 +36,7 @@ pub struct Config { pub separator_width: f64, pub tags_r: f64, pub tags_padding: f64, + pub tags_margin: f64, pub blocks_r: f64, pub blocks_overlap: f64, // misc @@ -78,6 +79,7 @@ impl Default for Config { separator_width: 2.0, tags_r: 0.0, tags_padding: 25.0, + tags_margin: 0.0, blocks_r: 0.0, blocks_overlap: 0.0,