Widget Candy. .NewWindow()

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 window widget. Window widgets can hold other widgets and even arrange (layout) them automatically for you. Window widgets can be dragged (horizontally, vertically, or both) within a specified drag area, which is the screen size, for example. Window widgets also provide a close button to let them disappear again.
To add any widget to a window widget, simply specify the window's unique name (in quotes) as the widget's 'parentGroup'. If a window is removed (deleted), all nested widgets are automatically deleted, too, so you don't need to remove all widgets of a window manually.
Widgets inside a window can either be positioned using absolute coordinates or positioned (arranged) automatically by calling the window's :layout() method. See Automated Widget Layout for a detailed description.
A window widget's title caption color is defined in the theme's lua file. See 'WindowCaptionColor1' and 'WindowCaptionColor2' there. You can also define some other useful window settings there like a window's font size, icon size or shadow offset, for example.
Beside tinting a window widget completely using the color property (see Widget Properties) You can also apply a colored gradient to a window's background only by specifying the properties gradientColor1, gradientColor2 and gradientDirection when creating a window (see below).
_G.GUI = require("widget_candy")
	x      = "50%",
	y      = "bottom",
	name   = "Win1",
	theme  = "MyTheme1",
	[any other properties...]
	} )
 	Use the common widget properties as described under Widget Properties. Additionally, this widget provides the following properties:
shadow	(Boolean) If set to true, a shadow will be displayed behind the window widget. A window shadow's alpha, position offset and corner radius can be defined in the theme's lua file.
windowAlpha	(Number 0..1)
Specifies the transparency of the window itself, not affecting any nested widgets.
(Boolean) If dragX is set to true, the window can be dragged horizontally, if dragY is set to true, the window can be dragged vertically.
dragArea	  ("auto" | Array) Defines the area within the window can be dragged around. If not specified, there are no drag boundaries applied. If set to "auto" (using quotes) the drag area will be automatically set to the screen dimensions (the window should not be placed within a moved or scaled display group then). If you want to define a custom drag area, pass an array with four values: dragArea = {left, top, width, height}
slideOut	(Number) Specify a value here from 0 to .99 to set the window's slide-out speed (the slow-down applied when the widget was dragged and then released). Use values from 0 (stop immediately) to .99 (slow slide out).
margin	(Number) Defines the spacing between the windows borders and the widgets placed inside.
closeButton	(Boolean) If set to true, a close button is shown on the window's top right corner. If tapped by the user, the window will set to be hidden only, not removed. Tapping a window's close button calls the onClose() function of a window (see below). You can put your own code into that function to execute any tasks when a window's clode button is used.
tapToFront	(Boolean) If set to true (default), the window will be brought to front when the window itself or any of its widgets are tapped. Set this property to false to disable this behavior.
height	("auto" | Number)
Specifies the fixed height of the window. If set to "auto" (using quotes), the window height will be calculated automatically depending on the widgets placed inside.
minHeight	(Number)
Defines the minimum height of the window (if the 'height' property is set to "auto").
gradientDirection	Corona only. Applies an additional custom color gradient to the window where colorGradient1 defines the starting color of the gradient (red, green, blue and alpha value and colorGradient2 the ending gradient color. gradientDirection defines the direction of the gradient an can be either "up", "down", "left", "right".
gradientColor1 = {1,0,1, .5},
gradientColor2 = {.25,.5,1, .5},
gradientDirection = "down",
modal	(Boolean) If set to true, the window will behave as a modal dialog -which means that everything behind the window will be darkened and set to non-interactive until the window is removed again. Note that his only works at window creation time, you cannot set a window to modal at a later time.
noTitle	(Boolean)
If set to true, the window's title bar (including icon, title caption and close button) will be suppressed (hidden).
Along with the above properties, you can also pass some functions to be called on certain events:
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.
onPress = function(EventData) [ YOUR CODE HERE ] end,
onWidgetPress	(function) If you define a function named 'onWidgetPress' with the widget's properties table, this function will be called when the user taps a widget inside the window (not the window itself). EventData.name will hold the pressed widget's name then.
onDrag	(function) If you define a function named 'onDrag' with the widget's properties table, this function will be called when the user drags the window around.
onDrag = 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.
onRelease = function(EventData) [ YOUR CODE HERE ] end,
onClose	(function) If you define a function named 'onClose' with the widget's properties table, this function will be called when the user taps the window's close button.
onClose = function(EventData) [ YOUR CODE HERE ] end,
To remove (delete) a window when the user taps the close button, call EventData.Widget:destroy() within the window's onClose listener function.
EventData	(Table) Your defined 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).
Along with the common widget methods, this widget provides the following additional methods:
MyWindow:layout ( doScreenAlign )
Arranges (positions) all widgets inside this window automatically. A window's layout() method should be used whenever you added new widgets to a window (once, after all the widgets have been added) to layout all the widgets automatically inside the window and to adjust the window height according to the widgets inside (if the window height is set to "auto"). To have widgets inside a window automatically positioned, the widget's x or y property must set to "auto" and its includeInLayout property set to true.
doScreenAlign	(Boolean) When true, the window will be re-aligned to the screen after its widgets have been arranged. This is useful, if the window should remain centered on the screen, for example, and its height changed after arranging the widgets inside.
MyWindow:close ()
Use this method to close (hide) the window programmatically. This will not remove or delete the window, it will be hidden only.
comments powered by Disqus


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:26:17
Last Modified: 2018-01-10 09:54:13

Web Analytics