Initial focus is set, and focus changes are reported.

This commit is contained in:
Nolan Darilek 2018-06-10 19:42:58 +00:00
parent c81d3fc4a4
commit df410e5802
2 changed files with 21 additions and 16 deletions

View File

@ -10,20 +10,26 @@ func augment_node(node):
func augment_tree(node): func augment_tree(node):
augment_node(node) augment_node(node)
for child in node.get_children(): for child in node.get_children():
augment_node(child) augment_tree(child)
func set_initial_screen_focus(screen): func set_initial_screen_focus(screen):
print("Screen ",screen) self.augment_tree(get_tree().root)
var focus var focus = find_focusable_control(get_tree().root)
var root = get_tree().root print("Focus ",focus, focus.is_in_group("accessible"))
augment_tree(root) if not focus:
if screen == "3D": return
focus = root.find_node("ToolButton", true, false)
if focus is Control:
print("Focus ",focus)
focus.grab_click_focus() focus.grab_click_focus()
focus.grab_focus() focus.grab_focus()
func find_focusable_control(node):
if node is Control and node.is_visible_in_tree() and (node.focus_mode == Control.FOCUS_CLICK or node.focus_mode == Control.FOCUS_ALL):
return node
for child in node.get_children():
var result = find_focusable_control(child)
if result:
return result
return null
func set_initial_scene_focus(scene): func set_initial_scene_focus(scene):
print("Set focus in scene") print("Set focus in scene")

View File

@ -6,18 +6,17 @@ func focused():
print("Focus entered.", self.node) print("Focus entered.", self.node)
func unfocused(): func unfocused():
print("Unfocused", self.node) pass
func gui_input(): func gui_input(event):
print("GUI input.") pass
func _init(node): 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())
self.node = node self.node = node
self.node.set_focus_mode(Control.FOCUS_ALL) # 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")