Widget Candy. .NewButton()

Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

                
 
 
WIDGET CANDY FOR CORONA & GIDEROS iPHONE ANDROID SDK Creates a button, showing an icon and text of your choice. Use the textAlign property (see Widget Properties) to display the icon to the left or right of the text, also to align the text caption.
 
A button's icon size is defined in the theme's lua file. See 'ButtonIconSize' there. Text buttons can be auto-sized (if there width property is set to "auto"). If so, the button will automatically sized according to the size of it's text caption.
 
Common buttons are of fixed height, so the height parameter has no effect on them. The height of a button is the height of a frame on the GUI sheet texture. This is to save resources and keep performance as good as possibe. The background is that a button with a fixed height uses three images only (left cap, right cap, middle segment) while a fully scalable button would use nine elements (four corners, left, right, top, bottom, middle). If you need to use fully scalable buttons, try out the Shape Button instead.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-- REQUIRE THE LIBRARY
_G.GUI = require("widget_candy")
 
-- CREATE THE WIDGET
_G.GUI.NewButton(
	{
	x       = 0,
	y       = 0,
	width   = "50%",
	name    = "MyButton",
	theme   = "MyTheme1",
	icon    = 2,
	caption = "Touch me!",
	onPress = function( EventData ) print("I WAS PRESSED!") end,
	[any other properties...]
	} )
*************************************************
 
Properties—-
 
 	Use the common widget properties as described under Widget Properties. Additionally, this widget provides the following properties:
 
toggleButton	(Boolean) If set to true, this button will behave as a "toggle button", which means that it will stay latched until it is tapped again. The toggleState property (see next) indicates whether the button is currently "latched" or not.
_____________________________________
 
toggleState	(Boolean) If toggleButton (see above) is set to true, this property can be used to set or read the button's current state (latched or not).
_______________________________________
 
toggleGroup	(String) Specify a unique toggle group name (string) to 'group' several toggle buttons, like radio buttons. If several toggle buttons are sharing the same toggle group name and you tapped on of them, all others are set to 'unlatched' automatically.
_________________________________________
 
disableOffset	(Boolean) By default, a button's icon and text are shifted a few pixels when pressed, to provide optical feedback to the user. If you do not want this, set this property to true to disable it, the button's icon and caption remain static then.
____________________________________________
 
flipIconX	(Boolean) Flips the button's icon horizontally when set to true.
______________________________________________
flipIconY	(Boolean) Flips the button's icon vertically when set to true.
______________________________________________
iconAlign	(String) Specifies the widget's icon position ("left", "center" or "right").
*************************************************
 
 
Along with the above properties, you can also pass some functions to be called on certain events. Those functions will receive a parameter that contains useful event data.
 
Listener Functions
 
onPress	(function) If you define a function named 'onPress' with the widget's properties table, this function will be called when the user taps the widget or when a drag event begins.
 
Please note that a toggle button's toggleState will be updated with the onRelease event, not the onPress event, so use the onRelease event to ask for a toggle button's current state.
 
Example:
onPress = function( EventData ) [ YOUR CODE HERE ] end,
_________________________________________________
 
onRelease	(function) If you define a function named 'onRelease' with the widget's properties table, this function will be called when the user lifts the finger from the window or if a drag event ended. Read the EventData.inside property to find out if the finger was lifted inside or outside of the widget.
 
Example:
onRelease = function( EventData ) [ YOUR CODE HERE ] end,
__________________________________________________
 
EventData	(Table) Your onPress and onRelease functions will receive a table that contains useful event data. This table contains the following data:
 
EventData.Widget - The widget's display object handle.
 
EventData.Props - A table that contains all the widget's properties.
 
EventData.name - The name of the widget (a string).
 
EventData.inside - True if the user lifted the finger inside the widget (released inside), false if the finger was lifted outside the widget (released outside). To be used in your onRelease listener function.
 
EventData.eventName - The event's name.
 
EventData.eventID - The event's id.
***************************************************
 
METHODS —
 
Along with the common widget methods, this widget has no additional methods.
*****************************************************
 
 
 
 
 
 
 
 
 
 
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 25
Date Added: 2018-01-10 15:43:30
Last Modified: 2018-01-10 09:54:12

Web Analytics