gtk4-demo: Some a11y improvements

Add some labels in the pickers demo.
This commit is contained in:
Matthias Clasen 2023-06-11 07:04:56 -04:00
parent 0f39069be1
commit 1b829c7d01
6 changed files with 67 additions and 26 deletions

View File

@ -162,6 +162,10 @@ create_page4 (GtkWidget *assistant)
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), progress_bar, GTK_ASSISTANT_PAGE_PROGRESS);
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), progress_bar, "Applying changes");
gtk_accessible_update_property (GTK_ACCESSIBLE (progress_bar),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Applying changes",
-1);
/* This prevents the assistant window from being
* closed while we're "busy" applying changes.
*/

View File

@ -49,6 +49,7 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">switch</property>
</object>
</child>
<child>
@ -73,6 +74,7 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">check</property>
</object>
</child>
<child>
@ -110,6 +112,7 @@
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="opacity">0</property>
<property name="accessible-role">status</property>
</object>
</child>
</object>
@ -150,10 +153,11 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">scale</property>
</object>
</child>
<child>
<object class="GtkScale">
<object class="GtkScale" id="scale">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="draw-value">0</property>
@ -185,10 +189,11 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">spin</property>
</object>
</child>
<child>
<object class="GtkSpinButton">
<object class="GtkSpinButton" id="spin">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="adjustment">
@ -217,10 +222,11 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">dropdown</property>
</object>
</child>
<child>
<object class="GtkDropDown">
<object class="GtkDropDown" id="dropdown">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="model">
@ -252,10 +258,11 @@
<property name="halign">start</property>
<property name="valign">center</property>
<property name="hexpand">1</property>
<property name="mnemonic-widget">entry</property>
</object>
</child>
<child>
<object class="GtkEntry">
<object class="GtkEntry" id="entry">
<property name="halign">end</property>
<property name="valign">center</property>
<property name="placeholder-text">Type here…</property>

View File

