Drop-Down Menu in Corona SDK
I was working on a B2B project which is targeting both iOS and Android tablet using Corona SDK. Our Customer wanted the application to be exactly the same as their web site. This caused some issues because there was not built-in structures for some web-based components, such as Drop Down Menu. So I was obliged to create my custom component for DDM. After finishing the project, I've decided to share the code so it could be helpful for some people who use Corona SDK and hate to be constrained to do something like this.
For now, I will only give the "simple usage" version. The rest will be added as soon as possible
It is required you to be familiar with both Corona SDK and Lua programming language
Simple Usage
-- DropDownMenu module local DDM = require "lib.DropDownMenu" local RowData = require "lib.RowData" -- Color DDM Row Data local colorData = {"Red", "Green", "Blue", "White"} for i=1, #colorData do local rowData = RowData.new(colorData[j], {ID=i}) colorData[j] = rowData end -- Callback function that is called when a row is clicked. local function onRowSelected(name, rowData) if name == "colors" then print("Selected color is " .. rowData.value) end end -- Initializing the DropDownMenu object local colorDDM = DDM.new({ name = "colors", x = 50, y = 100, width = 200, height = 40, dataList = colorData, onRowSelected = onRowSelected })
I am used to have the origin point ( anchor point) as top-left of the display objects, but corona default is not designed like this (except the scenes objects) which uses middle of the display objects as origin point. I changed the origin position to top-left in “main.lua” file -starting point of the app- by using code below:
display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 )
It is a matter of choice to use above code, but don’t forget to arrange it for all display objects accordingly.
I also made a sample project where you could see the whole usage of the Drop Down Menu through a simple project. You could download the project from my Github page.
I hope this works for you. If there is anything you want to ask, feel free to leave a comment.











