Skip to content

Commit

Permalink
config: add tags_margin
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Aug 2, 2024
1 parent e33db4f commit 3413a20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
41 changes: 18 additions & 23 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Bar {
layout_name: Option<String>,
mode_name: Option<String>,
tags_btns: ButtonManager<u32>,
tags_computed: Vec<(ColorPair, ComputedText)>,
tags_computed: Vec<(u32, ColorPair, ComputedText)>,
layout_name_computed: Option<ComputedText>,
mode_computed: Option<ComputedText>,
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit 3413a20

Please sign in to comment.