While this "widget" library is in beta stage, please understand that things can change between now and the time it is deemed stable. Be prepared to modify things such as parameter names, arguments, etc. in later builds if you choose to use it at this time.
To help things move quicker, if you find any issues, please report bugs properly (rather than using the forum), so we can squash them as soon as possible. Please include "Widget" in the bug title. Thank you for your cooperation and feedback!
Current version: 0.2 (beta)
Corona's widget library provides easy-access to common user interface widgets. Please see the Known Beta Issues and Recent Changes section (towards the bottom of this page) before you use these widgets in any of your projects.
For a demonstration of basic widget use, you'll find an example project called Widget Demo in the /SampleCode/Interface/WidgetDemo folder included in every Corona SDK download.
The following line makes all widgets available under the "widget" namespace.
local widget = require "widget"
See the Widget Themes section for more information on how to edit/use themes.
In case the API names are not descriptive enough, most of the documentation pages show a screenshot of each widget.
The mechanism used for 'theming' widgets is now completely different, and much more flexible. Themes are now external lua modules that you include in your project folder, which will have tables for the corresponding widgets. The individual widget tables in your theme file will have the parameters, and references to any graphics assets that are needed.
When a widget is instantiated, it first checks to see if there is a corresponding table in your theme file, with corresponding parameters. For parameters that aren't found in your theme file, the default values are used. You can override any theme parameters by setting your own parameters when you create a widget.
Please use the official themes as a reference for creating your own themes. Download links for the current "official" themes are below:
To set a theme, please see the widget.setTheme() API reference page.
Although widgets contain a display object via their .view property, they are not display objects in and of themselves. Because of this, when you are inserting a widget into a display group, you must insert the widget's .view property instead. Example:
-- WRONG: Will produce error: someGroup:insert( myWidget ) -- CORRECT: someGroup:insert( myWidget.view )
Widgets must only be removed via display.remove() or the removeSelf() method. Most display objects are automatically removed when their parent group is removed. For example:
local someGroup = display.newGroup() obj1 = display.newImage( "obj1.png" ) obj2 = display.newImage( "obj2.png" ) obj3 = display.newImage( "obj3.png" ) someGroup:insert( obj1 ) someGroup:insert( obj2 ) someGroup:insert( obj3 ) -- All three objects (obj1, obj2, & obj3) will also be removed: display.remove( someGroup ) someGroup = nil
The above code shows that when you remove a display group, its children objects will also be removed. This is NOT the case with UI widgets. While the widget may no longer appear on the screen, some properties/resources are still kept in memory.
To avoid memory leaks, manually remove any UI widgets:
-- insert widget into a display group someGroup:insert( myWidget.view ) -- remove widget first: display.remove( myWidget ) myWidget = nil -- then remove the display group: display.remove( someGroup ) someGroup = nil
DO NOT rely on the removal of a parent group to remove UI widgets, doing so will likely result in unexpected behavior and/or app crashes.
Please consider the following list of known beta issues before filing a bug report.
Version 0.2 (beta) includes tons of bug fixes and even a brand new widget, but it also imposes quite a few changes to the API, so please see the corresponding documentation for any widgets you are using or plan to use.
• scrollViews and tableViews have been completely re-designed from the ground-up for performance, stability, and flexibility (for the better, but this also explains the sudden absence of scrollbars, which will come in a later update).
• tableViews on older devices (such as the 3rd generation iPod touch and older) may experience performance issues with 500+ rows. Please consider implementing Apple's standard method of having a 'Show 25 More' row if your tableViews are going to have a very high number of rows, or consider splitting your content up using the tabBar widget.
• tableView bugs regarding the loss of rows and instability have been corrected, and are now stable/smooth at 60 FPS.
• tableView row items are handled completely differently now. There is no more setting titleText, icons, description text, or arrows. Each row is just another display group in which you handle all of the rendering. With that being said, if you were using the previous tableView implementation, your code will break—it will need to be updated to work with this new API.
• tableView category rows are much more stable, and rendering is handled in the same manner as regular row items, which means category rows are much more flexible in terms of what they can have in them.
• display.newText() is no longer affected by the widget library for retina-compatible text. Instead, display.newRetinaText() and display.newEmbossedText() have been made into factory functions.
• widget.newSegmentedControl() has been removed from the widget library, but is still available through the—now unsupported—open-source module: http://developer.anscamobile.com/code/segmented-control-widget.
• widget.newToolbar() has been removed in favor of creating a blank tabBar widget, and creating embossed text over it.
• pickerWheels no longer have built-in presets (due to the complete revampe of tableViews, pickerWheels also had to be re-created). These may be added in a future update.
• Buttons no longer have an iOS bar-button style applied to them by default, and also no longer auto-size by width (due to issues with retina compatible text). Because there are so many different types of buttons, they will instead be segregated via "styles" in theme files for the button widget.
• Despite a few small bug fixes, the slider widget is the only one that hasn't changed. A future update to widget will address some of the issues regarding sliders placed in groups, etc.