Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef Xywh = {x:Float, y:Float, width:Float, height:Float};
- class MyButton extends flash.display.Sprite{public function new() super()}
- using Main;
- class Main extends flash.display.Sprite
- {
- public function new()
- {
- super();
- [new MyButton(), new MyButton(), new MyButton()].distribute(20, PlaceTools.HORIZONTAL);
- }
- public static function main()
- {
- flash.Lib.current.addChild(new Main());
- }
- }
- class PlaceTools
- {
- public static var HORIZONTAL:String = "horizontal";
- public static function rightOf(target:Xywh, ref:Xywh, ?padding:Int=0, ?align:Bool=true, ?width:Float=0, ?height:Float=0):Void
- {
- target.x = ref.x + ref.width + padding;
- if(align) target.y = ref.y;
- if(width!=0)target.width=width;
- if(height!=0)target.height=height;
- }
- public static function distribute(arr:Array<Xywh>, ?padding:Int=0, ?dtype:String="horizontal")
- {
- for(i in 1...arr.length)
- {
- switch(dtype)
- {
- case HORIZONTAL:
- arr[i].rightOf(arr[i-1], padding);
- default:
- trace("not implemented in this example");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment