mirror of
https://github.com/lightsoutgames/godot-accessibility.git
synced 2024-11-22 11:55:56 +00:00
Clean up node presentation.
* Concatenate tokens then join them, rather than building up strings token by token and conditionally presenting them. * Present `hint_tooltip` in lieu of text in some cases, and don't present it again afterwards.
This commit is contained in:
parent
11a8dc7aa2
commit
d481e74261
125
accessible.gd
125
accessible.gd
|
@ -53,13 +53,13 @@ func accept_dialog_focus():
|
||||||
node.add_child(dialog_close_timer)
|
node.add_child(dialog_close_timer)
|
||||||
|
|
||||||
func checkbox_focus():
|
func checkbox_focus():
|
||||||
var text
|
var tokens = PoolStringArray([])
|
||||||
if node.pressed:
|
if node.pressed:
|
||||||
text = "checked"
|
tokens.append("checked")
|
||||||
else:
|
else:
|
||||||
text = "unchecked"
|
tokens.append("unchecked")
|
||||||
text += " checkbox"
|
tokens.append(" checkbox")
|
||||||
tts.speak(text, false)
|
tts.speak(tokens.join(" "), false)
|
||||||
|
|
||||||
func checkbox_toggled(checked):
|
func checkbox_toggled(checked):
|
||||||
if checked:
|
if checked:
|
||||||
|
@ -67,14 +67,17 @@ func checkbox_toggled(checked):
|
||||||
else:
|
else:
|
||||||
tts.speak("unchecked", true)
|
tts.speak("unchecked", true)
|
||||||
|
|
||||||
|
var spoke_hint_tooltip
|
||||||
|
|
||||||
func button_focus():
|
func button_focus():
|
||||||
var text
|
var tokens = PoolStringArray([])
|
||||||
if node.text:
|
if node.text:
|
||||||
text = node.text
|
tokens.append(node.text)
|
||||||
if text:
|
elif node.hint_tooltip:
|
||||||
tts.speak("%s: button" % text, false)
|
spoke_hint_tooltip = true
|
||||||
else:
|
tokens.append(node.hint_tooltip)
|
||||||
tts.speak("button", false)
|
tokens.append("button")
|
||||||
|
tts.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
func texturebutton_focus():
|
func texturebutton_focus():
|
||||||
tts.speak("button", false)
|
tts.speak("button", false)
|
||||||
|
@ -86,13 +89,13 @@ func item_list_focus():
|
||||||
tts.speak(selected, false)
|
tts.speak(selected, false)
|
||||||
|
|
||||||
func item_list_item_selected(index):
|
func item_list_item_selected(index):
|
||||||
tts.speak("Selected", false)
|
tts.speak("Selected", true)
|
||||||
|
|
||||||
func item_list_multi_selected(index, selected):
|
func item_list_multi_selected(index, selected):
|
||||||
tts.speak("Multiselect", false)
|
tts.speak("Multiselect", false)
|
||||||
|
|
||||||
func item_list_nothing_selected():
|
func item_list_nothing_selected():
|
||||||
tts.speak("Nothing selected", false)
|
tts.speak("Nothing selected", true)
|
||||||
|
|
||||||
func item_list_input(event):
|
func item_list_input(event):
|
||||||
var old_pos = position_in_children
|
var old_pos = position_in_children
|
||||||
|
@ -156,60 +159,62 @@ func check_caret_moved():
|
||||||
old_pos = pos
|
old_pos = pos
|
||||||
|
|
||||||
func menu_button_focus():
|
func menu_button_focus():
|
||||||
tts.speak(node.text + ": menu", false)
|
var tokens = PoolStringArray([])
|
||||||
|
if node.text:
|
||||||
|
tokens.append(node.text)
|
||||||
|
if node.hint_tooltip:
|
||||||
|
tokens.append(node.hint_tooltip)
|
||||||
|
spoke_hint_tooltip = true
|
||||||
|
tokens.append("menu")
|
||||||
|
tts.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
func popup_menu_focus():
|
func popup_menu_focus():
|
||||||
tts.speak("menu", false)
|
tts.speak("menu", false)
|
||||||
|
|
||||||
func popup_menu_item_id_focus(id):
|
func popup_menu_item_id_focus(id):
|
||||||
|
var tokens = PoolStringArray([])
|
||||||
var index = node.get_item_index(id)
|
var index = node.get_item_index(id)
|
||||||
print("id: %s, index: %s" % [id, index])
|
print("id: %s, index: %s" % [id, index])
|
||||||
if index == -1:
|
if index == -1:
|
||||||
index = id
|
index = id
|
||||||
var item = node.get_item_text(index)
|
var item = node.get_item_text(index)
|
||||||
|
if item:
|
||||||
|
tokens.append(item)
|
||||||
var submenu = node.get_item_submenu(index)
|
var submenu = node.get_item_submenu(index)
|
||||||
if submenu and not item:
|
if submenu:
|
||||||
item = submenu
|
tokens.append(submenu)
|
||||||
|
tokens.append("menu")
|
||||||
var tooltip = node.get_item_tooltip(index)
|
var tooltip = node.get_item_tooltip(index)
|
||||||
|
if tooltip:
|
||||||
|
tokens.append(tooltip)
|
||||||
var disabled = node.is_item_disabled(index)
|
var disabled = node.is_item_disabled(index)
|
||||||
if item and tooltip:
|
if disabled:
|
||||||
item += ": "
|
tokens.append("disabled")
|
||||||
item += tooltip
|
|
||||||
elif tooltip:
|
|
||||||
item = tooltip
|
|
||||||
var shortcut = node.get_item_shortcut(index)
|
var shortcut = node.get_item_shortcut(index)
|
||||||
if shortcut:
|
if shortcut:
|
||||||
var name = shortcut.resource_name
|
var name = shortcut.resource_name
|
||||||
|
if name:
|
||||||
|
tokens.append(name)
|
||||||
var text = shortcut.get_as_text()
|
var text = shortcut.get_as_text()
|
||||||
if name and text != "None":
|
if text != "None":
|
||||||
item += name + ": " +text
|
tokens.append(text)
|
||||||
elif name:
|
tokens.append(str(id + 1) + " of " + str(node.get_item_count()))
|
||||||
item = name
|
tts.speak(tokens.join(": "), true)
|
||||||
elif text:
|
|
||||||
item = text
|
|
||||||
if item == "":
|
|
||||||
item = "Unlabelled"
|
|
||||||
if submenu:
|
|
||||||
item += ": menu"
|
|
||||||
if disabled:
|
|
||||||
item += ": disabled"
|
|
||||||
item += ": " + str(id + 1) + " of " + str(node.get_item_count())
|
|
||||||
tts.speak(item, true)
|
|
||||||
|
|
||||||
func tree_item_render():
|
func tree_item_render():
|
||||||
var focused_tree_item = node.get_selected()
|
var focused_tree_item = node.get_selected()
|
||||||
var result = ""
|
var tokens = PoolStringArray([])
|
||||||
for i in range(node.columns):
|
for i in range(node.columns):
|
||||||
result += focused_tree_item.get_text(i) + ": "
|
tokens.append(focused_tree_item.get_text(i))
|
||||||
if focused_tree_item.get_children():
|
if focused_tree_item.get_children():
|
||||||
if focused_tree_item.collapsed:
|
if focused_tree_item.collapsed:
|
||||||
result += "collapsed "
|
tokens.append("collapsed")
|
||||||
else:
|
else:
|
||||||
result += "expanded "
|
tokens.append("expanded")
|
||||||
result += "tree item"
|
tokens.append("tree item")
|
||||||
if focused_tree_item.is_selected(0):
|
if focused_tree_item.is_selected(0):
|
||||||
result += ": selected"
|
tokens.append("selected")
|
||||||
tts.speak(result, true)
|
tts.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
var prev_selected_cell
|
var prev_selected_cell
|
||||||
|
|
||||||
|
@ -222,28 +227,26 @@ func tree_item_selected():
|
||||||
tree_item_render()
|
tree_item_render()
|
||||||
prev_selected_cell = cell
|
prev_selected_cell = cell
|
||||||
else:
|
else:
|
||||||
var text = ""
|
var tokens = PoolStringArray([])
|
||||||
for i in range(node.columns):
|
for i in range(node.columns):
|
||||||
if cell.is_selected(i):
|
if cell.is_selected(i):
|
||||||
var title = node.get_column_title(i)
|
var title = node.get_column_title(i)
|
||||||
if title:
|
if title:
|
||||||
text += title + ": "
|
tokens.append(title)
|
||||||
var column_text = cell.get_text(i)
|
var column_text = cell.get_text(i)
|
||||||
if column_text:
|
if column_text:
|
||||||
text += column_text + ", "
|
tokens.append(column_text)
|
||||||
var button_count = cell.get_button_count(i)
|
var button_count = cell.get_button_count(i)
|
||||||
if button_count != 0:
|
if button_count != 0:
|
||||||
button_index = 0
|
button_index = 0
|
||||||
text += str(button_count) + " " + singular_or_plural(button_count, "button", "buttons") + ", "
|
tokens.append(str(button_count) + " " + singular_or_plural(button_count, "button", "buttons"))
|
||||||
var button_tooltip = cell.get_button_tooltip(i, button_index)
|
var button_tooltip = cell.get_button_tooltip(i, button_index)
|
||||||
if button_tooltip:
|
if button_tooltip:
|
||||||
text += button_tooltip + ": button, "
|
tokens.append(button_tooltip)
|
||||||
|
tokens.append("button")
|
||||||
if button_count > 1:
|
if button_count > 1:
|
||||||
text += "Use Home and End to switch focus, "
|
tokens.append("Use Home and End to switch focus.")
|
||||||
if text != "":
|
tts.speak(tokens.join(": "), true)
|
||||||
tts.speak(text, true)
|
|
||||||
else:
|
|
||||||
tts.speak("blank", true)
|
|
||||||
|
|
||||||
func tree_item_multi_select(item, column, selected):
|
func tree_item_multi_select(item, column, selected):
|
||||||
if selected:
|
if selected:
|
||||||
|
@ -284,12 +287,12 @@ func tree_input(event):
|
||||||
new_button_index = item.get_button_count(column) - 1
|
new_button_index = item.get_button_count(column) - 1
|
||||||
if new_button_index != button_index:
|
if new_button_index != button_index:
|
||||||
button_index = new_button_index
|
button_index = new_button_index
|
||||||
|
var tokens = PoolStringArray([])
|
||||||
var tooltip = item.get_button_tooltip(column, button_index)
|
var tooltip = item.get_button_tooltip(column, button_index)
|
||||||
var text = ""
|
|
||||||
if tooltip:
|
if tooltip:
|
||||||
text += tooltip + ": "
|
tokens.append(tooltip)
|
||||||
text += "button"
|
tokens.append("button")
|
||||||
tts.speak(text, true)
|
tts.speak(tokens.join(": "), true)
|
||||||
|
|
||||||
func tree_focus():
|
func tree_focus():
|
||||||
if node.get_selected():
|
if node.get_selected():
|
||||||
|
@ -361,8 +364,9 @@ func focused():
|
||||||
tree_focus()
|
tree_focus()
|
||||||
else:
|
else:
|
||||||
print("No handler")
|
print("No handler")
|
||||||
if node.hint_tooltip:
|
if node.hint_tooltip and not spoke_hint_tooltip:
|
||||||
tts.speak(node.hint_tooltip, false)
|
tts.speak(node.hint_tooltip, false)
|
||||||
|
spoke_hint_tooltip = false
|
||||||
|
|
||||||
func unfocused():
|
func unfocused():
|
||||||
print("Unfocused")
|
print("Unfocused")
|
||||||
|
@ -416,11 +420,12 @@ func is_focusable(node):
|
||||||
func editor_inspector_section_focus():
|
func editor_inspector_section_focus():
|
||||||
var child = node.get_children()[0]
|
var child = node.get_children()[0]
|
||||||
var expanded = child.is_visible_in_tree()
|
var expanded = child.is_visible_in_tree()
|
||||||
tts.speak("editor inspector section:", true)
|
var tokens = PoolStringArray(["editor inspector section"])
|
||||||
if expanded:
|
if expanded:
|
||||||
tts.speak("expanded", false)
|
tokens.append("expanded")
|
||||||
else:
|
else:
|
||||||
tts.speak("collapsed", false)
|
tokens.append("collapsed")
|
||||||
|
tts.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
func editor_inspector_section_input(event):
|
func editor_inspector_section_input(event):
|
||||||
if event.is_action_pressed("ui_accept"):
|
if event.is_action_pressed("ui_accept"):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user