-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasicApp_Lua.lua
More file actions
232 lines (208 loc) · 10.5 KB
/
Copy pathBasicApp_Lua.lua
File metadata and controls
232 lines (208 loc) · 10.5 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
local LuaWrappers = require "CCKit2.LuaWrappers"
---@module "CCKit2.CCApplicationMain"
local CCApplicationMain = LuaWrappers.import "CCKit2.CCApplicationMain"
---@module "CCKit2.CCButton"
local CCButton = LuaWrappers.import "CCKit2.CCButton"
---@module "CCKit2.CCCheckbox"
local CCCheckbox = LuaWrappers.import "CCKit2.CCCheckbox"
---@module "CCKit2.CCDefaultWindowManagerConnection"
local CCDefaultWindowManagerConnection = LuaWrappers.import "CCKit2.CCDefaultWindowManagerConnection"
---@module "CCKit2.CCDialog"
local CCDialog = LuaWrappers.import "CCKit2.CCDialog"
---@module "CCKit2.CCImage"
local CCImage = LuaWrappers.import "CCKit2.CCImage"
---@module "CCKit2.CCImageView"
local CCImageView = LuaWrappers.import "CCKit2.CCImageView"
---@module "CCKit2.CCLabel"
local CCLabel = LuaWrappers.import "CCKit2.CCLabel"
---@module "CCKit2.CCLayoutConstraint"
local CCLayoutConstraint = LuaWrappers.import "CCKit2.CCLayoutConstraint"
---@module "CCKit2.CCProgressIndicator"
local CCProgressIndicator = LuaWrappers.import "CCKit2.CCProgressIndicator"
---@module "CCKit2.CCRadioButton"
local CCRadioButton = LuaWrappers.import "CCKit2.CCRadioButton"
---@module "CCKit2.CCScrollView"
local CCScrollView = LuaWrappers.import "CCKit2.CCScrollView"
---@module "CCKit2.CCSlider"
local CCSlider = LuaWrappers.import "CCKit2.CCSlider"
---@module "CCKit2.CCStackView"
local CCStackView = LuaWrappers.import "CCKit2.CCStackView"
---@module "CCKit2.CCTabView"
local CCTabView = LuaWrappers.import "CCKit2.CCTabView"
---@module "CCKit2.CCTableView"
local CCTableView = LuaWrappers.import "CCKit2.CCTableView"
---@module "CCKit2.CCTableViewStaticDataSource"
local CCTableViewStaticDataSource = LuaWrappers.import "CCKit2.CCTableViewStaticDataSource"
---@module "CCKit2.CCTextField"
local CCTextField = LuaWrappers.import "CCKit2.CCTextField"
---@module "CCKit2.CCTextView"
local CCTextView = LuaWrappers.import "CCKit2.CCTextView"
---@module "CCKit2.CCTypes"
local CCTypes = LuaWrappers.import "CCKit2.CCTypes"
local CCColor = CCTypes.CCColor
---@module "CCKit2.CCView"
local CCView = LuaWrappers.import "CCKit2.CCView"
---@module "CCKit2.CCViewController"
local CCViewController = LuaWrappers.import "CCKit2.CCViewController"
local tableData = {
{"Name", "Address", "Phone", "Age"},
{"John Doe", "123 Apple Way", "555-1234", 49},
{"Phillip Gonzalez", "2568 Weekley Street", "302-9163", 23},
{"Herbert Rodriguez", "3208 Hood Avenue", "755-6449", 71},
{"Johnnie Wooding", "159 Heavens Way", "241-7892", 76},
{"Mary McDonald", "802 Star Route", "590-2842", 27},
{"Donna Cook", "320 Westfall Avenue", "954-0272", 43},
{"Alberto Powers", "4826 Stone Lane", "350-1833", 22},
{"Minnie Cortez", "2230 Comfort Court", "255-9970", 59},
{"Shane Moore", "4258 Ocello Street", "893-5070", 76},
}
---@class MyView: CCView
local MyView = {}
function MyView:____constructor(frame)
CCView.prototype.____constructor(self, frame)
self.backgroundColor = CCColor.blue
end
function MyView:mouseDown(event)
self.backgroundColor = CCColor.red
end
function MyView:mouseUp(event)
self.backgroundColor = CCColor.blue
end
function MyView:keyDown(event)
self.backgroundColor = CCColor.green
end
function MyView:keyUp(event)
self.backgroundColor = CCColor.blue
end
MyView = LuaWrappers.class("MyView", CCView, MyView)
---@class ViewController: CCViewController
local ViewController = {}
ViewController.count = 0
function ViewController:increment()
self.count = self.count + 1
self.label.text = "Count: " .. self.count
self.progress.progress = self.count / 100
end
function ViewController:viewDidLoad()
CCViewController.prototype.viewDidLoad(self)
self.view.window.title = "CCKit2 Demo"
self.view.backgroundColor = CCColor.white
local tabView = LuaWrappers.new(CCTabView, {x = 1, y = 1, width = self.view.frame.width, height = self.view.frame.height - 1}, {"Basic", "Table", "Stack"})
self.view:addSubview(tabView)
local basicView = tabView:contentViewAt(0)
basicView.backgroundColor = CCColor.white
self.label = LuaWrappers.new(CCLabel, {x = 1, y = 1}, "Hello World!")
basicView:addSubview(self.label)
local button = LuaWrappers.new(CCButton, {x = 1, y = 2}, "Increment", function() self:increment() end)
basicView:addSubview(button)
local scrollView = LuaWrappers.new(CCScrollView, {x = 17, y = 1, width = 12, height = 4}, {width = 11, height = 20})
basicView:addSubview(scrollView)
local image = CCImage:createFromNFP(
[[ffff0123
eeee4567
dddd89ab
bbbbcdef]])
local imageView = LuaWrappers.new(CCImageView, {x = 1, y = 1}, image)
scrollView:addSubview(imageView)
local textView = LuaWrappers.new(CCTextView, {x = 1, y = 5, width = 11, height = 16})
textView.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
scrollView:addSubview(textView)
local checkbox = LuaWrappers.new(CCCheckbox, {x = 2, y = 3}, "Enabled")
checkbox.checked = true
checkbox.onStateChange = function(_, state) button.isEnabled = state end
basicView:addSubview(checkbox)
self.progress = LuaWrappers.new(CCProgressIndicator, {x = 1, y = 4, width = 11, height = 1}, CCProgressIndicator.Style.ThinBar)
basicView:addSubview(self.progress)
local slider = LuaWrappers.new(CCSlider, {x = 1, y = 5, width = 11, height = 1})
basicView:addSubview(slider)
local sliderText = LuaWrappers.new(CCLabel, {x = 13, y = 5}, "0.0")
slider.action = function(_, position)
sliderText.text = string.format("%.1f", position)
end
basicView:addSubview(sliderText)
local textBox = LuaWrappers.new(CCTextField, {x = 1, y = 6, width = 11, height = 1})
textBox.placeholderText = "Text..."
basicView:addSubview(textBox)
local radioCallback = function(sender) end
local radioA = LuaWrappers.new(CCRadioButton, {x = 21, y = 5}, "Opt 1")
radioA.onStateChange = radioCallback
basicView:addSubview(radioA)
local radioB = LuaWrappers.new(CCRadioButton, {x = 21, y = 6}, "Opt 2")
radioB.onStateChange = radioCallback
basicView:addSubview(radioB)
local radioC = LuaWrappers.new(CCRadioButton, {x = 21, y = 7}, "Opt 3")
radioC.onStateChange = radioCallback
basicView:addSubview(radioC)
local popupButton = LuaWrappers.new(CCButton, {x = 2, y = 7}, "Dialog", function() CCDialog:messageWithOneButton(self.view.window, "Alert", "This is a test of the dialog box and text view functionality, showing word wrapping.") end)
basicView:addSubview(popupButton)
--[=[local v2 = LuaWrappers.new(MyView, {x = 5, y = 5, width = 5, height = 5})
basicView:addSubview(v2)
local v3 = LuaWrappers.new(MyView, {x = 5, y = 5, width = 5, height = 5})
basicView:addSubview(v3)
local resizingView = LuaWrappers.new(CCView, {x = 0, y = 0, width = 0, height = 0})
resizingView.backgroundColor = CCColor.yellow
basicView:addSubview(resizingView)
CCView:addConstraintsByCode([[
v2.Top = button.Bottom + 1
v2.Bottom = rootView.Bottom - 1
v2.Left = rootView.Left + 1
v2.Width = v3.Width * 2
v3.Top = button.Bottom + 1
v3.Bottom = rootView.Bottom - 1
v3.Left = v2.Right + 1
v3.Right = rootView.Right - 1
resizingView.Top = label.Top
resizingView.Bottom = label.Bottom
resizingView.Left = label.Right + 1
resizingView.Right = rootView.Right - 1
]], {
v2 = v2,
v3 = v3,
button = button,
rootView = self.view,
resizingView = resizingView,
label = self.label,
})]=]
local tableContainer = tabView:contentViewAt(1)
local tableView = LuaWrappers.new(CCTableView, {x = 1, y = 1, width = tableContainer.frame.width, height = tableContainer.frame.height}, LuaWrappers.new(CCTableViewStaticDataSource, tableData));
tableView.canSelectRow = true
tableContainer:addSubview(tableView)
local stackContainer = tabView:contentViewAt(2)
local stackView = LuaWrappers.new(CCStackView, {x = 1, y = 1, width = stackContainer.frame.width, height = stackContainer.frame.height})
stackContainer:addSubview(stackView)
stackView:addConstraints({
LuaWrappers.new(CCLayoutConstraint, stackView, CCLayoutConstraint.Attribute.Top, CCLayoutConstraint.Relation.Equal, stackContainer, CCLayoutConstraint.Attribute.Top, 1, 0),
LuaWrappers.new(CCLayoutConstraint, stackView, CCLayoutConstraint.Attribute.Bottom, CCLayoutConstraint.Relation.Equal, stackContainer, CCLayoutConstraint.Attribute.Bottom, 1, 0),
LuaWrappers.new(CCLayoutConstraint, stackView, CCLayoutConstraint.Attribute.Left, CCLayoutConstraint.Relation.Equal, stackContainer, CCLayoutConstraint.Attribute.Left, 1, 0),
LuaWrappers.new(CCLayoutConstraint, stackView, CCLayoutConstraint.Attribute.Right, CCLayoutConstraint.Relation.Equal, stackContainer, CCLayoutConstraint.Attribute.Right, 1, 0)
})
stackView.spacing = 1
stackView.arrangedHorizontally = true
stackView:addSubview(LuaWrappers.new(MyView, {x = 1, y = 1, width = 10, height = 10}), 2)
stackView:addSubview(LuaWrappers.new(MyView, {x = 1, y = 1, width = 10, height = 10}), 1)
stackView:addSubview(LuaWrappers.new(MyView, {x = 1, y = 1, width = 10, height = 10}), 3)
local quit = LuaWrappers.new(CCButton, {x = 1, y = 1}, "Quit", function() self.view.window:close() end)
self.view:addSubview(quit)
CCView:addConstraintsByCode([[
quit.CenterX = superview.CenterX
quit.Bottom = superview.Bottom
quit.Width = 6
quit.Height = 1
tabView.Top = superview.Top
tabView.Bottom = superview.Bottom - 1
tabView.Left = superview.Left
tabView.Right = superview.Right
]], {quit = quit, superview = self.view, tabView = tabView})
end
function ViewController:viewWillAppear(animated)
CCViewController.prototype.viewWillAppear(self, animated)
self.view.window.title = "CCKit2 Demo"
end
ViewController = LuaWrappers.class("ViewController", CCViewController, ViewController)
---@class AppDelegate: CCApplicationDelegate
local AppDelegate = {}
function AppDelegate:applicationWindowManagerConnection(app)
return CCDefaultWindowManagerConnection(nil, app)
end
AppDelegate = LuaWrappers.class("AppDelegate", nil, AppDelegate)
CCApplicationMain(nil, ViewController, LuaWrappers.new(AppDelegate), ...)