-
Notifications
You must be signed in to change notification settings - Fork 23
/
components.gui_script
104 lines (88 loc) · 3.61 KB
/
components.gui_script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local gooey = require "gooey.gooey"
local utils = require "gooey.themes.utils"
local COLOR_LIGHTGREY = vmath.vector4(0.8, 0.8, 0.8, 1)
local COLOR_WHITE = vmath.vector4(1)
local COLOR_BLACK = vmath.vector4(0,0,0,1)
local COLOR_RED = vmath.vector4(1,0,0,1)
local function update_radiobutton(radiobutton)
if radiobutton.selected_now then
gui.set_color(radiobutton.node, COLOR_RED)
utils.shake(radiobutton.node, vmath.vector3(1))
elseif radiobutton.deselected_now then
gui.set_color(radiobutton.node, COLOR_WHITE)
utils.shake(radiobutton.node, vmath.vector3(1))
end
end
local function update_checkbox(checkbox)
if checkbox.checked_now then
gui.set_color(checkbox.node, COLOR_RED)
utils.shake(checkbox.node, vmath.vector3(1))
elseif checkbox.unchecked_now then
gui.set_color(checkbox.node, COLOR_WHITE)
utils.shake(checkbox.node, vmath.vector3(1))
end
end
local function update_button(button)
if button.over_now then
gui.set_color(button.node, COLOR_LIGHTGREY)
elseif button.out_now then
gui.set_color(button.node, COLOR_WHITE)
elseif button.pressed_now then
utils.shake(button.node, vmath.vector3(1))
end
end
local function update_input(input)
if input.pressed_now then
gui.set_color(input.node, COLOR_RED)
elseif input.released_now then
gui.set_color(input.node, COLOR_BLACK)
end
end
local function update_list(list)
for i,item in ipairs(list.items) do
gui.set_text(item.nodes[hash("listitem_text")], item.data or "")
end
end
function init(self)
gooey.acquire_input()
update_checkbox(gooey.checkbox("checkbox").set_checked(true))
update_radiobutton(gooey.radio("radio2").set_selected(true))
gooey.input("input_text", gui.KEYBOARD_TYPE_DEFAULT, nil, nil, { empty_text = "EMPTY, MAX 8 CHARS"})
gooey.input("input_alphanumeric", gui.KEYBOARD_TYPE_DEFAULT, nil, nil, { empty_text = "ALPHA NUMERIC CHARS" })
self.list_data = { "Sherlock", "Poirot", "Magnum", "Miss Marple", "Morse", "Columbo" }
update_list(gooey.dynamic_list("dynamiclist", "dynamiclist_bounds", "listitem", self.list_data))
end
function on_input(self, action_id, action)
local group = gooey.group("group1", function()
gooey.button("button", action_id, action, function(button)
if button.long_pressed then
print("Button was long pressed")
else
print("Button was pressed")
end
end, update_button)
gooey.button("back", action_id, action, function(button)
msg.post("controller:/go", "show_menu")
end, update_button)
gooey.checkbox("checkbox", action_id, action, function(checkbox)
print("checkbox", checkbox.checked)
end, update_checkbox)
gooey.radiogroup("MYGROUP", action_id, action, function(group_id, action_id, action)
gooey.radio("radio1", group_id, action_id, action, function(radio)
print("radio 1", radio.selected)
end, update_radiobutton)
gooey.radio("radio2", group_id, action_id, action, function(radio)
print("radio 2", radio.selected)
end, update_radiobutton)
gooey.radio("radio3", group_id, action_id, action, function(radio)
print("radio 3", radio.selected)
end, update_radiobutton)
end)
gooey.input("input_text", gui.KEYBOARD_TYPE_DEFAULT, action_id, action, { empty_text = "EMPTY, MAX 8 CHARS", max_length = 8 }, update_input)
gooey.input("input_alphanumeric", gui.KEYBOARD_TYPE_DEFAULT, action_id, action, { empty_text = "ALPHA NUMERIC CHARS", allowed_characters = "[%a%d%s]", use_marked_text = false}, update_input)
gooey.dynamic_list("dynamiclist", "dynamiclist_bounds", "listitem", self.list_data, action_id, action, nil, function(list)
print("selected item", list.selected_item.index, list.data[list.selected_item.index])
end, update_list)
end)
return group.consumed
end