[gtk/wip/baedert/for-master: 21/27] calendar: Add style class to today's label



commit 7b18f4443ecdc6d0302503ec5fddc1dd8a058c13
Author: Timm Bäder <mail baedert org>
Date:   Thu Feb 13 18:40:20 2020 +0100

    calendar: Add style class to today's label
    
    Add the .today style class to the label indicating the current day.
    
    Fixes #230

 gtk/gtkcalendar.c              | 20 +++++++++++++++++++-
 gtk/theme/Adwaita/_common.scss |  8 ++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 0b13b5fe64..5525b4263d 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -60,7 +60,7 @@
  * │   ├── label.year
  * │   ╰── button
  * ╰── grid
- *     ╰── label[.day-name][.week-number][.day-number][.other-month]
+ *     ╰── label[.day-name][.week-number][.day-number][.other-month][.today]
  * ]|
  *
  * GtkCalendar has a main node with name calendar. It contains a subnode called header
@@ -71,6 +71,7 @@
  * css class).
  *
  * Day labels that belong to the previous or next month get the .other-month style class.
+ * The label of the current day get the .today style class.
  *
  * Marked day labels get the :selected state assigned.
  */
@@ -1581,6 +1582,7 @@ gtk_calendar_select_day (GtkCalendar *self,
                          GDateTime   *date)
 {
   GtkCalendarPrivate *priv = gtk_calendar_get_instance_private (self);
+  GDateTime *today;
   int new_day, new_month, new_year;
   gboolean day_changed, month_changed, year_changed;
   char buffer[255];
@@ -1589,6 +1591,7 @@ gtk_calendar_select_day (GtkCalendar *self,
   struct tm *tm;
   int i;
   int x, y;
+  int today_day;
 
   g_return_if_fail (GTK_IS_CALENDAR (self));
   g_return_if_fail (date != NULL);
@@ -1628,6 +1631,16 @@ gtk_calendar_select_day (GtkCalendar *self,
   gtk_stack_set_visible_child_name (GTK_STACK (priv->month_name_stack),
                                     default_monthname[new_month - 1]);
 
+  today = g_date_time_new_now_local ();
+
+  if (g_date_time_get_year (priv->date) == g_date_time_get_year (today) &&
+      g_date_time_get_month (priv->date) == g_date_time_get_month (today))
+    today_day = g_date_time_get_day_of_month (today);
+  else
+    today_day = -1;
+
+  g_date_time_unref (today);
+
   /* Update day labels */
   for (y = 0; y < 6; y ++)
     for (x = 0; x < 7; x ++)
@@ -1664,6 +1677,11 @@ gtk_calendar_select_day (GtkCalendar *self,
           gtk_widget_set_state_flags (label, GTK_STATE_FLAG_SELECTED, FALSE);
         else
           gtk_widget_unset_state_flags (label, GTK_STATE_FLAG_SELECTED);
+
+        if (day == today_day)
+          gtk_widget_add_css_class (label, "today");
+        else
+          gtk_widget_remove_css_class (label, "today");
       }
 
   /* Update week number labels.
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 6f12535e86..14c3877547 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -3403,6 +3403,14 @@ calendar {
     > label.week-number {
     }
 
+    > label.today {
+      box-shadow: inset 0px -2px $borders_color;
+
+      &:selected {
+        box-shadow: none;
+      }
+    }
+
     > label.day-number {
       padding: 4px;
 


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