mirror of
https://github.com/lightsoutgames/godot-accessibility.git
synced 2024-11-22 11:55:56 +00:00
Add _Menu_ as keyboard shortcut to perform right-click. Also, clean up PopupMenu
presentation to speak shortcut names.
This commit is contained in:
parent
d42d913f29
commit
11a8dc7aa2
|
@ -20,12 +20,14 @@ func singular_or_plural(count, singular, plural):
|
||||||
else:
|
else:
|
||||||
return plural
|
return plural
|
||||||
|
|
||||||
func left_click(item := node):
|
func click(item := node, button_index = BUTTON_LEFT):
|
||||||
var click = InputEventMouseButton.new()
|
var click = InputEventMouseButton.new()
|
||||||
click.button_index = BUTTON_LEFT
|
click.button_index = button_index
|
||||||
click.pressed = true
|
click.pressed = true
|
||||||
if item is Node:
|
if item is Node:
|
||||||
click.position = item.rect_global_position
|
click.position = item.rect_global_position
|
||||||
|
else:
|
||||||
|
click.position = node.get_tree().root.get_mouse_position()
|
||||||
node.get_tree().input_event(click)
|
node.get_tree().input_event(click)
|
||||||
click.pressed = false
|
click.pressed = false
|
||||||
node.get_tree().input_event(click)
|
node.get_tree().input_event(click)
|
||||||
|
@ -160,20 +162,31 @@ 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):
|
||||||
print("id: %s" % id)
|
var index = node.get_item_index(id)
|
||||||
print("count: %s" % node.get_item_count())
|
print("id: %s, index: %s" % [id, index])
|
||||||
var item = node.get_item_text(id)
|
if index == -1:
|
||||||
var submenu = node.get_item_submenu(id)
|
index = id
|
||||||
var tooltip = node.get_item_tooltip(position_in_children)
|
var item = node.get_item_text(index)
|
||||||
var disabled = node.is_item_disabled(id)
|
var submenu = node.get_item_submenu(index)
|
||||||
|
if submenu and not item:
|
||||||
|
item = submenu
|
||||||
|
var tooltip = node.get_item_tooltip(index)
|
||||||
|
var disabled = node.is_item_disabled(index)
|
||||||
if item and tooltip:
|
if item and tooltip:
|
||||||
item += ": "
|
item += ": "
|
||||||
item += tooltip
|
item += tooltip
|
||||||
elif tooltip:
|
elif tooltip:
|
||||||
item = tooltip
|
item = tooltip
|
||||||
var shortcut = node.get_item_shortcut(position_in_children)
|
var shortcut = node.get_item_shortcut(index)
|
||||||
if shortcut != null and shortcut.get_as_text() != "None":
|
if shortcut:
|
||||||
item += ": "+shortcut.get_as_text()
|
var name = shortcut.resource_name
|
||||||
|
var text = shortcut.get_as_text()
|
||||||
|
if name and text != "None":
|
||||||
|
item += name + ": " +text
|
||||||
|
elif name:
|
||||||
|
item = name
|
||||||
|
elif text:
|
||||||
|
item = text
|
||||||
if item == "":
|
if item == "":
|
||||||
item = "Unlabelled"
|
item = "Unlabelled"
|
||||||
if submenu:
|
if submenu:
|
||||||
|
@ -246,6 +259,14 @@ func tree_input(event):
|
||||||
if item.is_selected(i):
|
if item.is_selected(i):
|
||||||
column = i
|
column = i
|
||||||
break
|
break
|
||||||
|
if item and event is InputEventKey and event.pressed and not event.echo:
|
||||||
|
var area
|
||||||
|
if column:
|
||||||
|
area = node.get_item_area_rect(item, column)
|
||||||
|
else:
|
||||||
|
area = node.get_item_area_rect(item)
|
||||||
|
var position = Vector2(node.rect_global_position.x + area.position.x, node.rect_global_position.y + area.position.y)
|
||||||
|
node.get_tree().root.warp_mouse(position)
|
||||||
if item and column and button_index != null:
|
if item and column and button_index != null:
|
||||||
if event.is_action_pressed("ui_accept"):
|
if event.is_action_pressed("ui_accept"):
|
||||||
node.accept_event()
|
node.accept_event()
|
||||||
|
@ -309,6 +330,7 @@ func tab_container_input(event):
|
||||||
|
|
||||||
func focused():
|
func focused():
|
||||||
print("Focus: %s" % node)
|
print("Focus: %s" % node)
|
||||||
|
node.get_tree().root.warp_mouse(node.rect_global_position)
|
||||||
tts.stop()
|
tts.stop()
|
||||||
var label = guess_label()
|
var label = guess_label()
|
||||||
if label:
|
if label:
|
||||||
|
@ -346,7 +368,14 @@ func unfocused():
|
||||||
print("Unfocused")
|
print("Unfocused")
|
||||||
position_in_children = 0
|
position_in_children = 0
|
||||||
|
|
||||||
|
func click_focused():
|
||||||
|
if node.has_focus():
|
||||||
|
return
|
||||||
|
node.grab_focus()
|
||||||
|
|
||||||
func gui_input(event):
|
func gui_input(event):
|
||||||
|
if event is InputEventKey and event.pressed and not event.echo and event.scancode == KEY_MENU:
|
||||||
|
return click(null, BUTTON_RIGHT)
|
||||||
if node is TabContainer:
|
if node is TabContainer:
|
||||||
return tab_container_input(event)
|
return tab_container_input(event)
|
||||||
elif node is ItemList:
|
elif node is ItemList:
|
||||||
|
@ -395,7 +424,7 @@ func editor_inspector_section_focus():
|
||||||
|
|
||||||
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"):
|
||||||
left_click()
|
click()
|
||||||
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()
|
||||||
if expanded:
|
if expanded:
|
||||||
|
@ -412,7 +441,7 @@ func _init(tts, node):
|
||||||
if is_focusable(node):
|
if is_focusable(node):
|
||||||
node.set_focus_mode(Control.FOCUS_ALL)
|
node.set_focus_mode(Control.FOCUS_ALL)
|
||||||
node.connect("focus_entered", self, "focused")
|
node.connect("focus_entered", self, "focused")
|
||||||
node.connect("mouse_entered", self, "focused")
|
node.connect("mouse_entered", self, "click_focused")
|
||||||
node.connect("focus_exited", self, "unfocused")
|
node.connect("focus_exited", self, "unfocused")
|
||||||
node.connect("mouse_exited", self, "unfocused")
|
node.connect("mouse_exited", self, "unfocused")
|
||||||
node.connect("gui_input", self, "gui_input")
|
node.connect("gui_input", self, "gui_input")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user