This shows you the differences between two versions of the page.
sample_code:dialogbox [2014/09/21 09:15] 81.174.242.106 |
sample_code:dialogbox [2014/09/21 17:22] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Sample dialog box===== | ||
- | This code was pinched from Dave Smart to check out the code blocks on the wiki. | ||
- | <code - dialist.js> | ||
- | //This demos creating dialog boxes. | ||
- | //any type of control to a dialog box. Here we | ||
- | //just adding a list control. | ||
- | |||
- | //Called when application is started. | ||
- | function OnStart() | ||
- | { | ||
- | //Create a layout with objects vertically centered. | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | //Create a button to launch the dialog. | ||
- | btn = app.CreateButton( "Show Dialog Box", 0.6, 0.1 ); | ||
- | btn.SetOnTouch( btn_OnTouch ); | ||
- | lay.AddChild( btn ); | ||
- | |||
- | //Add layout to app. | ||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | //Called when user touches our button. | ||
- | function btn_OnTouch() | ||
- | { | ||
- | //Create dialog window. | ||
- | dlgTxt = app.CreateDialog( " | ||
- | | ||
- | //Create a layout for dialog. | ||
- | layDlg = app.CreateLayout( " | ||
- | layDlg.SetPadding( 0.02, 0, 0.02, 0.02 ); | ||
- | dlgTxt.AddLayout( layDlg ); | ||
- | |||
- | //Create a list control. | ||
- | var list = " | ||
- | lstDlg = app.CreateList( list, 0.8, 0.3 ); | ||
- | lstDlg.SetTextSize( 22 ); | ||
- | lstDlg.SetTextColor( "# | ||
- | lstDlg.SetOnTouch( lst_OnTouch ); | ||
- | layDlg.AddChild( lstDlg ); | ||
- | | ||
- | //Show dialog. | ||
- | dlgTxt.Show(); | ||
- | } | ||
- | |||
- | //Handle list item selection. | ||
- | function lst_OnTouch( item ) | ||
- | { | ||
- | //Hide the dialog window. | ||
- | dlgTxt.Hide(); | ||
- | | ||
- | //Show which fruit the user chose. | ||
- | app.ShowPopup( "You chose " + item, " | ||
- | } | ||
- | </ |