jan_flanders

Untitled

Aug 15th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef Xywh = {x:Float, y:Float, width:Float, height:Float};
  2.  
  3. class MyButton extends flash.display.Sprite{public function new() super()}
  4.  
  5. using Main;
  6.  
  7. class Main extends flash.display.Sprite
  8. {
  9.     public function new()
  10.     {
  11.         super();
  12.         [new MyButton(), new MyButton(), new MyButton()].distribute(20, PlaceTools.HORIZONTAL);
  13.     }
  14.    
  15.     public static function main()
  16.     {
  17.         flash.Lib.current.addChild(new Main());
  18.     }
  19. }
  20.  
  21.  
  22. class PlaceTools
  23. {
  24.     public static var HORIZONTAL:String = "horizontal";
  25.  
  26.     public static function rightOf(target:Xywh, ref:Xywh, ?padding:Int=0, ?align:Bool=true, ?width:Float=0, ?height:Float=0):Void
  27.     {
  28.         target.x = ref.x + ref.width + padding;
  29.         if(align) target.y = ref.y;
  30.         if(width!=0)target.width=width;
  31.         if(height!=0)target.height=height;
  32.     }
  33.     public static function distribute(arr:Array<Xywh>, ?padding:Int=0, ?dtype:String="horizontal")
  34.     {
  35.         for(i in 1...arr.length)
  36.         {
  37.             switch(dtype)
  38.             {
  39.                 case HORIZONTAL:
  40.                     arr[i].rightOf(arr[i-1], padding);
  41.                    
  42.                 default:
  43.                     trace("not implemented in this example");
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment