date-chooser-day: Add the has-dot and dot-visible properties

This allows the days to display events.
This commit is contained in:
Adrien Plazas
2022-06-16 09:29:16 +02:00
parent 0ff62c4314
commit 7198ce41f9
4 changed files with 233 additions and 8 deletions
@@ -30,10 +30,20 @@ struct _GcalDateChooserDay
{
GtkButton parent;
GtkWidget *dot_revealer;
GtkWidget *label;
GDateTime *date;
};
enum {
PROP_0,
PROP_HAS_DOT,
PROP_DOT_VISIBLE,
NUM_PROPS
};
static GParamSpec *properties[NUM_PROPS] = { NULL, };
G_DEFINE_TYPE (GcalDateChooserDay, gcal_date_chooser_day, GTK_TYPE_BUTTON)
static void
@@ -46,6 +56,52 @@ gcal_date_chooser_day_dispose (GObject *object)
G_OBJECT_CLASS (gcal_date_chooser_day_parent_class)->dispose (object);
}
static void
gcal_date_chooser_day_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GcalDateChooserDay *self = GCAL_DATE_CHOOSER_DAY (object);
switch (prop_id)
{
case PROP_HAS_DOT:
g_value_set_boolean (value, gcal_date_chooser_day_get_has_dot (self));
break;
case PROP_DOT_VISIBLE:
g_value_set_boolean (value, gcal_date_chooser_day_get_dot_visible (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_date_chooser_day_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GcalDateChooserDay *self = GCAL_DATE_CHOOSER_DAY (object);
switch (prop_id)
{
case PROP_HAS_DOT:
gcal_date_chooser_day_set_has_dot (self, g_value_get_boolean (value));
break;
case PROP_DOT_VISIBLE:
gcal_date_chooser_day_set_dot_visible (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gcal_date_chooser_day_class_init (GcalDateChooserDayClass *class)
{
@@ -53,9 +109,44 @@ gcal_date_chooser_day_class_init (GcalDateChooserDayClass *class)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
object_class->dispose = gcal_date_chooser_day_dispose;
object_class->get_property = gcal_date_chooser_day_get_property;
object_class->set_property = gcal_date_chooser_day_set_property;
/**
* GcalDateChooserDay:has-dot:
*
* Whether the day has a dot or not.
*
* If the day has a dot, the label will be excentered to leave room for the
* dot, it will be centered otherwise.
*/
properties[PROP_HAS_DOT] =
g_param_spec_boolean ("has-dot",
"Has dot",
"Whether the day has a dot or not",
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GcalDateChooserDay:dot-visible:
*
* Whether the dot is visible or not.
*
* There will be no visible dot if [property@GcalDateChooserDay:has-dot] is
* #FALSE.
*/
properties[PROP_DOT_VISIBLE] =
g_param_spec_boolean ("dot-visible",
"Dot visible",
"Whether the dot is visible or not",
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, NUM_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/event-editor/gcal-date-chooser-day.ui");
gtk_widget_class_bind_template_child (widget_class, GcalDateChooserDay, dot_revealer);
gtk_widget_class_bind_template_child (widget_class, GcalDateChooserDay, label);
}
@@ -101,6 +192,86 @@ gcal_date_chooser_day_set_other_month (GcalDateChooserDay *self,
gtk_widget_remove_css_class (GTK_WIDGET (self), "other-month");
}
/**
* gcal_date_chooser_day_set_has_dot:
* @self: a #GcalDateChooserDay
* @has_dot: whether the day has a dot or not.
*
* Sets whether the day has a dot or not.
*
* If the day has a dot, the label will be excentered to leave room for the
* dot, it will be centered otherwise.
*/
void
gcal_date_chooser_day_set_has_dot (GcalDateChooserDay *self,
gboolean has_dot)
{
g_return_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self));
has_dot = !!has_dot;
if (gtk_widget_get_visible (self->dot_revealer) == has_dot)
return;
gtk_widget_set_visible (self->dot_revealer, has_dot);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HAS_DOT]);
}
/**
* gcal_date_chooser_day_get_has_dot:
* @self: a #GcalDateChooserDay
*
* Returns: whether the day has a dot or not.
*/
gboolean
gcal_date_chooser_day_get_has_dot (GcalDateChooserDay *self)
{
g_return_val_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self), FALSE);
return gtk_widget_get_visible (self->dot_revealer);
}
/**
* gcal_date_chooser_day_set_dot_visible:
* @self: a #GcalDateChooserDay
* @dot_visible: whether the dot is visible or not.
*
* Sets whether the dot is visible or not.
*
* There will be no visible dot if [property@GcalDateChooserDay:has-dot] is
* #FALSE.
*/
void
gcal_date_chooser_day_set_dot_visible (GcalDateChooserDay *self,
gboolean dot_visible)
{
g_return_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self));
dot_visible = !!dot_visible;
if (gtk_revealer_get_reveal_child (GTK_REVEALER (self->dot_revealer)) == dot_visible)
return;
gtk_revealer_set_reveal_child (GTK_REVEALER (self->dot_revealer), dot_visible);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DOT_VISIBLE]);
}
/**
* gcal_date_chooser_day_get_dot_visible:
* @self: a #GcalDateChooserDay
*
* Returns: whether the dot is visible or not.
*/
gboolean
gcal_date_chooser_day_get_dot_visible (GcalDateChooserDay *self)
{
g_return_val_if_fail (GCAL_IS_DATE_CHOOSER_DAY (self), FALSE);
return gtk_revealer_get_reveal_child (GTK_REVEALER (self->dot_revealer));
}
void
gcal_date_chooser_day_set_selected (GcalDateChooserDay *self,
gboolean selected)
@@ -32,6 +32,16 @@ GDateTime* gcal_date_chooser_day_get_date (GcalDateChoose
void gcal_date_chooser_day_set_date (GcalDateChooserDay *day,
GDateTime *date);
gboolean gcal_date_chooser_day_get_has_dot (GcalDateChooserDay *day);
void gcal_date_chooser_day_set_has_dot (GcalDateChooserDay *day,
gboolean has_dot);
gboolean gcal_date_chooser_day_get_dot_visible (GcalDateChooserDay *day);
void gcal_date_chooser_day_set_dot_visible (GcalDateChooserDay *day,
gboolean dot_visible);
void gcal_date_chooser_day_set_other_month (GcalDateChooserDay *day,
gboolean other_month);
+32 -8
View File
@@ -3,21 +3,45 @@
<template class="GcalDateChooserDay" parent="GtkButton">
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<style>
<class name="circular"/>
<class name="day"/>
<class name="flat"/>
<class name="text-button"/>
</style>
<child>
<object class="GtkLabel" id="label">
<property name="halign">center</property>
<property name="hexpand">True</property>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="width-chars">2</property>
<style>
<class name="numeric"/>
</style>
<child>
<object class="GtkLabel" id="label">
<property name="halign">center</property>
<property name="label">0</property>
<property name="valign">center</property>
<property name="width-chars">2</property>
<style>
<class name="day"/>
<class name="numeric"/>
</style>
</object>
</child>
<child>
<object class="GtkRevealer" id="dot_revealer">
<property name="halign">center</property>
<property name="transition-type">crossfade</property>
<property name="valign">end</property>
<property name="visible">False</property>
<property name="child">
<object class="AdwBin" id="dot">
<property name="css-name">dot</property>
<property name="halign">center</property>
<property name="valign">center</property>
</object>
</property>
</object>
</child>
</object>
</child>
</template>
+20
View File
@@ -191,21 +191,41 @@ datechooser button.day {
transition: none;
}
datechooser button.day dot {
background-color: @theme_fg_color;
border-radius: 50%;
min-height: 3px;
min-width: 3px;
}
datechooser button.day:selected {
background-color: @accent_bg_color;
color: @accent_fg_color;
font-weight: bold;
}
datechooser button.day:selected dot {
background-color: @accent_fg_color;
}
datechooser button.day.other-month:not(:hover),
datechooser button.day.other-month:backdrop {
color: alpha(currentColor, 0.1);
}
datechooser button.day.other-month:not(:hover) dot,
datechooser button.day.other-month:backdrop dot {
background-color: alpha(currentColor, 0.1);
}
datechooser button.day.other-month:hover:not(:backdrop) {
color: @insensitive_fg_color;
}
datechooser button.day.other-month:hover:not(:backdrop) dot {
background-color: @insensitive_fg_color;
}
label.month-name {
font-size: 16pt;
font-weight: bold;