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), ...)