[gnome-calendar] date-chooser-day: Make it a button
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] date-chooser-day: Make it a button
- Date: Thu, 16 Jun 2022 11:44:35 +0000 (UTC)
commit f9c4501d6ca739c44af0fa9e6cd3a632af51746c
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Apr 6 12:26:33 2022 +0200
date-chooser-day: Make it a button
This stops reimplementing a flat button and use GtkButton directly
instead.
src/gui/event-editor/gcal-date-chooser-day.c | 70 +++++++---------------------
src/gui/event-editor/gcal-date-chooser-day.h | 5 +-
src/gui/event-editor/gcal-date-chooser.c | 2 +-
src/theme/Adwaita.css | 48 ++++++-------------
4 files changed, 35 insertions(+), 90 deletions(-)
---
diff --git a/src/gui/event-editor/gcal-date-chooser-day.c b/src/gui/event-editor/gcal-date-chooser-day.c
index aab5d7d5..e4f4dbb4 100644
--- a/src/gui/event-editor/gcal-date-chooser-day.c
+++ b/src/gui/event-editor/gcal-date-chooser-day.c
@@ -1,6 +1,7 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2015 Red Hat, Inc.
+ * Copyright (C) 2022 Purism SPC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -25,33 +26,15 @@
#include <stdlib.h>
#include <langinfo.h>
-enum {
- SELECTED,
- LAST_DAY_SIGNAL
-};
-
-static guint signals[LAST_DAY_SIGNAL] = { 0, };
-
struct _GcalDateChooserDay
{
- AdwBin parent;
+ GtkButton parent;
GtkWidget *label;
GDateTime *date;
};
-G_DEFINE_TYPE (GcalDateChooserDay, gcal_date_chooser_day, ADW_TYPE_BIN)
-
-static void
-day_pressed (GtkGestureClick *click_gesture,
- gint n_press,
- gdouble x,
- gdouble y,
- GcalDateChooserDay *self)
-{
- if (n_press == 1)
- g_signal_emit (self, signals[SELECTED], 0);
-}
+G_DEFINE_TYPE (GcalDateChooserDay, gcal_date_chooser_day, GTK_TYPE_BUTTON)
static void
gcal_date_chooser_day_dispose (GObject *object)
@@ -66,40 +49,23 @@ gcal_date_chooser_day_dispose (GObject *object)
static void
gcal_date_chooser_day_class_init (GcalDateChooserDayClass *class)
{
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = gcal_date_chooser_day_dispose;
-
- signals[SELECTED] = g_signal_new ("selected",
- GCAL_TYPE_DATE_CHOOSER_DAY,
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE, 0);
-
- gtk_widget_class_set_css_name (widget_class, "day");
-
- gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0, "selected", NULL);
- gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0, "selected", NULL);
- gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0, "selected", NULL);
- gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0, "selected", NULL);
- gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0, "selected", NULL);
}
static void
gcal_date_chooser_day_init (GcalDateChooserDay *self)
{
- GtkGesture *click_gesture;
GtkWidget *widget = GTK_WIDGET (self);
gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_widget_set_can_focus (widget, TRUE);
+ gtk_widget_add_css_class (widget, "circular");
gtk_widget_add_css_class (widget, "day");
+ gtk_widget_add_css_class (widget, "flat");
self->label = gtk_label_new ("");
gtk_widget_set_halign (self->label, GTK_ALIGN_CENTER);
@@ -107,17 +73,7 @@ gcal_date_chooser_day_init (GcalDateChooserDay *self)
gtk_widget_set_hexpand (self->label, TRUE);
gtk_widget_set_vexpand (self->label, TRUE);
- adw_bin_set_child (ADW_BIN (self), self->label);
-
- click_gesture = gtk_gesture_click_new ();
- gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (click_gesture), 0);
- gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (click_gesture));
-
- g_signal_connect_object (click_gesture,
- "pressed",
- G_CALLBACK (day_pressed),
- self,
- 0);
+ gtk_button_set_child (GTK_BUTTON (self), self->label);
}
GtkWidget*
@@ -160,8 +116,16 @@ void
gcal_date_chooser_day_set_selected (GcalDateChooserDay *self,
gboolean selected)
{
- if (selected)
- gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE);
+ GtkWidget *widget = GTK_WIDGET (self);
+
+ if (G_UNLIKELY (selected))
+ {
+ gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
+ gtk_widget_remove_css_class (widget, "flat");
+ }
else
- gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED);
+ {
+ gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_SELECTED);
+ gtk_widget_add_css_class (widget, "flat");
+ }
}
diff --git a/src/gui/event-editor/gcal-date-chooser-day.h b/src/gui/event-editor/gcal-date-chooser-day.h
index 109f1211..e4c11bb1 100644
--- a/src/gui/event-editor/gcal-date-chooser-day.h
+++ b/src/gui/event-editor/gcal-date-chooser-day.h
@@ -1,5 +1,6 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2015 Red Hat, Inc.
+ * Copyright (C) 2022 Purism SPC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,12 +18,12 @@
#pragma once
-#include <adwaita.h>
+#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_DATE_CHOOSER_DAY (gcal_date_chooser_day_get_type())
-G_DECLARE_FINAL_TYPE (GcalDateChooserDay, gcal_date_chooser_day, GCAL, DATE_CHOOSER_DAY, AdwBin)
+G_DECLARE_FINAL_TYPE (GcalDateChooserDay, gcal_date_chooser_day, GCAL, DATE_CHOOSER_DAY, GtkButton)
GtkWidget* gcal_date_chooser_day_new (void);
diff --git a/src/gui/event-editor/gcal-date-chooser.c b/src/gui/event-editor/gcal-date-chooser.c
index 89a0504a..c43181f9 100644
--- a/src/gui/event-editor/gcal-date-chooser.c
+++ b/src/gui/event-editor/gcal-date-chooser.c
@@ -579,7 +579,7 @@ gcal_date_chooser_init (GcalDateChooser *self)
self->days[row][col] = gcal_date_chooser_day_new ();
g_signal_connect_object (self->days[row][col],
- "selected",
+ "clicked",
G_CALLBACK (day_selected_cb),
self,
0);
diff --git a/src/theme/Adwaita.css b/src/theme/Adwaita.css
index 18401020..15df3433 100644
--- a/src/theme/Adwaita.css
+++ b/src/theme/Adwaita.css
@@ -182,50 +182,30 @@ datechooser .weekday:backdrop {
}
/* days */
-datechooser day {
- transition-property: background-color;
- transition-duration: 200ms;
+datechooser button.day {
+ font-size: 10pt;
+ font-weight: normal;
+ margin: 3px;
+ min-height: 28px;
+ min-width: 28px;
+ transition: none;
}
-datechooser day label {
- transition-property: color;
- transition-duration: 200ms;
-}
-
-datechooser day {
- min-height: 32px;
- min-width: 32px;
- border-radius: 50%;
+datechooser button.day:selected {
+ background-color: @accent_bg_color;
+ color: @accent_fg_color;
+ font-weight: bold;
}
-datechooser day.other-month:not(:hover),
-datechooser day.other-month:backdrop {
+datechooser button.day.other-month:not(:hover),
+datechooser button.day.other-month:backdrop {
color: alpha(currentColor, 0.1);
}
-/* avoid the theme interfering with label colors */
-datechooser day:selected label,
-datechooser day.other-month label:hover,
-datechooser day.other-month label:backdrop {
- color: currentColor;
-}
-
-/* hovered days style */
-datechooser day:hover:not(:backdrop) {
- background-color: alpha(currentColor, 0.1);
-}
-
-datechooser day.other-month:hover:not(:backdrop) {
+datechooser button.day.other-month:hover:not(:backdrop) {
color: @insensitive_fg_color;
}
-datechooser day:selected,
-datechooser day:selected:hover {
- color: @accent_fg_color;
- background-color: @accent_bg_color;
- font-weight: bold;
-}
-
label.month-name {
font-size: 16pt;
font-weight: bold;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]