fontchooser: Improve accessibility

Set up missing accessible relations, labels and roles.
This commit is contained in:
Matthias Clasen 2023-06-10 11:00:35 -04:00
parent cf30a4f304
commit f20ef5a0fc
2 changed files with 42 additions and 2 deletions

View File

@ -1594,6 +1594,9 @@ add_axis (GtkFontChooserWidget *fontchooser,
(double)ax->max_value,
1.0, 10.0, 0.0);
axis->scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, axis->adjustment);
gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->scale),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL,
-1);
gtk_scale_add_mark (GTK_SCALE (axis->scale), (double)ax->default_value, GTK_POS_TOP, NULL);
gtk_widget_set_valign (axis->scale, GTK_ALIGN_BASELINE_FILL);
gtk_widget_set_hexpand (axis->scale, TRUE);
@ -1601,6 +1604,9 @@ add_axis (GtkFontChooserWidget *fontchooser,
gtk_scale_set_draw_value (GTK_SCALE (axis->scale), FALSE);
gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->scale, 1, row, 1, 1);
axis->spin = gtk_spin_button_new (axis->adjustment, 0, 0);
gtk_accessible_update_relation (GTK_ACCESSIBLE (axis->spin),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, axis->label, NULL,
-1);
g_signal_connect (axis->spin, "output", G_CALLBACK (output_cb), fontchooser);
gtk_widget_set_valign (axis->spin, GTK_ALIGN_BASELINE_FILL);
gtk_grid_attach (GTK_GRID (fontchooser->axis_grid), axis->spin, 2, row, 1, 1);
@ -2345,7 +2351,7 @@ add_enum_group (GtkFontChooserWidget *fontchooser,
const char **tags,
unsigned int n_tags)
{
GtkWidget *label;
GtkWidget *label = NULL;
GtkWidget *group;
PangoAttrList *attrs;
int i;
@ -2433,6 +2439,9 @@ add_radio_group (GtkFontChooserWidget *fontchooser,
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
gtk_box_append (GTK_BOX (group), label);
gtk_accessible_update_relation (GTK_ACCESSIBLE (group),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
for (i = 0; i < n_tags; i++)
{

View File

@ -196,6 +196,9 @@
<child>
<object class="GtkEntry" id="preview">
<property name="tooltip-text" translatable="yes">Preview Font</property>
<accessibility>
<property name="label" translatable="yes">Preview Font</property>
</accessibility>
<child>
<object class="GtkEventControllerScroll">
<property name="flags">horizontal</property>
@ -225,6 +228,9 @@
<property name="hexpand">1</property>
<property name="adjustment">slider_adjustment</property>
<property name="round-digits">0</property>
<accessibility>
<relation name="labelled-by">size_label</relation>
</accessibility>
<child>
<object class="GtkEventControllerScroll">
<property name="flags">horizontal</property>
@ -241,6 +247,9 @@
<object class="GtkSpinButton" id="size_spin">
<property name="adjustment">spin_adjustment</property>
<property name="valign">3</property>
<accessibility>
<relation name="labelled-by">size_label</relation>
</accessibility>
<signal name="output" handler="output_cb"/>
<layout>
<property name="column">2</property>
@ -262,6 +271,10 @@
<property name="vexpand">1</property>
<property name="halign">3</property>
<property name="valign">3</property>
<property name="accessible-role">alert</property>
<accessibility>
<relation name="labelled-by">no_fonts_label</relation>
</accessibility>
<style>
<class name="dim-label"/>
</style>
@ -276,7 +289,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="no_fonts_label">
<property name="label" translatable="yes">No Fonts Found</property>
<attributes>
<attribute name="weight" value="bold"></attribute>
@ -317,6 +330,9 @@
<property name="margin-end">12</property>
<property name="ellipsize">3</property>
<property name="xalign">0</property>
<accessibility>
<property name="description" translatable="1">Font Name</property>
</accessibility>
<binding name="label" object="GtkFontChooserWidget">
<closure type="gchararray" function="get_font_name">
<lookup name="selected-item">selection</lookup>
@ -334,6 +350,9 @@
<property name="tooltip-text" translatable="yes">Preview Font</property>
<property name="text" bind-source="preview" bind-property="text" bind-flags="bidirectional"/>
<property name="attributes" bind-source="preview" bind-property="attributes" bind-flags="bidirectional"/>
<accessibility>
<property name="label" translatable="yes">Preview Font</property>
</accessibility>
</object>
</child>
<child>
@ -356,6 +375,9 @@
<object class="GtkGrid" id="axis_grid">
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<accessibility>
<property name="label" translatable="1">Font Variation Axes</property>
</accessibility>
<child>
<object class="GtkLabel" id="size_label2">
<property name="label" translatable="yes">Size</property>
@ -372,6 +394,9 @@
<property name="hexpand">1</property>
<property name="adjustment">slider_adjustment</property>
<property name="round-digits">0</property>
<accessibility>
<relation name="labelled-by">size_label2</relation>
</accessibility>
<layout>
<property name="column">1</property>
<property name="row">0</property>
@ -383,6 +408,9 @@
<property name="adjustment">spin_adjustment</property>
<property name="valign">3</property>
<signal name="output" handler="output_cb"/>
<accessibility>
<relation name="labelled-by">size_label2</relation>
</accessibility>
<layout>
<property name="column">2</property>
<property name="row">0</property>
@ -395,6 +423,9 @@
<object class="GtkBox" id="feature_box">
<property name="orientation">1</property>
<property name="spacing">12</property>
<accessibility>
<property name="label" translatable="1">Font Features</property>
</accessibility>
</object>
</child>
</object>