week-grid, week-header: special-case today when drawing
The week grid should display a horizontal strip on the today column, and the week header should draw the week day labels with a custom color.
This commit is contained in:
@@ -28,7 +28,8 @@ calendar-view.header {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
calendar-view.current {
|
||||
calendar-view.current,
|
||||
weekgrid.current {
|
||||
background-color: alpha(@theme_selected_bg_color, 0.3);
|
||||
}
|
||||
|
||||
@@ -400,6 +401,10 @@ datechooser day:selected:hover {
|
||||
color: alpha(@theme_fg_color, 0.6);
|
||||
}
|
||||
|
||||
.week-header .today {
|
||||
color: @theme_selected_bg_color;
|
||||
}
|
||||
|
||||
.week-view {
|
||||
padding: 0px;
|
||||
}
|
||||
@@ -410,3 +415,9 @@ datechooser day:selected:hover {
|
||||
color: alpha(@theme_fg_color, 0.25);
|
||||
padding: 18px 12px;
|
||||
}
|
||||
|
||||
weekgrid.now-strip {
|
||||
background-color: alpha(@theme_selected_bg_color, 0.8);
|
||||
margin: 0 0 0 1px;
|
||||
min-height: 2px;
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@ gcal_week_grid_set_property (GObject *object,
|
||||
self->active_date = g_value_dup_boxed (value);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
return;
|
||||
|
||||
default:
|
||||
@@ -337,6 +338,23 @@ gcal_week_grid_unmap (GtkWidget *widget)
|
||||
GTK_WIDGET_CLASS (gcal_week_grid_parent_class)->unmap (widget);
|
||||
}
|
||||
|
||||
static inline gint
|
||||
get_today_column (GcalWeekGrid *self)
|
||||
{
|
||||
g_autoptr(GDateTime) today, week_start;
|
||||
gint days_diff;
|
||||
|
||||
today = g_date_time_new_now_local ();
|
||||
week_start = get_start_of_week (self->active_date);
|
||||
days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
|
||||
|
||||
/* Today is out of range */
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > 7)
|
||||
return -1;
|
||||
|
||||
return days_diff;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_week_grid_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
@@ -346,7 +364,7 @@ gcal_week_grid_draw (GtkWidget *widget,
|
||||
GtkBorder padding;
|
||||
GdkRGBA color;
|
||||
|
||||
gint i, width, height;
|
||||
gint i, width, height, today_column;
|
||||
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *font_desc;
|
||||
@@ -368,6 +386,35 @@ gcal_week_grid_draw (GtkWidget *widget,
|
||||
|
||||
cairo_set_line_width (cr, 0.65);
|
||||
|
||||
/* Today column */
|
||||
today_column = get_today_column (GCAL_WEEK_GRID (widget));
|
||||
|
||||
if (today_column != -1)
|
||||
{
|
||||
g_autoptr (GDateTime) now;
|
||||
GtkBorder margin;
|
||||
guint minutes_from_midnight;
|
||||
gint min_stip_height;
|
||||
|
||||
now = g_date_time_new_now_local ();
|
||||
minutes_from_midnight = g_date_time_get_hour (now) * 60 + g_date_time_get_minute (now);
|
||||
|
||||
gtk_style_context_save (context);
|
||||
gtk_style_context_add_class (context, "now-strip");
|
||||
|
||||
gtk_style_context_get (context, state, "min-height", &min_stip_height, NULL);
|
||||
gtk_style_context_get_margin (context, state, &margin);
|
||||
|
||||
gtk_render_background (context,
|
||||
cr,
|
||||
today_column * width / 7.0 + margin.left,
|
||||
round (minutes_from_midnight * ((gdouble) height / MINUTES_PER_DAY) + margin.top),
|
||||
width / 7.0 - margin.left - margin.right,
|
||||
MAX (1, min_stip_height - margin.top - margin.bottom));
|
||||
|
||||
gtk_style_context_restore (context);
|
||||
}
|
||||
|
||||
/* Vertical lines */
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
|
||||
@@ -163,6 +163,23 @@ get_end_of_week (icaltimetype *date)
|
||||
return week_end;
|
||||
}
|
||||
|
||||
static inline gint
|
||||
get_today_column (GcalWeekHeader *self)
|
||||
{
|
||||
g_autoptr(GDateTime) today, week_start;
|
||||
gint days_diff;
|
||||
|
||||
today = g_date_time_new_now_local ();
|
||||
week_start = get_start_of_week (self->active_date);
|
||||
days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
|
||||
|
||||
/* Today is out of range */
|
||||
if (g_date_time_compare (today, week_start) < 0 || days_diff > 7)
|
||||
return -1;
|
||||
|
||||
return days_diff;
|
||||
}
|
||||
|
||||
static gint
|
||||
get_event_start_weekday (GcalWeekHeader *self,
|
||||
GcalEvent *event)
|
||||
@@ -910,7 +927,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *bold_font;
|
||||
|
||||
gint i, font_height, current_cell;
|
||||
gint i, font_height, current_cell, today_column;
|
||||
gdouble cell_width;
|
||||
|
||||
cairo_save(cr);
|
||||
@@ -934,8 +951,10 @@ gcal_week_header_draw (GcalWeekHeader *self,
|
||||
week_end = g_date_time_add_days (week_start, 6);
|
||||
current_cell = icaltime_day_of_week (*(self->active_date)) - 1;
|
||||
current_cell = (7 + current_cell - self->first_weekday) % 7;
|
||||
today_column = get_today_column (self);
|
||||
|
||||
cell_width = alloc.width / 7.0;
|
||||
|
||||
pango_layout_get_pixel_size (layout, NULL, &font_height);
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
@@ -954,15 +973,18 @@ gcal_week_header_draw (GcalWeekHeader *self,
|
||||
gtk_style_context_save (context);
|
||||
gtk_style_context_add_class (context, "week-dates");
|
||||
gtk_style_context_get (context, state, "font", &bold_font, NULL);
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
if (i == today_column)
|
||||
gtk_style_context_add_class (context, "today");
|
||||
|
||||
pango_layout_set_font_description (layout, bold_font);
|
||||
pango_layout_set_text (layout, weekday_date, -1);
|
||||
cairo_move_to (cr,
|
||||
padding.left + cell_width * i + COLUMN_PADDING,
|
||||
font_height + padding.bottom);
|
||||
pango_cairo_show_layout (cr,layout);
|
||||
|
||||
gtk_render_layout (context,
|
||||
cr,
|
||||
padding.left + cell_width * i + COLUMN_PADDING,
|
||||
font_height + padding.bottom,
|
||||
layout);
|
||||
|
||||
gtk_style_context_restore (context);
|
||||
|
||||
@@ -973,24 +995,38 @@ gcal_week_header_draw (GcalWeekHeader *self,
|
||||
gtk_style_context_add_class (context, "week-names");
|
||||
gtk_style_context_get (context, state, "font", &bold_font, NULL);
|
||||
|
||||
if (i == today_column)
|
||||
gtk_style_context_add_class (context, "today");
|
||||
|
||||
pango_layout_set_font_description (layout, bold_font);
|
||||
pango_layout_set_text (layout, weekday_abv, -1);
|
||||
cairo_move_to (cr,
|
||||
padding.left + cell_width * i + COLUMN_PADDING,
|
||||
0);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
gtk_render_layout (context,
|
||||
cr,
|
||||
padding.left + cell_width * i + COLUMN_PADDING,
|
||||
0.0,
|
||||
layout);
|
||||
|
||||
gtk_style_context_restore (context);
|
||||
|
||||
/* Draws the lines after each day of the week */
|
||||
gtk_style_context_save (context);
|
||||
gtk_style_context_add_class (context, "lines");
|
||||
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
cairo_set_line_width (cr, 0.25);
|
||||
|
||||
cairo_move_to (cr,
|
||||
ALIGNED (cell_width * i),
|
||||
font_height + padding.bottom);
|
||||
|
||||
cairo_set_line_width (cr, 0.25);
|
||||
cairo_rel_line_to (cr, 0.0, gtk_widget_get_allocated_height (self->draw_area) - font_height + padding.bottom);
|
||||
cairo_stroke (cr);
|
||||
|
||||
gtk_style_context_restore (context);
|
||||
|
||||
g_free (weekday_date);
|
||||
g_free (weekday_abv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user