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,19 +10,25 @@ func augment_node(node):
func augment_tree(node):
augment_node(node)
for child in node.get_children():
augment_node(child)
augment_tree(child)
func set_initial_screen_focus(screen):
print("Screen ",screen)
var focus
var root = get_tree().root
augment_tree(root)
if screen == "3D":
focus = root.find_node("ToolButton", true, false)
if focus is Control:
print("Focus ",focus)
focus.grab_click_focus()
focus.grab_focus()
self.augment_tree(get_tree().root)
var focus = find_focusable_control(get_tree().root)
print("Focus ",focus, focus.is_in_group("accessible"))
if not focus:
return
focus.grab_click_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):
print("Set focus in scene")

View File

@ -6,18 +6,17 @@ func focused():
print("Focus entered.", self.node)
func unfocused():
print("Unfocused", self.node)
pass
func gui_input():
print("GUI input.")
func gui_input(event):
pass
func _init(node):
if node.is_in_group("accessible"):
return
node.add_to_group("accessible")
print(node.get_path())
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("mouse_entered", self, "focused")
self.node.connect("focus_exited", self, "unfocused")