Move all accessibility code into Accessible class. Also, add tree-augmenting function to make an entire tree accessible.

This commit is contained in:
Nolan Darilek 2018-06-07 21:28:33 +00:00
parent 319c1297c4
commit 2f1ad85f1d
2 changed files with 10 additions and 4 deletions

View File

@ -5,13 +5,18 @@ var Accessible = preload("accessible.gd")
func augment_node(node): func augment_node(node):
if node is Control: if node is Control:
node.set_focus_mode(Control.FOCUS_ALL)
Accessible.new(node) Accessible.new(node)
func augment_tree(node):
augment_node(node)
for child in node.get_children():
augment_node(child)
func set_initial_screen_focus(screen): func set_initial_screen_focus(screen):
print("Screen ",screen) print("Screen ",screen)
var focus var focus
var root = get_tree().root var root = get_tree().root
augment_tree(root)
if screen == "3D": if screen == "3D":
focus = root.find_node("ToolButton", true, false) focus = root.find_node("ToolButton", true, false)
print("Focus ",focus) print("Focus ",focus)

View File

@ -3,10 +3,10 @@ extends Object
var node var node
func focused(): func focused():
print("Focus entered.") print("Focus entered.", self.node)
func unfocused(): func unfocused():
print("Unfocused") print("Unfocused", self.node)
func gui_input(): func gui_input():
print("GUI input.") print("GUI input.")
@ -15,8 +15,9 @@ func _init(node):
if node.is_in_group("accessible"): if node.is_in_group("accessible"):
return return
node.add_to_group("accessible") node.add_to_group("accessible")
# print(node.get_path()) print(node.get_path())
self.node = node self.node = node
self.node.set_focus_mode(Control.FOCUS_ALL)
self.node.connect("focus_entered", self, "focused") self.node.connect("focus_entered", self, "focused")
self.node.connect("mouse_entered", self, "focused") self.node.connect("mouse_entered", self, "focused")
self.node.connect("focus_exited", self, "unfocused") self.node.connect("focus_exited", self, "unfocused")