Update GcalMultiChoice label when format callback changes

Currently the label text is only updated when set_value is called and
the new value is different to the current value. So if a format callback
is configured after the GcalMultiChoice is created, this won't be
applied until the value is changed to something other than the default.

The problem in issue #100 is that the default value for "month" is
0=>January. gcal_date_chooser_init sets the format callback and then
calls gcal_multi_choice_set_value with value==0 which won't update the
label.

Fix by having gcal_multi_choice_set_format_callback update the label
text with the result of applying the format callback to the current
value.

Fixes #100
This commit is contained in:
Nick Gasson
2019-10-01 17:44:04 +00:00
parent a6066f2203
commit b034bd4bf0
+20 -11
View File
@@ -79,21 +79,13 @@ get_value_string (GcalMultiChoice *self,
}
static void
set_value (GcalMultiChoice *self,
gint value,
GtkStackTransitionType transition)
apply_value (GcalMultiChoice *self,
GtkStackTransitionType transition)
{
GtkWidget *label;
const gchar *name;
gchar *text;
value = CLAMP (value, self->min_value, self->max_value);
if (self->value == value)
return;
self->value = value;
if (gtk_stack_get_visible_child (GTK_STACK (self->stack)) == self->label1)
{
name = "label2";
@@ -105,7 +97,7 @@ set_value (GcalMultiChoice *self,
label = self->label1;
}
text = get_value_string (self, value);
text = get_value_string (self, self->value);
gtk_label_set_text (GTK_LABEL (label), text);
g_free (text);
@@ -118,6 +110,21 @@ set_value (GcalMultiChoice *self,
self->wrap || self->value > self->min_value);
gtk_widget_set_sensitive (self->up_button,
self->wrap || self->value < self->max_value);
}
static void
set_value (GcalMultiChoice *self,
gint value,
GtkStackTransitionType transition)
{
value = CLAMP (value, self->min_value, self->max_value);
if (self->value == value)
return;
self->value = value;
apply_value (self, transition);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]);
}
@@ -489,4 +496,6 @@ gcal_multi_choice_set_format_callback (GcalMultiChoice *self,
self->format_cb = callback;
self->format_data = user_data;
self->format_destroy = destroy;
apply_value (self, GTK_STACK_TRANSITION_TYPE_NONE);
}