Return to having Accessible be a Node under ScreenReader, and having _exit_tree free resources.

This eliminates the need to track and iterate through a separate array of `Accessible`s in `ScreenReader`.

The previous performance issues are resolved by ensuring that any nodes processed aren't children of the `ScreenReader` node. I don't know of another way to avoid triggering signals on a child node than checking ancestry and failing fast.
This commit is contained in:
Nolan Darilek 2019-12-26 18:25:26 -06:00
parent 24483e4453
commit d9c740abd6
2 changed files with 8 additions and 12 deletions

View File

@ -499,7 +499,6 @@ func unfocused():
if not node.get_focus_owner(): if not node.get_focus_owner():
node.get_tree().root.warp_mouse(node.rect_global_position) node.get_tree().root.warp_mouse(node.rect_global_position)
timer.unreference() timer.unreference()
timer = null
func click_focused(): func click_focused():
if node.has_focus(): if node.has_focus():
@ -626,4 +625,8 @@ func _init(node):
node.connect("cell_selected", self, "tree_item_selected") node.connect("cell_selected", self, "tree_item_selected")
else: else:
node.connect("item_selected", self, "tree_item_selected") node.connect("item_selected", self, "tree_item_selected")
node.connect("tree_exiting", self, "free", [], Object.CONNECT_DEFERRED) node.connect("tree_exiting", self, "queue_free", [], Object.CONNECT_DEFERRED)
func _exit_tree():
if timer != null:
timer.unreference()

View File

@ -3,8 +3,6 @@ extends Node
var Accessible = preload("Accessible.gd") var Accessible = preload("Accessible.gd")
var accessibles = []
var focus_restore_timer = Timer.new() var focus_restore_timer = Timer.new()
func focused(node): func focused(node):
@ -26,7 +24,7 @@ func unfocused(node):
func augment_node(node): func augment_node(node):
if node is Control: if node is Control:
var accessible = Accessible.new(node) var accessible = Accessible.new(node)
accessibles.append(accessible) add_child(accessible)
if not node.is_connected("focus_entered", self, "focused"): if not node.is_connected("focus_entered", self, "focused"):
node.connect("focus_entered", self, "focused", [node]) node.connect("focus_entered", self, "focused", [node])
if not node.is_connected("mouse_entered", self, "click_focused"): if not node.is_connected("mouse_entered", self, "click_focused"):
@ -37,6 +35,8 @@ func augment_node(node):
node.connect("mouse_exited", self, "unfocused", [node]) node.connect("mouse_exited", self, "unfocused", [node])
func augment_tree(node): func augment_tree(node):
if node is Accessible:
return
augment_node(node) augment_node(node)
for child in node.get_children(): for child in node.get_children():
augment_tree(child) augment_tree(child)
@ -75,10 +75,3 @@ func _enter_tree():
focus_restore_timer.connect("timeout", self, "restore_focus") focus_restore_timer.connect("timeout", self, "restore_focus")
add_child(focus_restore_timer) add_child(focus_restore_timer)
get_tree().connect("node_added", self, "augment_tree") get_tree().connect("node_added", self, "augment_tree")
func _exit_tree():
for accessible in accessibles:
if accessible.timer != null:
accessible.timer.unreference()
accessible.timer = null
accessible.free()