Repository navigation
Expand file tree
/
Copy pathdynamiclist.gui_script
More file actions
89 lines (78 loc) · 2.76 KB
/
Copy pathdynamiclist.gui_script
File metadata and controls
89 lines (78 loc) · 2.76 KB
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
local gooey = require "gooey.gooey"
local image_cache = require "gooey.image_cache"
local cache = image_cache.create()
local function refresh_dynamiclist(list)
for _,item in ipairs(list.items) do
local pos = gui.get_position(item.root)
if item == list.selected_item then
pos.x = 4
elseif item == list.pressed_item then
pos.x = 4
elseif item == list.over_item_now then
pos.x = -4
elseif item == list.out_item_now then
pos.x = 0
elseif item ~= list.over_item then
pos.x = 0
end
gui.set_position(item.root, pos)
if item.data then
local image_node = item.nodes[hash("listitem_image")]
local text_node = item.nodes[hash("listitem_text")]
local url = ("https://dummyimage.com/40x40/%s/%s.png"):format(item.data.color, item.data.color)
gui.set_text(text_node, tostring(item.data.text))
gui.set_enabled(image_node, false)
image_cache.load(cache, url, image_node, function()
gui.set_enabled(image_node, true)
end)
end
end
end
function init(self)
gooey.acquire_input()
self.list_data = {
{ text = "Red", color = "f00" },
{ text = "Blue", color = "00f" },
{ text = "Green", color = "0f0" },
{ text = "Yellow", color = "ff0" },
{ text = "Orange", color = "f70" },
{ text = "Light grey", color = "ddd" },
{ text = "White", color = "fff" },
{ text = "Black", color = "000" },
{ text = "Salmon", color = "f87" },
{ text = "Pink", color = "fcc" },
{ text = "Coral", color = "f75" },
{ text = "Lavender", color = "eef" },
{ text = "Magenta", color = "f0f" },
}
gooey.dynamic_list("dynamiclist_bg", "dynamiclist_stencil", "listitem_bg", self.list_data, nil, nil, nil, nil, refresh_dynamiclist)
end
function final(self)
image_cache.clear(cache)
end
function on_input(self, action_id, action)
gooey.button("back_button", action_id, action, function(button)
msg.post("controller:/go", "show_menu")
end)
gooey.button("resize_button", action_id, action, function(button)
local height = math.random(300, 600)
local bg = gui.get_node("dynamiclist_bg")
local stencil = gui.get_node("dynamiclist_stencil")
local bg_size = gui.get_size(bg)
local stencil_size = gui.get_size(stencil)
bg_size.y = height
stencil_size.y = height * 0.95
gui.set_size(bg, bg_size)
gui.set_size(stencil, stencil_size)
end)
local list = gooey.dynamic_list("dynamiclist_bg", "dynamiclist_stencil", "listitem_bg", self.list_data, action_id, action, nil, function(list)
print("selected dynamic list item", list.selected_item.index, list.data[list.selected_item.index].text)
end, refresh_dynamiclist)
gooey.vertical_scrollbar("scrollbar_handle", "scrollbar_bg", action_id, action, function(scrollbar)
list.scroll_to(0, scrollbar.scroll.y)
end)
end
function on_reload(self)
-- Add input-handling code here
-- Remove this function if not needed
end