@ -18,7 +18,6 @@
#include <string.h>
#include "config.h"
#include <gtk/gtk.h>
#include <glib/gstdio.h>
@ -268,9 +267,9 @@ activate_run (GSimpleAction *action,
}
static GtkWidget *
display_image (const char *format,
const char *resource,
char **label)
display_image (const char *format,
const char *resource,
GtkWidget *label)
{
GtkWidget *sw, *image;
@ -280,13 +279,17 @@ display_image (const char *format,
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), image);
gtk_accessible_update_relation (GTK_ACCESSIBLE (image),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
return sw;
}
static GtkWidget *
display_images (const char *format,
const char *resource_dir,
char **label)
display_images (const char *format,
const char *resource_dir,
GtkWidget *label)
{
char **resources;
GtkWidget *grid;
@ -325,15 +328,19 @@ display_images (const char *format,
g_strfreev (resources);
*label = g_strdup ("Images");
gtk_label_set_label (GTK_LABEL (label), "Images");
gtk_accessible_update_relation (GTK_ACCESSIBLE (grid),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
return sw;
}
static GtkWidget *
display_text (const char *format,
const char *resource,
char **label)
display_text (const char *format,
const char *resource,
GtkWidget *label)
{
GtkTextBuffer *buffer;
GtkWidget *textview, *sw;
@ -368,6 +375,10 @@ display_text (const char *format,
gtk_text_view_set_buffer (GTK_TEXT_VIEW (textview), buffer);
gtk_accessible_update_relation (GTK_ACCESSIBLE (textview),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
@ -378,15 +389,19 @@ display_text (const char *format,
}
static GtkWidget *
display_video (const char *format,
const char *resource,
char **label)
display_video (const char *format,
const char *resource,
GtkWidget *label)
{
GtkWidget *video;
video = gtk_video_new_for_resource (resource);
gtk_video_set_loop (GTK_VIDEO (video), TRUE);
gtk_accessible_update_relation (GTK_ACCESSIBLE (video),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
return video;
}
@ -408,9 +423,9 @@ display_nothing (const char *resource)
static struct {
const char *extension;
const char *format;
GtkWidget * (* display_func) (const char *format,
const char *resource,
char **label);
GtkWidget * (* display_func) (const char *format,
const char *resource,
GtkWidget *label);
} display_funcs[] = {
{ ".gif", NULL, display_image },
{ ".jpg", NULL, display_image },
@ -433,7 +448,6 @@ add_data_tab (const char *demoname)
char **resources;
GtkWidget *widget, *label;
guint i, j;
char *label_string;
resource_dir = g_strconcat ("/", demoname, NULL);
resources = g_resources_enumerate_children (resource_dir, 0, NULL);
@ -453,23 +467,21 @@ add_data_tab (const char *demoname)
break;
}
label_string = NULL;
label = gtk_label_new (resources[i]);
if (j < G_N_ELEMENTS (display_funcs))
widget = display_funcs[j].display_func (display_funcs[j].format,
resource_name,
&label_string);
label);
else
widget = display_nothing (resource_name);
label = gtk_label_new (label_string ? label_string : resources[i]);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), widget, label);
g_object_set (gtk_notebook_get_page (GTK_NOTEBOOK (notebook), widget),
"tab-expand", FALSE,
NULL);
g_free (resource_name);
g_free (label_string);
}
g_strfreev (resources);

View File

@ -60,10 +60,14 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchBar" id="searchbar">
<accessibility>
<relation name="labelled-by">search-entry</relation>
</accessibility>
<property name="key-capture-widget">window</property>
<child>
<object class="GtkSearchEntry" id="search-entry">
<accessibility>
<property name="label" translatable="yes">Search</property>
<relation name="controls">listview</relation>
</accessibility>
</object>

View File

@ -68,6 +68,9 @@ do_password_entry (GtkWidget *do_widget)
"placeholder-text", "Password",
"activates-default", TRUE,
NULL);
gtk_accessible_update_property (GTK_ACCESSIBLE (entry),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Password",
-1);
g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
gtk_box_append (GTK_BOX (box), entry);
@ -77,6 +80,9 @@ do_password_entry (GtkWidget *do_widget)
"placeholder-text", "Confirm",
"activates-default", TRUE,
NULL);
gtk_accessible_update_property (GTK_ACCESSIBLE (entry2),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Confirm",
-1);
g_signal_connect (entry2, "notify::text", G_CALLBACK (update_button), NULL);
gtk_box_append (GTK_BOX (box), entry2);

View File

@ -189,6 +189,7 @@ do_pickers (GtkWidget *do_widget)
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
picker = gtk_color_dialog_button_new (gtk_color_dialog_new ());
gtk_label_set_mnemonic_widget (GTK_LABEL (label), picker);
gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
label = gtk_label_new ("Font:");
@ -198,6 +199,7 @@ do_pickers (GtkWidget *do_widget)
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
picker = gtk_font_dialog_button_new (gtk_font_dialog_new ());
gtk_label_set_mnemonic_widget (GTK_LABEL (label), picker);
gtk_grid_attach (GTK_GRID (table), picker, 1, 1, 1, 1);
label = gtk_label_new ("File:");
@ -208,6 +210,9 @@ do_pickers (GtkWidget *do_widget)
picker = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
button = gtk_button_new_from_icon_name ("document-open-symbolic");
gtk_accessible_update_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Select File",
-1);
label = gtk_label_new ("None");
@ -223,6 +228,9 @@ do_pickers (GtkWidget *do_widget)
gtk_box_append (GTK_BOX (picker), button);
app_picker = gtk_button_new_from_icon_name ("emblem-system-symbolic");
gtk_widget_set_halign (app_picker, GTK_ALIGN_END);
gtk_accessible_update_property (GTK_ACCESSIBLE (app_picker),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Open File",
-1);
gtk_widget_set_sensitive (app_picker, FALSE);
g_signal_connect (app_picker, "clicked", G_CALLBACK (open_app), NULL);
gtk_box_append (GTK_BOX (picker), app_picker);