This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:slide_menu [2015/09/25 07:59] stevegarman created |
sample_code:slide_menu [2019/03/02 03:42] sandudhate old revision restored (2016/01/02 05:07) and Removed DSVersion check |
||
---|---|---|---|
Line 2: | Line 2: | ||
You can swipe left to close this menu. | You can swipe left to close this menu. | ||
<code JavaScript swipeMenu.js> | <code JavaScript swipeMenu.js> | ||
- | var layMenu,lst,txe; | + | |
+ | var layMenu, | ||
// | // | ||
function OnStart() | function OnStart() | ||
Line 8: | Line 9: | ||
app.SetOrientation(" | app.SetOrientation(" | ||
app.EnableBackKey(false); | app.EnableBackKey(false); | ||
+ | |||
// | // | ||
- | var layMain=app.CreateLayout(" | + | var layApp=app.CreateLayout(" |
- | layMain.SetBackColor("# | + | layApp.SetBackColor("# |
- | layMain.SetPosition(0, | + | layApp.SetPosition(0, |
- | app.AddLayout(layMain); | + | app.AddLayout(layApp); |
- | var lay=app.CreateLayout(" | + | |
+ | // | ||
+ | var layHome=app.CreateLayout(" | ||
var btnMnu; | var btnMnu; | ||
- | if(app.GetDSVersion()> | + | btnMnu=app.CreateButton(" |
- | { | + | btnMnu.SetStyle( "# |
- | btnMnu=app.CreateButton(" | + | |
- | btnMnu.SetStyle( "# | + | |
- | } | + | |
- | else | + | |
- | btnMnu=app.CreateButton(" | + | |
btnMnu.SetOnTouch(mnuAnimate); | btnMnu.SetOnTouch(mnuAnimate); | ||
- | lay.AddChild(btnMnu); | + | layHome.AddChild(btnMnu); |
txe =app.CreateTextEdit(" | txe =app.CreateTextEdit(" | ||
txe.SetMargins(0.05, | txe.SetMargins(0.05, | ||
txe.SetBackColor("# | txe.SetBackColor("# | ||
- | lay.AddChild(txe); | + | layHome.AddChild(txe); |
- | layMain.AddChild(lay); | + | layApp.AddChild(layHome); |
// | // | ||
- | layMenu = app.CreateLayout( " | + | layMenu = getSlideMenu(menu_OnTouch, |
+ | layMenu.SetPosition(0, | ||
+ | // | ||
+ | layMenu.AddItem(" | ||
+ | layMenu.AddItem(" | ||
+ | layMenu.AddItem(" | ||
+ | layMenu.AddItem(" | ||
+ | |||
+ | // | ||
+ | layApp.AddChild( layMenu ); | ||
+ | } | ||
+ | |||
+ | function mnuAnimate() | ||
+ | { | ||
+ | if(layMenu.GetVisibility()===" | ||
+ | layMenu.Show(); | ||
+ | else | ||
+ | layMenu.Hide(); | ||
+ | } | ||
+ | |||
+ | function OnBack() | ||
+ | { | ||
+ | if(layMenu.GetVisibility()===" | ||
+ | layMenu.Animate(" | ||
+ | else app.Exit(); | ||
+ | } | ||
+ | |||
+ | // | ||
+ | function OnMenu( item ) | ||
+ | { | ||
+ | if(item==null) mnuAnimate(); | ||
+ | } | ||
+ | |||
+ | function getSlideMenu(onTouch, | ||
+ | { | ||
+ | // | ||
+ | var lst | ||
+ | var layMenu = app.CreateLayout( " | ||
layMenu.SetPosition(0, | layMenu.SetPosition(0, | ||
layMenu.SetBackColor("# | layMenu.SetBackColor("# | ||
Line 37: | Line 73: | ||
// | // | ||
lst = app.CreateList( "" | lst = app.CreateList( "" | ||
- | lst.SetOnTouch(lst_OnTouch); | + | if(onTouch) lst.SetOnTouch(onTouch); |
lst.SetList(null); | lst.SetList(null); | ||
- | lst.AddItem(" | ||
- | lst.AddItem(" | ||
- | lst.AddItem(" | ||
- | lst.AddItem(" | ||
layMenu.AddChild( lst ); | layMenu.AddChild( lst ); | ||
// | // | ||
var img=app.CreateImage(null, | var img=app.CreateImage(null, | ||
- | img.downX=0 | + | img.menu=lst; |
- | img.SetOnTouch(swipeTest); | + | img.downX=0; |
+ | if(swipeTest) img.SetOnTouch(swipeTest); | ||
layMenu.AddChild(img); | layMenu.AddChild(img); | ||
- | //Add layout to app. | + | //public methods |
- | layMain.AddChild( layMenu ); | + | img.Hide=function() |
+ | { | ||
+ | layMenu.Hide(); | ||
+ | } | ||
+ | layMenu.Show=function() | ||
+ | { | ||
+ | this.Animate(" | ||
+ | } | ||
+ | layMenu.Hide=function() | ||
+ | { | ||
+ | this.Animate(" | ||
+ | } | ||
+ | layMenu.AddItem=function( title, | ||
+ | { | ||
+ | lst.AddItem( title, | ||
+ | } | ||
+ | layMenu.Setlist=function( list, | ||
+ | { | ||
+ | lst.SetList( list, | ||
+ | } | ||
+ | return layMenu | ||
} | } | ||
- | function mnuAnimate() | + | // |
+ | function menu_OnTouch( title, | ||
{ | { | ||
- | if(layMenu.GetVisibility()==="Hide") | + | var s = txe.GetText()+"\n"+title; |
- | layMenu.Animate(" | + | txe.SetText(s); |
- | else | + | app.ShowPopup(title+" added") |
- | layMenu.Animate("SlideToLeft"); | + | |
} | } | ||
- | function swipeTest(ev) | + | // |
+ | function menu_SwipeTest(ev) | ||
{ | { | ||
if(ev.action===" | if(ev.action===" | ||
Line 71: | Line 125: | ||
{ | { | ||
if(ev.X-this.downX < | if(ev.X-this.downX < | ||
- | layMenu.Animate(" | + | this.Hide(); |
else | else | ||
- | app.SimulateTouch(lst, | + | app.SimulateTouch(this.menu, |
} | } | ||
- | } | ||
- | |||
- | function lst_OnTouch( title, | ||
- | { | ||
- | var s = txe.GetText()+" | ||
- | txe.SetText(s); | ||
- | app.ShowPopup(title+" | ||
- | } | ||
- | |||
- | function OnBack() | ||
- | { | ||
- | if(layMenu.GetVisibility()===" | ||
- | layMenu.Animate(" | ||
- | else app.Exit(); | ||
} | } | ||
</ | </ |