generated from defold/template-native-extension
-
Notifications
You must be signed in to change notification settings - Fork 19
/
example.script
176 lines (136 loc) · 3.49 KB
/
example.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
local tab1 = require("example.tab1")
local tab2 = require("example.tab2")
local tab3 = require("example.tab3")
local tab4 = require("example.tab4")
local tab5 = require("example.tab5")
local tab6 = require("example.tab6")
local style = require("example.style")
local fonts = require("example.fonts")
local images = require("example.images")
function init(self)
self.counter = 0
self.radio = 1
self.show_demo_window = false
self.show_close_window = false
imgui.set_ini_filename()
style.set()
fonts.load()
images.load()
end
local function close_window(self)
local flags = imgui.WINDOWFLAGS_NOMOVE
local full, open = imgui.begin_window("Close window", true, flags)
if full then
imgui.text("You can close this window, but cannot move")
end
imgui.end_window()
if not open then
self.show_close_window = false
end
end
local function main_menu_bar(self)
if imgui.begin_main_menu_bar() then
if imgui.begin_menu("File") then
if imgui.menu_item("Quit", "Ctrl+Q") then
sys.exit(0)
end
imgui.end_menu()
end
if imgui.begin_menu("View") then
local clicked = imgui.menu_item("Show Demo Window", nil, self.show_demo_window)
if clicked then
self.show_demo_window = not self.show_demo_window
end
imgui.end_menu()
end
if imgui.begin_menu("About") then
imgui.menu_item("Defold v" .. sys.get_engine_info().version, nil, nil, false)
imgui.end_menu()
end
imgui.end_main_menu_bar()
end
end
local function nested_menu(self)
if imgui.begin_menu("Nested Menu") then
imgui.menu_item("Nested Item")
nested_menu(self)
imgui.end_menu()
end
end
local function menu_bar(self)
if imgui.begin_menu_bar() then
if imgui.begin_menu("Menu") then
if imgui.menu_item("Menu Item") then
print("Clicked 'Menu Item'")
end
-- Shortcuts are only visual, ImGui doesn't currently use them
imgui.menu_item("Has Shortcut", "Ctrl+A")
local changed, active = imgui.menu_item("Toggleable Item", nil, self.toggle_item_active)
if changed then
self.toggle_item_active = active
print("'Toggleable Item' is " .. (self.toggle_item_active and "on" or "off"))
end
imgui.menu_item("Disabled Item", nil, nil, false)
if imgui.begin_menu("Nested Menu") then
imgui.menu_item("Item")
nested_menu(self)
imgui.end_menu()
end
if imgui.menu_item("Click Me!") then
sys.exit(0)
end
imgui.end_menu()
end
if imgui.begin_menu("Other Menu") then
if imgui.menu_item("Other Menu Item") then
print("Clicked 'Other Menu Item'")
end
imgui.end_menu()
end
imgui.end_menu_bar()
end
end
function update(self, dt)
main_menu_bar(self)
if self.show_demo_window then
imgui.demo()
end
if self.show_close_window then
close_window(self)
end
imgui.begin_window("Hello, world!", nil, imgui.WINDOWFLAGS_MENUBAR)
menu_bar(self)
imgui.begin_tab_bar("tabs")
local tab1_open = imgui.begin_tab_item("Tab1")
if tab1_open then
tab1(self)
imgui.end_tab_item()
end
local tab2_open = imgui.begin_tab_item("Tab2")
if tab2_open then
tab2(self)
imgui.end_tab_item()
end
local tab3_open = imgui.begin_tab_item("Tab3")
if tab3_open then
tab3(self)
imgui.end_tab_item()
end
local tab4_open = imgui.begin_tab_item("Tab4")
if tab4_open then
tab4(self)
imgui.end_tab_item()
end
local tab5_open = imgui.begin_tab_item("Tab5")
if tab5_open then
tab5(self)
imgui.end_tab_item()
end
local tab6_open = imgui.begin_tab_item("Tab6")
if tab6_open then
tab6(self)
imgui.end_tab_item()
end
imgui.end_tab_bar()
imgui.end_window()
end