Compare commits

...

2 Commits

Author SHA1 Message Date
Fabrizio Iannetti 801f6a5c81 improved event visualization
* margin between bars
* fix min row height computation

Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
2023-09-29 22:56:24 +02:00
Fabrizio Iannetti 9ce23811d5 naming
Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
2023-09-29 22:55:35 +02:00
2 changed files with 24 additions and 14 deletions

View File

@ -26,7 +26,7 @@ pub struct CellGrid {
num_y: u32, num_y: u32,
} }
pub struct CellGridCells<'a> { pub struct CellGridIterator<'a> {
grid: &'a CellGrid, grid: &'a CellGrid,
// current position when iterating // current position when iterating
@ -49,8 +49,8 @@ impl CellGrid {
} }
} }
pub fn iter(&self) -> CellGridCells { pub fn iter(&self) -> CellGridIterator {
CellGridCells { CellGridIterator {
grid: self, grid: self,
pos_x: 0, pos_x: 0,
pos_y: 0, pos_y: 0,
@ -78,7 +78,7 @@ impl CellGrid {
} }
} }
impl<'a> CellGridCells<'a> { impl<'a> CellGridIterator<'a> {
fn compute_cell(&mut self) -> () { fn compute_cell(&mut self) -> () {
let grid: &'a CellGrid = self.grid; let grid: &'a CellGrid = self.grid;
self.curr.pos_x = self.pos_x; self.curr.pos_x = self.pos_x;
@ -96,7 +96,7 @@ impl<'a> CellGridCells<'a> {
} }
} }
impl<'a> Iterator for CellGridCells<'a> { impl<'a> Iterator for CellGridIterator<'a> {
type Item = Cell; type Item = Cell;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

View File

@ -46,6 +46,7 @@ pub struct CalendarParams {
day_text_margin: f32, day_text_margin: f32,
ev_height: f32, ev_height: f32,
ev_margin: f32,
ev_bg: Color, ev_bg: Color,
ev_fontsize: f32, ev_fontsize: f32,
} }
@ -62,6 +63,7 @@ impl CalendarParams {
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,
ev_height: 20.0, ev_height: 20.0,
ev_margin: 2.0,
ev_bg: Color::from_rgb8(200, 245, 200), ev_bg: Color::from_rgb8(200, 245, 200),
ev_fontsize: 16.0, ev_fontsize: 16.0,
} }
@ -76,6 +78,7 @@ fn render_events_in_row(
first_day: NaiveDate, first_day: NaiveDate,
num_days: i64, num_days: i64,
row_bounds: Rectangle, row_bounds: Rectangle,
min_row_height: f32,
font_size: Pixels, font_size: Pixels,
fg: Color, fg: Color,
content: &str, content: &str,
@ -110,6 +113,7 @@ fn render_events_in_row(
let x = row_bounds.x; let x = row_bounds.x;
let y = row_bounds.y + params.day_text_margin + day_text_height; let y = row_bounds.y + params.day_text_margin + day_text_height;
let ev_height = params.ev_height; let ev_height = params.ev_height;
let ev_margin = params.ev_margin;
let mut ev_y: f32 = 0.0; let mut ev_y: f32 = 0.0;
@ -119,7 +123,7 @@ fn render_events_in_row(
ev: e, ev: e,
bounds: Rectangle { bounds: Rectangle {
x, x,
y, y: y,
width: 0.0, width: 0.0,
height: ev_height, height: ev_height,
}, },
@ -138,11 +142,6 @@ fn render_events_in_row(
let mut current_day = first_day; let mut current_day = first_day;
// use the minimum row height to compute available space for event bars
// to avoid inconsistentencies when rowas have slightly different heights
// and some can fit more event bars than others
let min_row_height = row_grid.compute_min_height();
// update event bars // update event bars
for cell in row_grid.iter() { for cell in row_grid.iter() {
ev_y = y; ev_y = y;
@ -152,14 +151,14 @@ fn render_events_in_row(
{ {
// start of event // start of event
ev_bar.bounds.x = cell.x; ev_bar.bounds.x = cell.x;
ev_bar.bounds.y = ev_y; ev_bar.bounds.y = ev_y + ev_margin;
} }
if ev_bar.ev.end == current_day { if ev_bar.ev.end == current_day {
// end of event -> set width // end of event -> set width
ev_bar.bounds.width = cell.x + cell.width - ev_bar.bounds.x; ev_bar.bounds.width = cell.x + cell.width - ev_bar.bounds.x;
} }
if ev_bar.ev.is_in_day(current_day) { if ev_bar.ev.is_in_day(current_day) {
ev_y += ev_height; ev_y += ev_height + 2.0 * ev_margin;
} }
} }
current_day = current_day.succ_opt().unwrap(); current_day = current_day.succ_opt().unwrap();
@ -366,7 +365,11 @@ impl<'a> CalendarMonthView<'a> {
let mut current_day = self.first_day_in_view; let mut current_day = self.first_day_in_view;
let grid = CellGrid::new(bounds.x, bounds.y, bounds.width, bounds.height, 7, 6); let grid = CellGrid::new(bounds.x, bounds.y, bounds.width, bounds.height, 7, 6);
let min_row_height = grid.compute_min_height(); // use the minimum row height to compute available space for event bars
// to avoid inconsistentencies when rowas have slightly different heights
// and some can fit more event bars than others
let min_row_height = grid.compute_min_height();
for row in grid.rows().iter() { for row in grid.rows().iter() {
let row_first_day = current_day; let row_first_day = current_day;
let row_grid = CellGrid::new(row.x, row.y, row.width, row.height, 7, 1); let row_grid = CellGrid::new(row.x, row.y, row.width, row.height, 7, 1);
@ -443,6 +446,7 @@ impl<'a> CalendarMonthView<'a> {
row_first_day, row_first_day,
6, 6,
row_bounds, row_bounds,
min_row_height,
font_size, font_size,
self.params.day_fg, self.params.day_fg,
content, content,
@ -732,6 +736,11 @@ impl<'a> CalendarYearView<'a> {
12, 12,
); );
// use the minimum row height to compute available space for event bars
// to avoid inconsistentencies when rowas have slightly different heights
// and some can fit more event bars than others
let min_row_height = grid.compute_min_height();
for row in grid.rows().iter() { for row in grid.rows().iter() {
let row_grid = CellGrid::new( let row_grid = CellGrid::new(
row.x, row.x,
@ -829,6 +838,7 @@ impl<'a> CalendarYearView<'a> {
first_day_of_month, first_day_of_month,
row_days as i64, row_days as i64,
row_bounds, row_bounds,
min_row_height,
font_size, font_size,
self.params.day_fg, self.params.day_fg,
content, content,