mirror of
https://github.com/lightsoutgames/godot-accessibility.git
synced 2024-11-22 11:55:56 +00:00
Add global signal-catching for better handling of cases where focus is lost.
This commit is contained in:
parent
0e8b6ae9e8
commit
0783dfb548
|
@ -171,9 +171,6 @@ func menu_button_focus():
|
||||||
tokens.append("menu")
|
tokens.append("menu")
|
||||||
TTS.speak(tokens.join(": "), false)
|
TTS.speak(tokens.join(": "), false)
|
||||||
|
|
||||||
func panel_focus():
|
|
||||||
TTS.speak("panel", true)
|
|
||||||
|
|
||||||
func popup_menu_focus():
|
func popup_menu_focus():
|
||||||
TTS.speak("menu", false)
|
TTS.speak("menu", false)
|
||||||
|
|
||||||
|
@ -384,8 +381,6 @@ func focus():
|
||||||
label_focus()
|
label_focus()
|
||||||
elif node is LineEdit:
|
elif node is LineEdit:
|
||||||
line_edit_focus()
|
line_edit_focus()
|
||||||
elif node is Panel:
|
|
||||||
panel_focus()
|
|
||||||
elif node is PopupMenu:
|
elif node is PopupMenu:
|
||||||
popup_menu_focus()
|
popup_menu_focus()
|
||||||
elif node is TabContainer:
|
elif node is TabContainer:
|
||||||
|
@ -411,8 +406,9 @@ func unfocus():
|
||||||
func click_focus():
|
func click_focus():
|
||||||
if node.has_focus():
|
if node.has_focus():
|
||||||
return
|
return
|
||||||
print("Grabbing focus: %s" % node)
|
if node.focus_mode == Control.FOCUS_ALL:
|
||||||
node.grab_focus()
|
print("Grabbing focus: %s" % node)
|
||||||
|
node.grab_focus()
|
||||||
|
|
||||||
func gui_input(event):
|
func gui_input(event):
|
||||||
if event is InputEventKey and Input.is_action_just_pressed("ui_accept") and event.control and event.alt:
|
if event is InputEventKey and Input.is_action_just_pressed("ui_accept") and event.control and event.alt:
|
||||||
|
@ -464,6 +460,8 @@ func is_focusable(node):
|
||||||
return false
|
return false
|
||||||
if node.get_class() == "CollisionShape2DEditor":
|
if node.get_class() == "CollisionShape2DEditor":
|
||||||
return false
|
return false
|
||||||
|
if node is Panel:
|
||||||
|
return false
|
||||||
if node is TabContainer:
|
if node is TabContainer:
|
||||||
return true
|
return true
|
||||||
if node.get_class() == "EditorInspectorSection":
|
if node.get_class() == "EditorInspectorSection":
|
||||||
|
|
|
@ -3,9 +3,34 @@ extends Node
|
||||||
|
|
||||||
var Accessible = preload("Accessible.gd")
|
var Accessible = preload("Accessible.gd")
|
||||||
|
|
||||||
|
var focus_restore_timer = Timer.new()
|
||||||
|
|
||||||
|
func focused(node):
|
||||||
|
focus_restore_timer.stop()
|
||||||
|
|
||||||
|
func click_focused(node):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func restore_focus():
|
||||||
|
var focus = find_focusable_control(get_tree().root)
|
||||||
|
if focus:
|
||||||
|
focus.grab_focus()
|
||||||
|
focus.grab_click_focus()
|
||||||
|
|
||||||
|
func unfocused(node):
|
||||||
|
focus_restore_timer.start(0.2)
|
||||||
|
|
||||||
func augment_node(node):
|
func augment_node(node):
|
||||||
if node is Control:
|
if node is Control:
|
||||||
Accessible.new(node)
|
Accessible.new(node)
|
||||||
|
if not node.is_connected("focus_entered", self, "focused"):
|
||||||
|
node.connect("focus_entered", self, "focused", [node])
|
||||||
|
if not node.is_connected("mouse_entered", self, "click_focused"):
|
||||||
|
node.connect("mouse_entered", self, "click_focused", [node])
|
||||||
|
if not node.is_connected("focus_exited", self, "unfocused"):
|
||||||
|
node.connect("focus_exited", self, "unfocused", [node])
|
||||||
|
if not node.is_connected("mouse_exited", self, "unfocused"):
|
||||||
|
node.connect("mouse_exited", self, "unfocused", [node])
|
||||||
|
|
||||||
func augment_tree(node):
|
func augment_tree(node):
|
||||||
augment_node(node)
|
augment_node(node)
|
||||||
|
@ -34,7 +59,6 @@ func find_focusable_control(node):
|
||||||
return null
|
return null
|
||||||
|
|
||||||
func set_initial_scene_focus(scene):
|
func set_initial_scene_focus(scene):
|
||||||
print("Set focus in scene")
|
|
||||||
self.augment_tree(get_tree().root)
|
self.augment_tree(get_tree().root)
|
||||||
var focus = find_focusable_control(get_tree().root)
|
var focus = find_focusable_control(get_tree().root)
|
||||||
if not focus:
|
if not focus:
|
||||||
|
@ -43,5 +67,8 @@ func set_initial_scene_focus(scene):
|
||||||
focus.grab_focus()
|
focus.grab_focus()
|
||||||
|
|
||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
|
focus_restore_timer.one_shot = true
|
||||||
|
focus_restore_timer.connect("timeout", self, "restore_focus")
|
||||||
|
add_child(focus_restore_timer)
|
||||||
TTS.rate = 255
|
TTS.rate = 255
|
||||||
get_tree().connect("node_added", self, "augment_tree")
|
get_tree().connect("node_added", self, "augment_tree")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user