2018-05-28 16:48:02 +00:00
|
|
|
extends Object
|
|
|
|
|
|
|
|
var node
|
|
|
|
|
2018-06-10 21:14:43 +00:00
|
|
|
func item_or_items(count):
|
|
|
|
if count == 1:
|
|
|
|
return "item"
|
|
|
|
else:
|
|
|
|
return "items"
|
|
|
|
|
2018-06-10 20:32:27 +00:00
|
|
|
func present_button():
|
|
|
|
var text = "Unlabelled"
|
|
|
|
if node.text:
|
|
|
|
text = node.text
|
|
|
|
print("%s: button" % text)
|
|
|
|
|
2018-06-10 21:14:43 +00:00
|
|
|
func present_item_list():
|
|
|
|
var count = node.get_item_count()
|
|
|
|
var selected = node.get_selected_items()
|
|
|
|
print("list, %s %s" % [count, item_or_items(count)])
|
|
|
|
print(selected)
|
|
|
|
|
2018-06-10 20:32:27 +00:00
|
|
|
func present_line_edit():
|
|
|
|
var text = "blank"
|
|
|
|
if node.secret:
|
|
|
|
text = "password"
|
|
|
|
elif node.text != "":
|
|
|
|
text = node.text
|
|
|
|
elif node.placeholder_text != "":
|
|
|
|
text = node.placeholder_text
|
|
|
|
var type = "editable text"
|
|
|
|
if not node.editable:
|
|
|
|
type = "text"
|
|
|
|
print("%s: %s" % [text, type])
|
|
|
|
|
2018-07-03 15:45:31 +00:00
|
|
|
func text_deleted(text):
|
|
|
|
print("%s deleted" % text)
|
|
|
|
|
|
|
|
func text_inserted(text):
|
|
|
|
print(text)
|
|
|
|
|
2018-06-18 20:33:03 +00:00
|
|
|
var old_pos
|
|
|
|
|
|
|
|
func check_caret_moved():
|
2018-06-12 12:32:09 +00:00
|
|
|
var pos = node.caret_position
|
2018-06-18 20:33:03 +00:00
|
|
|
if old_pos != pos:
|
|
|
|
var text = node.text
|
|
|
|
if pos > len(text)-1:
|
|
|
|
print("blank")
|
|
|
|
else:
|
|
|
|
print(text[pos])
|
|
|
|
old_pos = pos
|
2018-06-12 12:32:09 +00:00
|
|
|
|
2018-06-10 21:02:45 +00:00
|
|
|
func present_tree():
|
|
|
|
var root = node.get_root()
|
|
|
|
var count = 0
|
|
|
|
print("tree: %s %s" % [count, item_or_items(count)])
|
|
|
|
|
2018-05-28 21:45:13 +00:00
|
|
|
func focused():
|
2018-06-10 20:18:00 +00:00
|
|
|
if node is Button:
|
2018-06-10 20:32:27 +00:00
|
|
|
present_button()
|
2018-06-10 21:14:43 +00:00
|
|
|
elif node is ItemList:
|
|
|
|
present_item_list()
|
2018-06-10 20:32:27 +00:00
|
|
|
elif node is LineEdit:
|
|
|
|
present_line_edit()
|
2018-06-10 21:02:45 +00:00
|
|
|
elif node is Tree:
|
|
|
|
present_tree()
|
2018-06-10 20:18:00 +00:00
|
|
|
else:
|
|
|
|
print("Focus entered.", self.node)
|
2018-05-28 16:48:02 +00:00
|
|
|
|
2018-05-28 21:45:13 +00:00
|
|
|
func unfocused():
|
2018-06-10 19:42:58 +00:00
|
|
|
pass
|
2018-05-28 21:09:29 +00:00
|
|
|
|
2018-06-10 19:42:58 +00:00
|
|
|
func gui_input(event):
|
2018-06-18 20:33:03 +00:00
|
|
|
if self.node is LineEdit:
|
|
|
|
check_caret_moved()
|
2018-05-28 16:48:02 +00:00
|
|
|
|
|
|
|
func _init(node):
|
2018-06-07 21:18:36 +00:00
|
|
|
if node.is_in_group("accessible"):
|
|
|
|
return
|
|
|
|
node.add_to_group("accessible")
|
2018-05-28 16:48:02 +00:00
|
|
|
self.node = node
|
2018-06-10 19:42:58 +00:00
|
|
|
# self.node.set_focus_mode(Control.FOCUS_ALL)
|
2018-05-28 21:45:13 +00:00
|
|
|
self.node.connect("focus_entered", self, "focused")
|
|
|
|
self.node.connect("mouse_entered", self, "focused")
|
|
|
|
self.node.connect("focus_exited", self, "unfocused")
|
|
|
|
self.node.connect("mouse_exited", self, "unfocused")
|
|
|
|
self.node.connect("gui_input", self, "gui_input")
|
2018-07-03 15:45:31 +00:00
|
|
|
if self.node is LineEdit:
|
|
|
|
self.node.connect("text_deleted", self, "text_deleted")
|
|
|
|
self.node.connect("text_inserted", self, "text_inserted")
|
2018-05-28 16:48:02 +00:00
|
|
|
self.node.connect("tree_exiting", self, "free")
|