gtk-demo: Miscellaneous a11y improvements

This commit is contained in:
Matthias Clasen 2023-06-18 12:59:51 -04:00
parent 60a170db88
commit 8d9a59f698
6 changed files with 48 additions and 8 deletions

View File

@ -4,6 +4,9 @@
<object class="GtkWindow" id="window">
<property name="resizable">1</property>
<property name="title">Clipboard</property>
<accessibility>
<relation name="described-by">label</relation>
</accessibility>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
@ -13,7 +16,7 @@
<property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="label">
<property name="label">“Copy” will copy the selected data the clipboard, “Paste” will show the current clipboard contents. You can also drag the data to the bottom.</property>
<property name="wrap">1</property>
<property name="max-width-chars">40</property>

View File

@ -387,6 +387,8 @@ demo3_widget_class_init (Demo3WidgetClass *class)
gtk_widget_class_set_template_from_resource (widget_class, "/menu/demo3widget.ui");
gtk_widget_class_bind_template_child (widget_class, Demo3Widget, menu);
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_IMG);
}
GtkWidget *

View File

@ -19,8 +19,14 @@
</item>
</menu>
<template class="Demo3Widget">
<accessibility>
<property name="label">Demo image</property>
</accessibility>
<child>
<object class="GtkPopoverMenu" id="menu">
<accessibility>
<property name="label">Context menu</property>
</accessibility>
<property name="has-arrow">0</property>
<property name="menu-model">model</property>
</object>

View File

@ -334,11 +334,17 @@ do_drawingarea (GtkWidget *do_widget)
gtk_widget_set_vexpand (frame, TRUE);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
da = g_object_new (GTK_TYPE_DRAWING_AREA,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
gtk_accessible_update_relation (GTK_ACCESSIBLE (da),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), groups_draw, NULL, NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
/*
* Create the scribble area
@ -352,11 +358,17 @@ do_drawingarea (GtkWidget *do_widget)
gtk_widget_set_vexpand (frame, TRUE);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
da = g_object_new (GTK_TYPE_DRAWING_AREA,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
gtk_accessible_update_relation (GTK_ACCESSIBLE (da),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), scribble_draw, NULL, NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
g_signal_connect (da, "resize",
G_CALLBACK (scribble_resize), NULL);
@ -372,7 +384,7 @@ do_drawingarea (GtkWidget *do_widget)
}
if (!gtk_widget_get_visible (window))
gtk_widget_set_visible (window, TRUE);
gtk_window_present (GTK_WINDOW (window));
else
gtk_window_destroy (GTK_WINDOW (window));

View File

@ -18,6 +18,7 @@ do_headerbar (GtkWidget *do_widget)
GtkWidget *header;
GtkWidget *button;
GtkWidget *box;
GtkWidget *content;
if (!window)
{
@ -37,16 +38,26 @@ do_headerbar (GtkWidget *do_widget)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_add_css_class (box, "linked");
button = gtk_button_new_from_icon_name ("go-previous-symbolic");
gtk_widget_set_tooltip_text (button, "Back");
gtk_box_append (GTK_BOX (box), button);
button = gtk_button_new_from_icon_name ("go-next-symbolic");
gtk_widget_set_tooltip_text (button, "Forward");
gtk_box_append (GTK_BOX (box), button);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), box);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), gtk_switch_new ());
button = gtk_switch_new ();
gtk_accessible_update_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Change something",
-1);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
gtk_window_set_child (GTK_WINDOW (window), gtk_text_view_new ());
content = gtk_text_view_new ();
gtk_accessible_update_property (GTK_ACCESSIBLE (content),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Content",
-1);
gtk_window_set_child (GTK_WINDOW (window), content);
}
if (!gtk_widget_get_visible (window))

View File

@ -164,12 +164,18 @@ do_image_scaling (GtkWidget *do_widget)
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, -10., 10., 0.1);
gtk_scale_add_mark (GTK_SCALE (scale), 0., GTK_POS_TOP, NULL);
gtk_widget_set_tooltip_text (scale, "Zoom");
gtk_accessible_update_property (GTK_ACCESSIBLE (scale),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Zoom",
-1);
gtk_range_set_value (GTK_RANGE (scale), 0.);
gtk_widget_set_hexpand (scale, TRUE);
gtk_box_append (GTK_BOX (box2), scale);
dropdown = gtk_drop_down_new (G_LIST_MODEL (gtk_string_list_new ((const char *[]){ "Linear", "Nearest", "Trilinear", NULL })), NULL);
gtk_widget_set_tooltip_text (dropdown, "Filter");
gtk_accessible_update_property (GTK_ACCESSIBLE (dropdown),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Filter",
-1);
gtk_box_append (GTK_BOX (box2), dropdown);
g_object_bind_property (dropdown, "selected", widget, "filter", G_BINDING_DEFAULT);