-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy patha11y.v
More file actions
124 lines (115 loc) · 3.16 KB
/
Copy patha11y.v
File metadata and controls
124 lines (115 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module gui
// A11yCfg is embedded in widget Cfg structs to provide
// accessible label and description. V promotes the fields,
// so call sites are unchanged.
pub struct A11yCfg {
pub:
a11y_label string // override label for screen readers
a11y_description string // extended help text
}
// AccessRole identifies a shape's semantic role for assistive
// technology. Maps 1:1 to NSAccessibilityRole on macOS.
// Windows UIA control types are the intended future mapping;
// the current Windows backend does not expose UIA yet. Zero
// value .none means the shape is invisible to the accessibility tree.
pub enum AccessRole as u8 {
none
button
checkbox
color_well
combo_box
date_field
dialog
disclosure
grid
grid_cell
group
heading
image
link
list
list_item
menu
menu_bar
menu_item
progress_bar
radio_button
radio_group
scroll_area
scroll_bar
slider
splitter
static_text
switch_toggle
tab
tab_item
text_field
text_area
toolbar
tree
tree_item
}
// AccessState is a bitmask of dynamic accessibility states.
// Follows the Modifier pattern from event.v. Uses u16 to
// save space; disabled is excluded because Shape.disabled
// already exists.
pub enum AccessState as u16 {
none = 0
expanded = 1 // disclosure/expand_panel open
selected = 2 // tab, list item, menu item
checked = 4 // toggle, checkbox
required = 8 // form validation
invalid = 16 // form validation error
busy = 32 // async loading / progress
read_only = 64 // non-editable text field
modal = 128 // dialog
live = 256 // value changes announced to screen reader
}
// has checks if the state bitmask contains the given flag.
pub fn (s AccessState) has(flag AccessState) bool {
return u16(s) & u16(flag) > 0 || s == flag
}
// AccessInfo holds string and numeric accessibility data.
// Heap-allocated, nil on Shape when unused. Same lazy-alloc
// pattern as EventHandlers / ShapeTextConfig / ShapeEffects.
@[heap]
pub struct AccessInfo {
pub mut:
label string // primary screen-reader label
description string // extended help text
value_text string // current value as text (live buffer)
value_num f32 // numeric value (slider, progress)
value_min f32 // range minimum
value_max f32 // range maximum
heading_level u8 // 1-6 for headings, 0 otherwise
}
// has_a11y returns true if the shape has allocated AccessInfo.
@[inline]
pub fn (shape &Shape) has_a11y() bool {
return shape.a11y != unsafe { nil }
}
// make_a11y_info creates an AccessInfo with label and
// description, returning nil when both are empty.
fn make_a11y_info(label string, description string) &AccessInfo {
if label.len > 0 || description.len > 0 {
return &AccessInfo{
label: label
description: description
}
}
return unsafe { nil }
}
// LiveNode captures V strings from shapes with .live state
// during a11y_collect, avoiding cstring_to_vstring round-trips.
struct LiveNode {
label string
value_text string
}
// a11y_label returns the effective label: explicit a11y_label
// if set, otherwise the fallback.
fn a11y_label(a11y_label string, fallback string) string {
if a11y_label.len > 0 {
return a11y_label
}
return fallback
}