multi-choice: Bind category to tooltip + a11y label

This adds a tooltip to the multi choice buttons, with the text
"Previous/Next (category)". This fixes the warnings in the date
chooser popover.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/681>
This commit is contained in:
Zoey Ahmed
2026-01-29 02:21:43 +00:00
committed by Marge Bot
parent 42595e4a65
commit 272f7fd34f
3 changed files with 41 additions and 20 deletions
+5 -20
View File
@@ -12,13 +12,10 @@ template $GcalDateChooser: Adw.Bin {
animate: false;
value: 0;
wrap: true;
category: _("Month");
visible: bind $get_split_choice_visible(template.show-heading, template.split-month-year) as <bool>;
notify::value => $split_multi_choice_changed() swapped;
accessibility {
label: _("Month");
}
layout {
column: 0;
row: 0;
@@ -32,12 +29,9 @@ template $GcalDateChooser: Adw.Bin {
max-value: 9999;
animate: false;
value: 0;
category: _("Year");
notify::value => $split_multi_choice_changed() swapped;
accessibility {
label: _("Year");
}
layout {
column: 1;
row: 0;
@@ -52,12 +46,9 @@ template $GcalDateChooser: Adw.Bin {
popover: popover;
animate: false;
value: 0;
category: _("Month");
notify::value => $combined_multi_choice_changed() swapped;
accessibility {
label: _("Month");
}
layout {
column: 0;
column-span: 2;
@@ -89,10 +80,7 @@ Popover popover {
max-value: bind month_choice.max-value bidirectional;
animate: bind month_choice.animate bidirectional;
value: bind month_choice.value bidirectional;
accessibility {
label: _("Month");
}
category: bind month_choice.category bidirectional;
}
$GcalMultiChoice {
@@ -100,10 +88,7 @@ Popover popover {
max-value: bind year_choice.max-value bidirectional;
animate: bind year_choice.animate bidirectional;
value: bind year_choice.value bidirectional;
accessibility {
label: _("Year");
}
category: bind year_choice.category bidirectional;
}
styles [
@@ -3,11 +3,13 @@ using Gtk 4.0;
template $GcalMultiChoice: Box {
spacing: 6;
accessible-role: spin_button;
notify::category => $set_accessibility_label() swapped;
Button down_button {
icon-name: "pan-start-symbolic";
clicked => $button_clicked_cb();
can-focus: false;
tooltip-text: bind $get_down_button_tooltip(template.category) as <string>;
styles [
"back-button",
@@ -53,6 +55,7 @@ template $GcalMultiChoice: Box {
icon-name: "pan-end-symbolic";
clicked => $button_clicked_cb();
can-focus: false;
tooltip-text: bind $get_up_button_tooltip(template.category) as <string>;
styles [
"circular",
+33
View File
@@ -24,6 +24,8 @@
#include "gcal-multi-choice.h"
#include <glib/gi18n.h>
struct _GcalMultiChoice
{
GtkBox parent;
@@ -159,6 +161,26 @@ set_value (GcalMultiChoice *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]);
}
static gchar *
get_down_button_tooltip (GcalMultiChoice *self,
gchar *category)
{
g_autofree gchar *formatted_tooltip = NULL;
formatted_tooltip = g_strdup_printf (_("Previous %1$s"), category);
return g_steal_pointer (&formatted_tooltip);
}
static gchar *
get_up_button_tooltip (GcalMultiChoice *self,
gchar *category)
{
g_autofree gchar *formatted_tooltip = NULL;
formatted_tooltip = g_strdup_printf (_("Next %1$s"), category);
return g_steal_pointer (&formatted_tooltip);
}
static void
go_up (GcalMultiChoice *self)
{
@@ -224,6 +246,14 @@ update_sensitivity (GcalMultiChoice *self)
GTK_ACCESSIBLE_RELATION_CONTROLS);
}
static void
set_accessibility_label (GcalMultiChoice *self)
{
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_PROPERTY_LABEL,
gcal_multi_choice_get_category (self), -1);
}
static void
button_clicked_cb (GtkWidget *button,
GcalMultiChoice *self)
@@ -672,10 +702,13 @@ gcal_multi_choice_class_init (GcalMultiChoiceClass *class)
gtk_widget_class_bind_template_child (widget_class, GcalMultiChoice, label1);
gtk_widget_class_bind_template_child (widget_class, GcalMultiChoice, label2);
gtk_widget_class_bind_template_callback (widget_class, set_accessibility_label);
gtk_widget_class_bind_template_callback (widget_class, button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, button_toggled_cb);
gtk_widget_class_bind_template_callback (widget_class, button_state_flags_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, key_pressed_cb);
gtk_widget_class_bind_template_callback (widget_class, get_down_button_tooltip);
gtk_widget_class_bind_template_callback (widget_class, get_up_button_tooltip);
gtk_widget_class_set_css_name (widget_class, "navigator");
}