year-view: add hover effect to the navigator

The current implementation of the Year navigator gives
absolutely no clue that the days are actually selectable,
which may confuse some users.

A simple way to inform the user that the Year navigator
is actually interactive is the hovering effect.

Fix the lack of feedback by adding the hover effect to the
year navigator.

https://bugzilla.gnome.org/show_bug.cgi?id=762462
This commit is contained in:
Georges Basile Stavracas Neto
2016-05-20 22:09:00 -03:00
parent 8fd6138972
commit 6a8a4dfad0
2 changed files with 60 additions and 15 deletions
+5
View File
@@ -122,6 +122,11 @@ calendar-view.second-view-header {
font-weight: bold; font-weight: bold;
} }
.year-navigator:hover {
background-color: alpha(@theme_fg_color, 0.1);
border-radius: 2px;
}
.year-navigator.with-events { .year-navigator.with-events {
background-color: @theme_fg_color; background-color: @theme_fg_color;
border-radius: 3px; border-radius: 3px;
+55 -15
View File
@@ -34,6 +34,7 @@ typedef struct
/* month span from 0 to 11 */ /* month span from 0 to 11 */
gint start_day, start_month; gint start_day, start_month;
gint end_day, end_month; gint end_day, end_month;
gint hovered_day, hovered_month;
} ButtonData; } ButtonData;
typedef struct typedef struct
@@ -729,6 +730,27 @@ draw_month_grid (GcalYearView *year_view,
box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0; box_padding_top = (box_side - layout_height) / 2 > 0 ? (box_side - layout_height) / 2 : 0;
box_padding_start = (box_side - layout_width) / 2 > 0 ? (box_side - layout_width) / 2 : 0; box_padding_start = (box_side - layout_width) / 2 > 0 ? (box_side - layout_width) / 2 : 0;
/* Draw the hover background */
if (year_view->selected_data->hovered_day == j &&
year_view->selected_data->hovered_month == month_nr)
{
gint hover_x, hover_y;
hover_x = box_side * column + x + sw * box_padding_start / 2.0 - year_view->k * box_side - 2.0;
hover_y = box_side * (row + 1) + y + box_padding_top - 1.0;
gtk_style_context_set_state (context, state_flags | GTK_STATE_FLAG_PRELIGHT);
gtk_render_background (context,
cr,
hover_x,
hover_y,
box_side - box_padding_start / 2.0,
box_side);
gtk_style_context_set_state (context, state_flags);
}
selected_day = FALSE; selected_day = FALSE;
if (year_view->selected_data->start_day != 0) if (year_view->selected_data->start_day != 0)
{ {
@@ -1054,25 +1076,43 @@ navigator_motion_notify_cb (GcalYearView *year_view,
gint day, month; gint day, month;
gboolean is_title = FALSE; gboolean is_title = FALSE;
if (!year_view->button_pressed) if (calculate_day_month_for_coord (year_view, event->x, event->y, &day, &month, &is_title))
return FALSE; {
if (year_view->button_pressed)
{
/* Cancel the hover when selecting a date range */
year_view->selected_data->hovered_day = -1;
year_view->selected_data->hovered_month = -1;
if (!calculate_day_month_for_coord (year_view, event->x, event->y, &day, &month, &is_title)) if (is_title)
goto fail; day = g_date_get_days_in_month (month + 1, year_view->date->year);
if (is_title) year_view->selected_data->end_day = day;
day = g_date_get_days_in_month (month + 1, year_view->date->year); year_view->selected_data->end_month = month;
gtk_widget_queue_draw (widget);
year_view->selected_data->end_day = day; return GDK_EVENT_STOP;
year_view->selected_data->end_month = month; }
gtk_widget_queue_draw (widget); else
return TRUE; {
/* We only deal with the hover effect when the button is not pressed */
year_view->selected_data->hovered_day = day;
year_view->selected_data->hovered_month = month;
gtk_widget_queue_draw (widget);
fail: return GDK_EVENT_PROPAGATE;
year_view->selected_data->end_day = year_view->selected_data->start_day; }
year_view->selected_data->end_month = year_view->selected_data->start_month; }
gtk_widget_queue_draw (widget); else
return TRUE; {
/* Reset the end day */
year_view->selected_data->end_day = year_view->selected_data->start_day;
year_view->selected_data->end_month = year_view->selected_data->start_month;
gtk_widget_queue_draw (widget);
return GDK_EVENT_STOP;
}
} }
static void static void