[gnome-calendar] month-view: grey out invalid days



commit d11ed85a7f94b7d350b0448d8452f01606a04eb6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jul 30 16:03:39 2017 +0100

    month-view: grey out invalid days
    
    It should be very clear that days outside the current
    month are actually not valid. The current drawing
    algorithm does not differentiate that, thought, and
    draws everything at the same color.
    
    Fix that by greying out the days outside the current
    month.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763771

 data/theme/gtk-styles.css   |    4 +++
 src/views/gcal-month-view.c |   62 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 061373f..d53f784 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -56,6 +56,10 @@ calendar-view.lines {
     color: alpha(@theme_fg_color, 0.4);
 }
 
+calendar-view.offset {
+    background-color: alpha(@theme_bg_color, 0.5);
+}
+
 /* Year View CSS */
 .year-view {
     padding: 0px;
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index d8c0073..52c2894 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -1479,15 +1479,21 @@ gcal_month_view_draw (GtkWidget *widget,
 
   gint font_width, font_height, pos_x, pos_y, shown_rows;
   gint i, j, sw, lower_mark = 43, upper_mark = -2;
-  gint cell_width, cell_height;
+  gint unused_start, unused_start_width;
+  gint unused_end, unused_end_width;
+  gdouble cell_width, cell_height;
   gdouble start_grid_y, first_row_gap = 0.0;
   gdouble days;
 
+  gboolean is_ltr;
+
   self = GCAL_MONTH_VIEW (widget);
   ppriv = GCAL_SUBSCRIBER_VIEW (widget)->priv;
 
   today = g_date_time_new_now_local ();
 
+  is_ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
+
   /* fonts and colors selection */
   context = gtk_widget_get_style_context (widget);
   state = gtk_style_context_get_state (context);
@@ -1619,6 +1625,60 @@ gcal_month_view_draw (GtkWidget *widget,
                              cell_height + 1);
     }
 
+  /* grey background on cells outside the current month */
+  unused_start = is_ltr ? 0 : real_cell (self->days_delay - 1, self->k);
+  unused_start_width = self->days_delay;
+
+  unused_end = is_ltr ? real_cell (days, self->k) % 7 : 0;
+  unused_end_width = 7 * shown_rows - days;
+
+  gtk_style_context_save (context);
+  gtk_style_context_add_class (context, "offset");
+
+  /* Half-cell at the top and bottom */
+  if (shown_rows == 5)
+    {
+      gdouble half_cell = cell_height / 2.0;
+
+      gtk_render_background (context,
+                             cr,
+                             0,
+                             start_grid_y,
+                             alloc.width,
+                             half_cell);
+
+      gtk_render_background (context,
+                             cr,
+                             0,
+                             start_grid_y + cell_height * (shown_rows + first_row_gap),
+                             alloc.width,
+                             cell_height / 2);
+    }
+
+  /* Unused cells at the start */
+  if (unused_start_width > 0)
+    {
+      gtk_render_background (context,
+                             cr,
+                             floor (cell_width * unused_start),
+                             floor (cell_height * first_row_gap + start_grid_y),
+                             cell_width * unused_start_width,
+                             cell_height + 1);
+    }
+
+  /* Unused cells at the end */
+  if (unused_end_width > 0)
+    {
+      gtk_render_background (context,
+                         cr,
+                         floor (cell_width * unused_end),
+                         floor (start_grid_y + cell_height * (first_row_gap + shown_rows - 1)),
+                         cell_width * unused_end_width + 1,
+                         cell_height + 1);
+    }
+
+  gtk_style_context_restore (context);
+
   /* grid numbers */
   gtk_style_context_get (context, state, "font", &font_desc, NULL);
   pango_layout_set_font_description (layout, font_desc);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]