better names for day text colours

Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
This commit is contained in:
Fabrizio Iannetti 2022-12-27 09:29:29 +01:00
parent f2f4e36c20
commit 966752614a
1 changed files with 14 additions and 19 deletions

View File

@ -14,7 +14,7 @@ use iced_native::{Color, Element, Length, Point, Rectangle, Widget};
use iced_native::text; use iced_native::text;
use iced_native::alignment; use iced_native::alignment;
use iced_native::widget::Tree; use iced_native::widget::Tree;
use chrono::{NaiveDate, Datelike, Duration, Weekday, Local}; use chrono::{NaiveDate, Datelike, Duration, Local};
use super::basics::CellGrid; use super::basics::CellGrid;
const MONTH_NAMES: [&str;12] = [ const MONTH_NAMES: [&str;12] = [
@ -41,8 +41,8 @@ pub struct CalendarParams {
show_weeks: bool, show_weeks: bool,
header_fg: Color, header_fg: Color,
header_bg: Color, header_bg: Color,
day_text: Color, day_fg: Color,
day_text_other_month: Color, day_other_month_fg: Color,
day_weekend_bg: Color, day_weekend_bg: Color,
day_today_bg: Color, day_today_bg: Color,
day_text_margin: f32, day_text_margin: f32,
@ -55,8 +55,8 @@ impl CalendarParams {
header_fg: Color::BLACK, header_fg: Color::BLACK,
header_bg: Color::TRANSPARENT, header_bg: Color::TRANSPARENT,
day_today_bg: Color::from_rgb8(214, 242, 252), day_today_bg: Color::from_rgb8(214, 242, 252),
day_text: Color::BLACK, day_fg: Color::BLACK,
day_text_other_month: Color::from_rgb8(220, 220, 220), day_other_month_fg: Color::from_rgb8(220, 220, 220),
day_weekend_bg: Color::from_rgb8(245, 245, 245), day_weekend_bg: Color::from_rgb8(245, 245, 245),
day_text_margin: 5.0, day_text_margin: 5.0,
} }
@ -69,7 +69,6 @@ pub struct CalendarMonthView {
first_day: NaiveDate, first_day: NaiveDate,
first_day_in_view: NaiveDate, first_day_in_view: NaiveDate,
params: CalendarParams, params: CalendarParams,
weekday_on_first: Weekday,
week_column_width: f32, week_column_width: f32,
week_column_font_size: f32, week_column_font_size: f32,
} }
@ -93,7 +92,6 @@ impl CalendarMonthView {
first_day, first_day,
first_day_in_view, first_day_in_view,
params: params.clone(), params: params.clone(),
weekday_on_first,
week_column_width: 30.0, week_column_width: 30.0,
week_column_font_size: 18.0, week_column_font_size: 18.0,
} }
@ -114,7 +112,6 @@ impl CalendarMonthView {
let first_day_in_view = first_day - Duration::days(weekday_on_first.num_days_from_monday() as i64); let first_day_in_view = first_day - Duration::days(weekday_on_first.num_days_from_monday() as i64);
self.first_day = first_day; self.first_day = first_day;
self.weekday_on_first = weekday_on_first;
self.first_day_in_view = first_day_in_view; self.first_day_in_view = first_day_in_view;
} }
@ -202,7 +199,7 @@ impl CalendarMonthView {
y: day_bounds.y, y: day_bounds.y,
..day_bounds ..day_bounds
}, },
color: self.params.day_text, color: self.params.day_fg,
font: Default::default(), font: Default::default(),
horizontal_alignment: alignment::Horizontal::Center, horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: alignment::Vertical::Top, vertical_alignment: alignment::Vertical::Top,
@ -235,9 +232,9 @@ impl CalendarMonthView {
// color of text // color of text
let fg = if current_day.month() == self.first_day.month() { let fg = if current_day.month() == self.first_day.month() {
self.params.day_text self.params.day_fg
} else { } else {
self.params.day_text_other_month self.params.day_other_month_fg
}; };
// background color of the day cell // background color of the day cell
@ -257,7 +254,7 @@ impl CalendarMonthView {
bounds: Rectangle {width: day_bounds.width + 0.5, height: day_bounds.height + 0.5, ..day_bounds}, bounds: Rectangle {width: day_bounds.width + 0.5, height: day_bounds.height + 0.5, ..day_bounds},
border_radius: 0.0.into(), border_radius: 0.0.into(),
border_width: 1.0, border_width: 1.0,
border_color: self.params.day_text_other_month, border_color: self.params.day_other_month_fg,
}, },
bg_color); bg_color);
@ -357,7 +354,6 @@ pub struct CalendarYearView {
first_day: NaiveDate, first_day: NaiveDate,
first_day_in_view: NaiveDate, first_day_in_view: NaiveDate,
params: CalendarParams, params: CalendarParams,
weekday_on_first: Weekday,
month_column_font_size: f32, month_column_font_size: f32,
margin: f32, margin: f32,
} }
@ -377,7 +373,6 @@ impl CalendarYearView {
first_day, first_day,
first_day_in_view, first_day_in_view,
params: params.clone(), params: params.clone(),
weekday_on_first,
month_column_font_size: 24.0, month_column_font_size: 24.0,
margin: 10.0 margin: 10.0
} }
@ -388,10 +383,10 @@ impl CalendarYearView {
self.first_day = NaiveDate::from_ymd(day.year(), 1, 1); self.first_day = NaiveDate::from_ymd(day.year(), 1, 1);
// weekday on first day of the year // weekday on first day of the year
self.weekday_on_first = self.first_day.weekday(); let weekday_on_first = self.first_day.weekday();
// first visible day in the view // first visible day in the view
self.first_day_in_view = self.first_day - Duration::days(self.weekday_on_first.num_days_from_monday() as i64); self.first_day_in_view = self.first_day - Duration::days(weekday_on_first.num_days_from_monday() as i64);
} }
fn draw_header( fn draw_header(
@ -495,7 +490,7 @@ impl CalendarYearView {
y: month_name_bounds.center_y(), y: month_name_bounds.center_y(),
..month_name_bounds ..month_name_bounds
}, },
color: self.params.day_text, color: self.params.day_fg,
font: Default::default(), font: Default::default(),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
@ -535,7 +530,7 @@ impl CalendarYearView {
let content = t.as_str(); let content = t.as_str();
// color of text // color of text
let fg = self.params.day_text; let fg = self.params.day_fg;
// background color of the day cell // background color of the day cell
let bg_color = if current_day == Local::today().naive_local() { let bg_color = if current_day == Local::today().naive_local() {
@ -554,7 +549,7 @@ impl CalendarYearView {
bounds: day_bounds, bounds: day_bounds,
border_radius: 0.0.into(), border_radius: 0.0.into(),
border_width: 1.0, border_width: 1.0,
border_color: self.params.day_text_other_month, border_color: self.params.day_other_month_fg,
}, },
bg_color); bg_color);