User Tools

Site Tools


sample_code:slide_menu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
sample_code:slide_menu [2015/09/25 07:59]
stevegarman created
sample_code:slide_menu [2019/03/02 11:42] (current)
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,txe;
 //Called when application is started. //Called when application is started.
 function OnStart() function OnStart()
Line 8: Line 9:
     app.SetOrientation("Portrait");     app.SetOrientation("Portrait");
     app.EnableBackKey(false);     app.EnableBackKey(false);
 +
     //container layout     //container layout
-    var layMain=app.CreateLayout("Absolute"); +    var layApp=app.CreateLayout("Absolute"); 
-    layMain.SetBackColor("#ff224422"); +    layApp.SetBackColor("#ff224422"); 
-    layMain.SetPosition(0,0,1,1); +    layApp.SetPosition(0,0,1,1); 
-    app.AddLayout(layMain); +    app.AddLayout(layApp); 
-    var lay=app.CreateLayout("Linear","Left,FillXY");+ 
 +    //home layout 
 +    var layHome=app.CreateLayout("Linear","Left,FillXY");
     var btnMnu;     var btnMnu;
-    if(app.GetDSVersion()>1.25) +    btnMnu=app.CreateButton("[fa-bars]", -1, -1, "fontawesome,custom"); 
-    { +    btnMnu.SetStyle( "#77bb77", "#559955", 15, "#449944",2,0 );
-       btnMnu=app.CreateButton("[fa-bars]", -1, -1, "fontawesome,custom"); +
-       btnMnu.SetStyle( "#77bb77", "#559955", 15, "#449944",2,); +
-    } +
-    else +
-       btnMnu=app.CreateButton("[fa-bars]", -1, -1, "fontawesome,alum");+
     btnMnu.SetOnTouch(mnuAnimate);     btnMnu.SetOnTouch(mnuAnimate);
-    lay.AddChild(btnMnu);+    layHome.AddChild(btnMnu);
     txe =app.CreateTextEdit("aaaaa\nbbbbb",0.9,0.8);     txe =app.CreateTextEdit("aaaaa\nbbbbb",0.9,0.8);
     txe.SetMargins(0.05,0.02,0,0)     txe.SetMargins(0.05,0.02,0,0)
     txe.SetBackColor("#ff888888");     txe.SetBackColor("#ff888888");
-    lay.AddChild(txe); +    layHome.AddChild(txe); 
-    layMain.AddChild(lay);+    layApp.AddChild(layHome);
  
    //Create menu layout    //Create menu layout
-    layMenu = app.CreateLayout( "Absolute", "" );    +    layMenu = getSlideMenu(menu_OnTouch, menu_SwipeTest);     
 +    layMenu.SetPosition(0,0.08); 
 +    //Populate menu list 
 +    layMenu.AddItem("Hello","World","/Sys/Img/Add.png"); 
 +    layMenu.AddItem("Another","Item","/Sys/Img/Bulb.png"); 
 +    layMenu.AddItem("Three","","video"); 
 +    layMenu.AddItem("Four","","audio"); 
 + 
 +    //Add layout to app.     
 +    layApp.AddChild( layMenu ); 
 +
 + 
 +function mnuAnimate() 
 +
 +    if(layMenu.GetVisibility()==="Hide"
 +       layMenu.Show(); 
 +    else 
 +       layMenu.Hide(); 
 +
 + 
 +function OnBack() 
 +
 +   if(layMenu.GetVisibility()==="Show"
 +      layMenu.Animate("SlideToLeft"); 
 +   else app.Exit(); 
 +
 + 
 +//catch hardware menu button 
 +function OnMenu( item ) 
 +{     
 +    if(item==null) mnuAnimate(); 
 +
 + 
 +function getSlideMenu(onTouch, swipeTest) 
 +
 +//Create menu layout 
 +    var lst 
 +    var layMenu = app.CreateLayout( "Absolute", "" );    
     layMenu.SetPosition(0,0.08);     layMenu.SetPosition(0,0.08);
     layMenu.SetBackColor("#ff66aa66");     layMenu.SetBackColor("#ff66aa66");
Line 37: Line 73:
     //Create menu list     //Create menu list
     lst = app.CreateList( "" ,0.8,0.8);     lst = app.CreateList( "" ,0.8,0.8);
-    lst.SetOnTouch(lst_OnTouch);+    if(onTouch) lst.SetOnTouch(onTouch);
     lst.SetList(null);     lst.SetList(null);
-    lst.AddItem("Hello","World","/Sys/Img/Add.png"); 
-    lst.AddItem("Another","Item","/Sys/Img/Bulb.png"); 
-    lst.AddItem("Three","","video"); 
-    lst.AddItem("Four","","audio"); 
     layMenu.AddChild( lst );     layMenu.AddChild( lst );
     //create swiper image     //create swiper image
     var img=app.CreateImage(null,0.8,0.8);     var img=app.CreateImage(null,0.8,0.8);
-    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.AddChildlayMenu );+    img.Hide=function() 
 +    
 +         layMenu.Hide(); 
 +    
 +    layMenu.Show=function(
 +    { 
 +         this.Animate("SlideFromLeft"); 
 +    } 
 +    layMenu.Hide=function() 
 +    { 
 +         this.Animate("SlidetoLeft"); 
 +    } 
 +    layMenu.AddItem=function( title,body,image ) 
 +    { 
 +        lst.AddItem( title,body,image ); 
 +    } 
 +    layMenu.Setlist=function( list,delim ) 
 +    { 
 +        lst.SetList( list,delim ) 
 +    } 
 +    return layMenu
 } }
  
-function mnuAnimate()+// callback function for menu selection 
 +function menu_OnTouchtitle, body, image, index )
 { {
-    if(layMenu.GetVisibility()==="Hide") +  var s = txe.GetText()+"\n"+title; 
-       layMenu.Animate("SlideFromLeft"); +  txe.SetText(s); 
-    else +  app.ShowPopup(title+added")
-       layMenu.Animate("SlideToLeft");+
 } }
  
-function swipeTest(ev)+// callback function to swipe close menu 
 +function menu_SwipeTest(ev)
 { {
     if(ev.action==="Down")     if(ev.action==="Down")
Line 71: Line 125:
     {     {
         if(ev.X-this.downX < -0.1)         if(ev.X-this.downX < -0.1)
-           layMenu.Animate("SlideToLeft");+           this.Hide();
         else          else 
-           app.SimulateTouch(lst,ev.X,ev.Y);+           app.SimulateTouch(this.menu,ev.X,ev.Y);
     }     }
-} 
- 
-function lst_OnTouch( title, body, image, index ) 
-{ 
-  var s = txe.GetText()+"\n"+title; 
-  txe.SetText(s); 
-  app.ShowPopup(title+" added") 
-} 
- 
-function OnBack() 
-{ 
-   if(layMenu.GetVisibility()==="Show") 
-      layMenu.Animate("SlideToLeft"); 
-   else app.Exit(); 
 } }
  
 </code> </code>
sample_code/slide_menu.1443167943.txt.gz · Last modified: 2015/09/25 15:59 (external edit)