Make calendar background color configurable

This commit is contained in:
Dheepak Krishnamurthy 2020-11-03 03:05:11 -07:00
parent 9ec3543e9d
commit 0aae32a706
3 changed files with 9 additions and 3 deletions

View file

@ -211,7 +211,7 @@ impl TTApp {
.constraints([Constraint::Min(0)].as_ref())
.split(f.size());
let today = Local::today();
let c = Calendar::default()
let mut c = Calendar::default()
.block(
Block::default()
.title(Spans::from(vec![
@ -225,6 +225,7 @@ impl TTApp {
.year(self.calendar_year)
.date_style(dates_with_styles)
.months_per_row(self.config.uda_calendar_months_per_row);
c.title_background_color = self.config.uda_style_calendar_title.bg;
f.render_widget(c, rects[0]);
}

View file

@ -25,6 +25,7 @@ pub struct Calendar<'a> {
pub style: Style,
pub months_per_row: usize,
pub date_style: Vec<(NaiveDate, Style)>,
pub title_background_color: Color,
}
impl<'a> Default for Calendar<'a> {
@ -38,6 +39,7 @@ impl<'a> Default for Calendar<'a> {
year,
month,
date_style: vec![],
title_background_color: Color::White,
}
}
}
@ -157,7 +159,7 @@ impl<'a> Widget for Calendar<'a> {
let d = &mut days[c];
let m = d.0.month() as usize;
let s = format!("{:^20}", month_names[m - 1]);
let style = Style::default().bg(Color::Rgb(220, 220, 220));
let style = Style::default().bg(self.title_background_color);
if m == today.month() as usize && self.year + year as i32 == today.year() {
buf.set_string(x, y, &s, style.add_modifier(Modifier::BOLD));
} else {
@ -170,7 +172,7 @@ impl<'a> Widget for Calendar<'a> {
for c in startm..endm {
let d = &mut days[c];
let m = d.0.month() as usize;
let style = Style::default().bg(Color::Rgb(220, 220, 220));
let style = Style::default().bg(self.title_background_color);
if m == today.month() as usize && self.year + year as i32 == today.year() {
buf.set_string(
x as u16,

View file

@ -48,6 +48,7 @@ pub struct Config {
pub uda_selection_blink: bool,
pub uda_calendar_months_per_row: usize,
pub uda_style_context_active: TColor,
pub uda_style_calendar_title: TColor,
}
trait TaskWarriorBool {
@ -94,6 +95,8 @@ impl Config {
uda_selection_dim: Self::get_uda_selection_dim(),
uda_selection_blink: Self::get_uda_selection_blink(),
uda_calendar_months_per_row: Self::get_uda_months_per_row(),
uda_style_calendar_title: Self::get_uda_style("calendar.title")
.unwrap_or(TColor::new(Color::Black, Color::Rgb(220, 220, 220), vec![])),
uda_style_context_active: Self::get_uda_style("context.active")
.unwrap_or(TColor::new(Color::Black, Color::Rgb(220, 220, 220), vec![])),
})