added view group
This commit is contained in:
49
com/abit/haxework/gui/GroupView.hx
Executable file
49
com/abit/haxework/gui/GroupView.hx
Executable file
@@ -0,0 +1,49 @@
|
||||
package com.abit.haxework.gui;
|
||||
|
||||
import com.abit.haxework.gui.layout.DefaultLayout;
|
||||
import com.abit.haxework.gui.layout.ILayout;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class GroupView extends View implements IGroupView<Sprite> {
|
||||
|
||||
public var layout(default, default):ILayout;
|
||||
public var views(default, null):Array<IView<Sprite>>;
|
||||
private var viewsById:Map<String, IView<Sprite>>;
|
||||
|
||||
public function new(?layout:ILayout) {
|
||||
super();
|
||||
this.layout = layout == null ? new DefaultLayout() : layout;
|
||||
views = [];
|
||||
viewsById = new Map<String, IView<Sprite>>();
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
layout.place(this, views);
|
||||
for (view in views) view.update();
|
||||
super.update();
|
||||
}
|
||||
|
||||
public function addView(view:IView<Sprite>):IView<Sprite> {
|
||||
views.push(view);
|
||||
viewsById.set(view.id, view);
|
||||
content.addChild(view.content);
|
||||
view.parent = this;
|
||||
return view;
|
||||
}
|
||||
|
||||
public function removeView(view:IView<Sprite>):IView<Sprite> {
|
||||
view.parent = null;
|
||||
viewsById.remove(view.id);
|
||||
views.remove(view);
|
||||
content.removeChild(view.content);
|
||||
return view;
|
||||
}
|
||||
|
||||
public function removeViewById(id:String):IView<Sprite> {
|
||||
if (viewsById.exists(id)) {
|
||||
return removeView(viewsById.get(id));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
com/abit/haxework/gui/IGroupView.hx
Executable file
13
com/abit/haxework/gui/IGroupView.hx
Executable file
@@ -0,0 +1,13 @@
|
||||
package com.abit.haxework.gui;
|
||||
|
||||
import com.abit.haxework.gui.layout.ILayout;
|
||||
|
||||
interface IGroupView<C> extends IView<C> {
|
||||
|
||||
public var views(default, null):Array<IView<C>>;
|
||||
public var layout(default, default):ILayout;
|
||||
|
||||
public function addView(view:IView<C>):IView<C>;
|
||||
public function removeView(view:IView<C>):IView<C>;
|
||||
public function removeViewById(id:String):IView<C>;
|
||||
}
|
||||
@@ -15,5 +15,7 @@ interface IView<C> {
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):ISkin<C, IView<C>>;
|
||||
|
||||
public var parent(default, null):Null<IView<C>>;
|
||||
|
||||
public function update():Void;
|
||||
}
|
||||
@@ -24,6 +24,8 @@ class View implements IView<Sprite> {
|
||||
public var content(default, null):Sprite;
|
||||
public var skin(default, set):ISkin<Sprite, IView<Sprite>>;
|
||||
|
||||
public var parent(default, null):Null<IView<Sprite>>;
|
||||
|
||||
public function new() {
|
||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||
content = new Sprite();
|
||||
|
||||
12
com/abit/haxework/gui/layout/DefaultLayout.hx
Executable file
12
com/abit/haxework/gui/layout/DefaultLayout.hx
Executable file
@@ -0,0 +1,12 @@
|
||||
package com.abit.haxework.gui.layout;
|
||||
|
||||
class DefaultLayout implements ILayout {
|
||||
|
||||
public function new() {
|
||||
|
||||
}
|
||||
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
|
||||
}
|
||||
}
|
||||
5
com/abit/haxework/gui/layout/ILayout.hx
Executable file
5
com/abit/haxework/gui/layout/ILayout.hx
Executable file
@@ -0,0 +1,5 @@
|
||||
package com.abit.haxework.gui.layout;
|
||||
|
||||
interface ILayout {
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void;
|
||||
}
|
||||
Reference in New Issue
Block a user