improved event visualization
* margin between bars * fix min row height computation Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
This commit is contained in:
parent
9ce23811d5
commit
801f6a5c81
@ -46,6 +46,7 @@ pub struct CalendarParams {
|
||||
day_text_margin: f32,
|
||||
|
||||
ev_height: f32,
|
||||
ev_margin: f32,
|
||||
ev_bg: Color,
|
||||
ev_fontsize: f32,
|
||||
}
|
||||
@ -62,6 +63,7 @@ impl CalendarParams {
|
||||
day_weekend_bg: Color::from_rgb8(245, 245, 245),
|
||||
day_text_margin: 5.0,
|
||||
ev_height: 20.0,
|
||||
ev_margin: 2.0,
|
||||
ev_bg: Color::from_rgb8(200, 245, 200),
|
||||
ev_fontsize: 16.0,
|
||||
}
|
||||
@ -76,6 +78,7 @@ fn render_events_in_row(
|
||||
first_day: NaiveDate,
|
||||
num_days: i64,
|
||||
row_bounds: Rectangle,
|
||||
min_row_height: f32,
|
||||
font_size: Pixels,
|
||||
fg: Color,
|
||||
content: &str,
|
||||
@ -110,6 +113,7 @@ fn render_events_in_row(
|
||||
let x = row_bounds.x;
|
||||
let y = row_bounds.y + params.day_text_margin + day_text_height;
|
||||
let ev_height = params.ev_height;
|
||||
let ev_margin = params.ev_margin;
|
||||
|
||||
let mut ev_y: f32 = 0.0;
|
||||
|
||||
@ -119,7 +123,7 @@ fn render_events_in_row(
|
||||
ev: e,
|
||||
bounds: Rectangle {
|
||||
x,
|
||||
y,
|
||||
y: y,
|
||||
width: 0.0,
|
||||
height: ev_height,
|
||||
},
|
||||
@ -138,11 +142,6 @@ fn render_events_in_row(
|
||||
|
||||
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
|
||||
for cell in row_grid.iter() {
|
||||
ev_y = y;
|
||||
@ -152,14 +151,14 @@ fn render_events_in_row(
|
||||
{
|
||||
// start of event
|
||||
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 {
|
||||
// end of event -> set width
|
||||
ev_bar.bounds.width = cell.x + cell.width - ev_bar.bounds.x;
|
||||
}
|
||||
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();
|
||||
@ -366,7 +365,11 @@ impl<'a> CalendarMonthView<'a> {
|
||||
let mut current_day = self.first_day_in_view;
|
||||
|
||||
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() {
|
||||
let row_first_day = current_day;
|
||||
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,
|
||||
6,
|
||||
row_bounds,
|
||||
min_row_height,
|
||||
font_size,
|
||||
self.params.day_fg,
|
||||
content,
|
||||
@ -732,6 +736,11 @@ impl<'a> CalendarYearView<'a> {
|
||||
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() {
|
||||
let row_grid = CellGrid::new(
|
||||
row.x,
|
||||
@ -829,6 +838,7 @@ impl<'a> CalendarYearView<'a> {
|
||||
first_day_of_month,
|
||||
row_days as i64,
|
||||
row_bounds,
|
||||
min_row_height,
|
||||
font_size,
|
||||
self.params.day_fg,
|
||||
content,
|
||||
|
Loading…
x
Reference in New Issue
Block a user