From 901cc3494fac35eaa2c843b679f477e354c22d68 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 29 Jan 2020 21:47:57 +0200 Subject: [PATCH] ui/themes: add theming support in tab bar --- ui/src/components/mail/listing.rs | 31 +++++++++++++++++++++++-------- ui/src/components/utilities.rs | 19 +++++++++++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 5d9f217bd..da0a9d277 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -295,6 +295,7 @@ pub struct Listing { cursor_pos: (usize, usize), startup_checks_rate: RateLimit, id: ComponentId, + theme_default: ThemeAttribute, show_divider: bool, menu_visibility: bool, @@ -326,6 +327,7 @@ impl Component for Listing { if !is_valid_area!(area) { return; } + self.theme_default = crate::conf::value(context, "theme_default"); let upper_left = upper_left!(area); let bottom_right = bottom_right!(area); let total_cols = get_x(bottom_right) - get_x(upper_left); @@ -339,14 +341,18 @@ impl Component for Listing { if self.dirty && mid != get_x(upper_left) { if self.show_divider { for i in get_y(upper_left)..=get_y(bottom_right) { - grid[(mid, i)].set_ch(VERT_BOUNDARY); - grid[(mid, i)].set_fg(Color::Default); - grid[(mid, i)].set_bg(Color::Default); + grid[(mid, i)] + .set_ch(VERT_BOUNDARY) + .set_fg(self.theme_default.fg) + .set_bg(self.theme_default.bg) + .set_attrs(self.theme_default.attrs); } } else { for i in get_y(upper_left)..=get_y(bottom_right) { - grid[(mid, i)].set_fg(Color::Default); - grid[(mid, i)].set_bg(Color::Default); + grid[(mid, i)] + .set_fg(self.theme_default.fg) + .set_bg(self.theme_default.bg) + .set_attrs(self.theme_default.attrs); } } context @@ -896,6 +902,7 @@ impl Listing { dirty: true, cursor_pos: (0, 0), startup_checks_rate: RateLimit::new(2, 1000), + theme_default: ThemeAttribute::default(), id: ComponentId::new_v4(), show_divider: false, menu_visibility: true, @@ -908,7 +915,15 @@ impl Listing { if !self.is_dirty() { return; } - clear_area(grid, area); + for row in grid.bounds_iter(area) { + for c in row { + grid[c] + .set_ch(' ') + .set_fg(self.theme_default.fg) + .set_bg(self.theme_default.bg) + .set_attrs(self.theme_default.attrs); + } + } /* visually divide menu and listing */ area = (area.0, pos_dec(area.1, (1, 0))); let upper_left = upper_left!(area); @@ -1023,8 +1038,8 @@ impl Listing { write_string_to_grid( &a.name, grid, - Color::Default, - Color::Default, + self.theme_default.fg, + self.theme_default.bg, Attr::Bold, area, None, diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index d6e818f64..ea6eb9b59 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -1375,8 +1375,9 @@ impl Tabbed { clear_area(grid, area); return; } - let mut tab_focused_attribute = crate::conf::value(context, "tab.focused"); + let tab_bar_attribute = crate::conf::value(context, "tab.bar"); let tab_unfocused_attribute = crate::conf::value(context, "tab.unfocused"); + let mut tab_focused_attribute = crate::conf::value(context, "tab.focused"); if std::env::var("NO_COLOR").is_ok() && (context.settings.terminal.use_color.is_false() || context.settings.terminal.use_color.is_internal()) @@ -1408,17 +1409,21 @@ impl Tabbed { if y != _y_ { break; } + grid[(x_, _y_)] + .set_fg(tab_bar_attribute.fg) + .set_bg(tab_bar_attribute.bg) + .set_attrs(tab_bar_attribute.attrs); } let (cols, _) = grid.size(); let cslice: &mut [Cell] = grid; - //TODO: bounds check let cslice_len = cslice.len(); for c in cslice[(y * cols) + x.saturating_sub(1) ..std::cmp::min((y * cols) + x.saturating_sub(1), cslice_len)] .iter_mut() { - c.set_bg(Color::Byte(7)); - c.set_ch(' '); + c.set_ch(' ').set_bg(tab_unfocused_attribute.bg); + //.set_fg(tab_unfocused_attribute.bg) + //.set_bg(Color::Byte(7)); } if self.cursor_pos == self.children.len() - 1 { @@ -1428,6 +1433,12 @@ impl Tabbed { .set_bg(tab_unfocused_attribute.fg) .set_attrs(tab_unfocused_attribute.attrs); } + for c in grid.row_iter(x..cols, get_y(upper_left)) { + grid[c] + .set_fg(tab_bar_attribute.fg) + .set_bg(tab_bar_attribute.bg) + .set_attrs(tab_bar_attribute.attrs); + } context.dirty_areas.push_back(area); }