Back

Enable Drag

Drag methods using the EnableDrag method of the Support object:

 sup.EnableDrag( object, tagname, callback );

match: obj.EnableDrag( tagname, callback );

Example - Simple

 app.LoadPlugin( "Support" );  function OnStart()
 {
 lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

 sup = app.CreateSupport();

 left = app.CreateButton( "Left" );
 left.EnableDrag( "DragButton", OnDragStart );
 lay.AddChild( left );

 right = app.CreateButton( "Right", 0.4, 0.4 );
 right.SetTag( "RightButton" );
 right.On( "drag", OnDrag );
 lay.AddChild( right );

 app.AddLayout( lay );
 }

 function OnDrag( action, tag )
 {

 switch( action )
 {
 case "Start": lay.SetBackColor( color.RED );break;
 case "Enter": lay.SetBackColor( color.GREEN ); break;
 case "Exit": lay.SetBackColor( color.RED ); break;
 case "Drop":
  if( tag == "RightButton" ) right.SetText( "Dropped" );
break;
 case "Stop": lay.SetBackColor( "Black" ); break;
 }

 }

 function OnDragStart( tag )
 {
 console.log( "Start Drag For: "+tag );
 }
  Copy   Copy All    Run   

Example - Remove Images

 app.LoadPlugin( "Support" );
 
 //Called when application is started.
 function OnStart()
 {
 layer = app.CreateLayout( "Absolute", "FillXY" );
 layer.SetBackColor( "#FAFAFA" );

 sup = app.CreateSupport();
 anim = sup.AnimationManager();

 // Content.
 layc = sup.CreateGridLayout( "FillXY,Center" );
 layc.SetColCount( 5 );
 layc.SetBackColor( "#FAFAFA" );


 for( var i=0; i<10; i++ ) {
  var tag = "btn-"+i;
  window[tag] = app.CreateImage( "/Sys/Img/Droid"+((i%2)+1)+".png", 0.1 );
  window[tag].EnableDrag( tag, OnDragStart );
  layc.AddChild( window[tag] );
 }

layer.AddChild( layc );
 
 // Drag Menu.
 layd = app.CreateLayout( "Linear", "VCenter,FillXY" );
 layd.SetSize( 0.8/_asp, 0.8 );
  layd.SetState( color.GREY, color.GREY, 0.4/_asp );
 layd.SetPosition( 0.5-(0.4/2), 0.5 );
 layd.SetAlpha( 0 ); // not use hide. 'Cause not show drag listener.
 
 close = app.CreateButton( "[fa-close]", 0.4/_asp, 0.4, "fontawesome" );
 close.SetState( color.GREY_DARK_2, color.GREY_DARK_2, 0.4/_asp );
 close.SetTextSize( 32 );
 close.SetTextColor( "White" );
 close.SetTag( "delete" );
 close.On( "Drag", OnDrag );
 layd.AddChild( close );
 
 layer.AddChild( layd );
 
 //Add layout to app.
 app.AddLayout( layer );
 }
 
 function OnDragStart( tag )
 {
  select = window[tag];
  // select.Hide();
  anim.ZoomInEnter( layd ).Play();
 }
 
 function OnDrag( action, tag )
 {
  switch( action )
 {
  case "Start": break;
  case "Enter": break;
  case "Exit": break;
  case "Drop":
   if( tag == "delete" ) select.Gone();
   // else select.Show();   break;
  case "Stop": anim.ZoomOutExit( layd ).Play(); break;
 }
 }
  Copy   Copy All    Run