forked from vlang/vglyph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_accessibility.v
More file actions
43 lines (37 loc) · 1.15 KB
/
Copy pathlayout_accessibility.v
File metadata and controls
43 lines (37 loc) · 1.15 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
module vglyph
import gg
import accessibility
// update_accessibility takes a Layout and converts it into accessibility nodes,
// essentially "publishing" the visual structure to the screen reader.
// This accumulates nodes for the current frame. Call am.commit() to push changes.
pub fn update_accessibility(mut am accessibility.AccessibilityManager, l Layout, origin_x f32,
origin_y f32) {
// Process Lines
for line in l.lines {
// Only create nodes for lines that have content
if line.length == 0 {
continue
}
line_text := extract_text(l, line.start_index, line.length)
rect := gg.Rect{
x: origin_x + line.rect.x
y: origin_y + line.rect.y
width: line.rect.width
height: line.rect.height
}
am.add_text_node(line_text, rect)
}
}
// extract_text returns the substring of the layout's original text
// for the byte range [start, start+length). Uses the stored text
// rather than per-item run_text which is only set in debug builds.
fn extract_text(l Layout, start int, length int) string {
if start < 0 || length <= 0 {
return ''
}
end := start + length
if end > l.text.len {
return ''
}
return l.text[start..end]
}