view type removed
This commit is contained in:
11
haxework/animate/CircleMaskAnimate.hx
Normal file → Executable file
11
haxework/animate/CircleMaskAnimate.hx
Normal file → Executable file
@@ -1,5 +1,6 @@
|
||||
package haxework.animate;
|
||||
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import haxework.animate.IAnimate;
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.IView;
|
||||
@@ -7,12 +8,12 @@ import haxework.animate.Animate;
|
||||
|
||||
class CircleMaskAnimate extends Animate {
|
||||
|
||||
private var view:IView<Sprite>;
|
||||
private var view:IView;
|
||||
private var mask:Sprite;
|
||||
private var cyrcle:Sprite;
|
||||
private var size:Float;
|
||||
|
||||
public function new(view:IView<Sprite>, ?duration:Int = 1000) {
|
||||
public function new(view:IView, ?duration:Int = 1000) {
|
||||
super(duration);
|
||||
this.view = view;
|
||||
this.mask = new Sprite();
|
||||
@@ -29,9 +30,9 @@ class CircleMaskAnimate extends Animate {
|
||||
|
||||
redraw(size, size);
|
||||
|
||||
view.parent.content.addChild(mask);
|
||||
view.parent.container.addChild(mask);
|
||||
view.content.mask = mask;
|
||||
view.parent.content.addChild(cyrcle);
|
||||
view.parent.container.addChild(cyrcle);
|
||||
|
||||
super.start(callback, custom);
|
||||
}
|
||||
@@ -56,7 +57,7 @@ class CircleMaskAnimate extends Animate {
|
||||
if (progress >= 1 && view.content.parent != null) {
|
||||
if (view.content.parent.contains(mask)) view.content.parent.removeChild(mask);
|
||||
view.content.mask = null;
|
||||
if (view.content.parent.contains(cyrcle)) view.parent.content.removeChild(cyrcle);
|
||||
if (view.content.parent.contains(cyrcle)) view.parent.container.removeChild(cyrcle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
haxework/animate/FadeAnimate.hx
Normal file → Executable file
4
haxework/animate/FadeAnimate.hx
Normal file → Executable file
@@ -7,9 +7,9 @@ import haxework.animate.Animate;
|
||||
|
||||
class FadeAnimate extends Animate {
|
||||
|
||||
private var view:IView<Sprite>;
|
||||
private var view:IView;
|
||||
|
||||
public function new(view:IView<Sprite>, ?duration = 500) {
|
||||
public function new(view:IView, ?duration = 500) {
|
||||
super(duration);
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
4
haxework/animate/UnFadeAnimate.hx
Normal file → Executable file
4
haxework/animate/UnFadeAnimate.hx
Normal file → Executable file
@@ -6,9 +6,9 @@ import haxework.animate.Animate;
|
||||
|
||||
class UnFadeAnimate extends Animate {
|
||||
|
||||
private var view:IView<Sprite>;
|
||||
private var view:IView;
|
||||
|
||||
public function new(view:IView<Sprite>, ?duration = 500) {
|
||||
public function new(view:IView, ?duration = 500) {
|
||||
super(duration);
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class AnimateView extends SpriteView {
|
||||
frames = [];
|
||||
frame = 0;
|
||||
interval = 200;
|
||||
content.addChild(bitmap);
|
||||
contentAsSprite.addChild(bitmap);
|
||||
changeFrame();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ class ButtonView extends LabelView {
|
||||
downed = false;
|
||||
state = ButtonState.UP;
|
||||
dispatcher = new Dispatcher<ButtonViewListener<Dynamic>>();
|
||||
content.buttonMode = true;
|
||||
content.mouseChildren = false;
|
||||
contentAsSprite.buttonMode = true;
|
||||
contentAsSprite.mouseChildren = false;
|
||||
#if js
|
||||
content.addEventListener(MouseEvent.MOUSE_UP, onMouseClick);
|
||||
#else
|
||||
@@ -81,7 +81,7 @@ class ButtonView extends LabelView {
|
||||
private function set_disabled(value:Bool):Bool {
|
||||
if (disabled != value) {
|
||||
disabled = value;
|
||||
content.buttonMode = !disabled;
|
||||
contentAsSprite.buttonMode = !disabled;
|
||||
invalidate();
|
||||
}
|
||||
return disabled;
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.layout.DefaultLayout;
|
||||
import haxework.gui.layout.ILayout;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
class GroupView extends SpriteView implements IGroupView {
|
||||
public var container(get, null):DisplayObjectContainer;
|
||||
|
||||
public var views(default, set):Array<IView<Dynamic>>;
|
||||
public var views(default, set):Array<IView>;
|
||||
public var layout(default, default):ILayout;
|
||||
|
||||
public var layoutVAlign(default, set):VAlign;
|
||||
@@ -21,7 +23,7 @@ class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
public var bottomPadding(default, set):Float;
|
||||
public var paddings(null, set):Float;
|
||||
|
||||
private var viewsById:Map<String, IView<Dynamic>>;
|
||||
private var viewsById:Map<String, IView>;
|
||||
|
||||
public function new(?layout:ILayout) {
|
||||
super();
|
||||
@@ -31,7 +33,11 @@ class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
layoutHAlign = HAlign.CENTER;
|
||||
layoutVAlign = VAlign.MIDDLE;
|
||||
views = [];
|
||||
viewsById = new Map<String, IView<Sprite>>();
|
||||
viewsById = new Map<String, IView>();
|
||||
}
|
||||
|
||||
inline private function get_container():DisplayObjectContainer {
|
||||
return contentAsSprite;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
@@ -39,51 +45,51 @@ class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
for (view in views) {
|
||||
view.update();
|
||||
if (view.index > -1) {
|
||||
content.setChildIndex(view.content, view.index);
|
||||
contentAsSprite.setChildIndex(view.content, view.index);
|
||||
}
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
|
||||
public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
public function set_views(value:Array<IView>):Array<IView> {
|
||||
if (views == null) views = [];
|
||||
for (view in value) addView(view);
|
||||
return views;
|
||||
}
|
||||
|
||||
public function addView(view:IView<Dynamic>):IView<Dynamic> {
|
||||
public function addView(view:IView):IView {
|
||||
views.push(view);
|
||||
viewsById.set(view.id, view);
|
||||
if (view.content != null) content.addChild(view.content);
|
||||
if (view.content != null) contentAsSprite.addChild(view.content);
|
||||
view.parent = this;
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function insertView(view:IView<Dynamic>, index:Int):IView<Dynamic> {
|
||||
public function insertView(view:IView, index:Int):IView {
|
||||
if (index < 0) index = views.length + index;
|
||||
views.insert(index, view);
|
||||
viewsById.set(view.id, view);
|
||||
if (view.content != null) content.addChild(view.content);
|
||||
if (view.content != null) contentAsSprite.addChild(view.content);
|
||||
view.parent = this;
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic> {
|
||||
public function addViewFirst(view:IView):IView {
|
||||
views.unshift(view);
|
||||
viewsById.set(view.id, view);
|
||||
content.addChild(view.content);
|
||||
contentAsSprite.addChild(view.content);
|
||||
view.parent = this;
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
|
||||
public function removeView(view:IView<Dynamic>):IView<Dynamic> {
|
||||
public function removeView(view:IView):IView {
|
||||
view.parent = null;
|
||||
viewsById.remove(view.id);
|
||||
views.remove(view);
|
||||
if (view.content != null) content.removeChild(view.content);
|
||||
if (view.content != null) contentAsSprite.removeChild(view.content);
|
||||
invalidate();
|
||||
return view;
|
||||
}
|
||||
@@ -94,7 +100,7 @@ class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
}
|
||||
}
|
||||
|
||||
public function removeViewById(id:String):IView<Dynamic> {
|
||||
public function removeViewById(id:String):IView {
|
||||
if (viewsById.exists(id)) {
|
||||
return removeView(viewsById.get(id));
|
||||
} else {
|
||||
@@ -102,7 +108,7 @@ class GroupView extends SpriteView implements IGroupView<Sprite> {
|
||||
}
|
||||
}
|
||||
|
||||
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V> {
|
||||
public function findViewById<V:IView>(id:String, ?clazz:Class<V>):Null<V> {
|
||||
var idd:Array<String> = id.split(":");
|
||||
if (idd.length > 1) {
|
||||
var id0 = idd.shift();
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package haxework.gui;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.layout.ILayout;
|
||||
|
||||
interface IGroupView<C:Content> extends IView<C> extends HasPaddings {
|
||||
interface IGroupView extends IView extends HasPaddings {
|
||||
public var container(get, null):DisplayObjectContainer;
|
||||
|
||||
public var views(default, null):Array<IView<Dynamic>>;
|
||||
public var views(default, null):Array<IView>;
|
||||
public var layout(default, default):ILayout;
|
||||
|
||||
public var layoutVAlign(default, set):VAlign;
|
||||
public var layoutHAlign(default, set):HAlign;
|
||||
public var layoutMargin(default, set):Float;
|
||||
|
||||
public function addView(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function insertView(view:IView<Dynamic>, index:Int):IView<Dynamic>;
|
||||
public function removeView(view:IView<Dynamic>):IView<Dynamic>;
|
||||
public function addView(view:IView):IView;
|
||||
public function addViewFirst(view:IView):IView;
|
||||
public function insertView(view:IView, index:Int):IView;
|
||||
public function removeView(view:IView):IView;
|
||||
public function removeAllViews():Void;
|
||||
public function removeViewById(id:String):IView<Dynamic>;
|
||||
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V>;
|
||||
public function removeViewById(id:String):IView;
|
||||
public function findViewById<V:IView>(id:String, ?clazz:Class<V>):Null<V>;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.text.TextField;
|
||||
import haxework.gui.IView.Content;
|
||||
import flash.text.TextFormatAlign;
|
||||
|
||||
interface ITextView<C:Content, T> extends IView<C> extends HasPaddings {
|
||||
public var textField(default, null):T;
|
||||
interface ITextView extends IView extends HasPaddings {
|
||||
public var textField(default, null):TextField;
|
||||
public var text(get, set):String;
|
||||
public var align(default, set):TextFormatAlign;
|
||||
//ToDo: font properties to object
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import haxework.gui.core.VAlign;
|
||||
import haxework.gui.core.HAlign;
|
||||
import haxework.gui.skin.ISkin;
|
||||
import haxework.gui.core.SizeType;
|
||||
|
||||
typedef Content = {
|
||||
#if flash
|
||||
var x(default,default):Float;
|
||||
var y(default,default):Float;
|
||||
var visible(default,default):Bool;
|
||||
var alpha(default,default):Float;
|
||||
@:optional var mouseEnabled(default,default):Bool;
|
||||
#else
|
||||
var x(get,set):Float;
|
||||
var y(get,set):Float;
|
||||
var visible(get,set):Bool;
|
||||
var alpha(get,set):Float;
|
||||
@:optional var mouseEnabled(default,default):Bool;
|
||||
#end
|
||||
}
|
||||
|
||||
interface IView<C:Content> {
|
||||
interface IView {
|
||||
public var id(default, default):String;
|
||||
|
||||
public var x(default, set):Float;
|
||||
@@ -52,10 +37,10 @@ interface IView<C:Content> {
|
||||
public var bottomMargin(default, set):Float;
|
||||
public var margins(null, set):Float;
|
||||
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):ISkin<C, IView<C>>;
|
||||
public var content(default, null):DisplayObject;
|
||||
public var skin(default, set):ISkin<Dynamic>;
|
||||
|
||||
public var parent(default, null):Null<IGroupView<Dynamic>>;
|
||||
public var parent(default, null):Null<IGroupView>;
|
||||
public var inLayout(default, set):Bool;
|
||||
|
||||
public var visible(default, set):Bool;
|
||||
|
||||
@@ -28,7 +28,7 @@ class InputView extends TextView implements IDisposable {
|
||||
textField.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
|
||||
|
||||
hintTextField = buildHintTextField();
|
||||
content.addChild(hintTextField);
|
||||
contentAsSprite.addChild(hintTextField);
|
||||
}
|
||||
|
||||
override private function buildTextField():TextField {
|
||||
|
||||
@@ -4,7 +4,7 @@ import haxework.net.SwfLoader;
|
||||
import flash.display.MovieClip;
|
||||
|
||||
//ToDo: sprite wrapper?
|
||||
class MovieView extends View<MovieClip> {
|
||||
class MovieView extends View {
|
||||
|
||||
public var movie(get, set):MovieClip;
|
||||
public var movieUrl(default, set):String;
|
||||
@@ -14,22 +14,22 @@ class MovieView extends View<MovieClip> {
|
||||
}
|
||||
|
||||
private function get_movie():MovieClip {
|
||||
return content;
|
||||
return cast content;
|
||||
}
|
||||
|
||||
private function set_movie(value:MovieClip):MovieClip {
|
||||
var index:Int = 0;
|
||||
if (parent != null && content != null) {
|
||||
index = parent.content.getChildIndex(content);
|
||||
parent.content.removeChild(content);
|
||||
index = parent.container.getChildIndex(content);
|
||||
parent.container.removeChild(content);
|
||||
}
|
||||
content = value;
|
||||
content.visible = visible;
|
||||
if (parent != null) {
|
||||
parent.content.addChildAt(content, index);
|
||||
parent.container.addChildAt(content, index);
|
||||
}
|
||||
invalidate();
|
||||
return content;
|
||||
return cast content;
|
||||
}
|
||||
|
||||
private function set_movieUrl(value:String):String {
|
||||
|
||||
@@ -12,10 +12,10 @@ class Root {
|
||||
|
||||
public static var instance(default, null):Root;
|
||||
|
||||
public var view(default, null):IView<Sprite>;
|
||||
public var view(default, null):IView;
|
||||
public var autoSize(default, default):Bool;
|
||||
|
||||
public function new(view:IView<Sprite>, autoSize:Bool = true) {
|
||||
public function new(view:IView, autoSize:Bool = true) {
|
||||
if (instance != null) throw new Error("Only one instance");
|
||||
instance = this;
|
||||
this.view = view;
|
||||
|
||||
@@ -3,12 +3,18 @@ package haxework.gui;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class SpriteView extends View<Sprite> {
|
||||
class SpriteView extends View {
|
||||
|
||||
public var contentAsSprite(get, null):Sprite;
|
||||
|
||||
public function new() {
|
||||
super(new Sprite());
|
||||
}
|
||||
|
||||
inline private function get_contentAsSprite():Sprite {
|
||||
return cast content;
|
||||
}
|
||||
|
||||
#if dev_layout
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
|
||||
@@ -12,7 +12,7 @@ import flash.text.TextFormat;
|
||||
import flash.display.Sprite;
|
||||
import flash.text.TextField;
|
||||
|
||||
class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
||||
class TextView extends SpriteView implements ITextView {
|
||||
|
||||
public var textField(default, null):TextField;
|
||||
public var text(get, set):String;
|
||||
@@ -60,7 +60,7 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
||||
textFormat.size = 16;
|
||||
textFormat.leading = 0;
|
||||
textFormat.align = TextFormatAlign.CENTER;
|
||||
content.addChild(textField);
|
||||
contentAsSprite.addChild(textField);
|
||||
}
|
||||
|
||||
private function buildTextField():TextField {
|
||||
|
||||
@@ -6,7 +6,7 @@ import haxework.gui.skin.ISkin;
|
||||
class ToggleButtonView extends ButtonView {
|
||||
|
||||
public var on(default, set):Bool;
|
||||
public var onSkin(default, set):ISkin<Sprite, IView<Sprite>>;
|
||||
public var onSkin(default, set):ISkin<Dynamic>;
|
||||
|
||||
public var onText(default, set):String;
|
||||
|
||||
@@ -20,13 +20,13 @@ class ToggleButtonView extends ButtonView {
|
||||
return on;
|
||||
}
|
||||
|
||||
private function set_onSkin(value:ISkin<Sprite, IView<Sprite>>):ISkin<Sprite, IView<Sprite>> {
|
||||
private function set_onSkin(value:ISkin<Dynamic>):ISkin<Dynamic> {
|
||||
onSkin = value;
|
||||
invalidate();
|
||||
return onSkin;
|
||||
}
|
||||
|
||||
override private function currentSkin():ISkin<Sprite, IView<Sprite>> {
|
||||
override private function currentSkin():ISkin<Dynamic> {
|
||||
return on ? onSkin : skin;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package haxework.gui;
|
||||
|
||||
import flash.display.InteractiveObject;
|
||||
import flash.display.DisplayObject;
|
||||
import flash.errors.Error;
|
||||
import haxework.gui.IView.Content;
|
||||
import haxework.gui.skin.ISize;
|
||||
import haxework.gui.core.SizeType;
|
||||
import haxework.gui.core.HAlign;
|
||||
@@ -13,7 +14,7 @@ import haxework.gui.skin.ISkin;
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
class View<C:Content> implements IView<C> {
|
||||
class View implements IView {
|
||||
|
||||
private static var counter:Int = 0;
|
||||
public static var updater(default, null):Updater = new Updater();
|
||||
@@ -48,17 +49,17 @@ class View<C:Content> implements IView<C> {
|
||||
public var bottomMargin(default, set):Float;
|
||||
public var margins(null, set):Float;
|
||||
|
||||
public var content(default, null):C;
|
||||
public var skin(default, set):ISkin<C, IView<C>>;
|
||||
public var content(default, null):DisplayObject;
|
||||
public var skin(default, set):ISkin<Dynamic>;
|
||||
|
||||
public var parent(default, null):Null<IGroupView<Dynamic>>;
|
||||
public var parent(default, null):Null<IGroupView>;
|
||||
public var inLayout(default, set):Bool;
|
||||
|
||||
public var visible(default, set):Bool;
|
||||
public var index(default, set):Int;
|
||||
public var mouseEnabled(default, set):Bool = true;
|
||||
|
||||
public function new(content:C) {
|
||||
public function new(content:DisplayObject) {
|
||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||
this.content = content;
|
||||
x = 0;
|
||||
@@ -73,7 +74,7 @@ class View<C:Content> implements IView<C> {
|
||||
index = -1;
|
||||
}
|
||||
|
||||
private function currentSkin():ISkin<C, IView<C>> {
|
||||
private function currentSkin():ISkin<Dynamic> {
|
||||
return skin;
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ class View<C:Content> implements IView<C> {
|
||||
content.x = x;
|
||||
content.y = y;
|
||||
}
|
||||
var skin:ISkin<C, IView<C>> = currentSkin();
|
||||
var skin:ISkin<Dynamic> = currentSkin();
|
||||
if (contentSize && skin != null && Std.is(skin, ISize)) {
|
||||
var size:ISize = cast(skin, ISize);
|
||||
if (!Math.isNaN(size.width)) width = size.width;
|
||||
@@ -263,7 +264,7 @@ class View<C:Content> implements IView<C> {
|
||||
return value;
|
||||
}
|
||||
|
||||
private function set_skin(value:ISkin<C, IView<C>>):ISkin<C, IView<C>> {
|
||||
private function set_skin(value:ISkin<Dynamic>):ISkin<Dynamic> {
|
||||
skin = value;
|
||||
invalidate();
|
||||
return skin;
|
||||
@@ -296,7 +297,9 @@ class View<C:Content> implements IView<C> {
|
||||
private function set_mouseEnabled(value:Bool):Bool {
|
||||
if (mouseEnabled != value) {
|
||||
mouseEnabled = value;
|
||||
if (content != null) content.mouseEnabled = mouseEnabled;
|
||||
if (content != null && Std.is(content, InteractiveObject)) {
|
||||
cast(content, InteractiveObject).mouseEnabled = mouseEnabled;
|
||||
}
|
||||
}
|
||||
return mouseEnabled;
|
||||
}
|
||||
@@ -306,7 +309,7 @@ class View<C:Content> implements IView<C> {
|
||||
class Updater {
|
||||
|
||||
public var stage(null, set):Stage;
|
||||
private var invalidated:Array<IView<Dynamic>>;
|
||||
private var invalidated:Array<Dynamic>;
|
||||
|
||||
public function new() {
|
||||
invalidated = [];
|
||||
@@ -317,7 +320,7 @@ class Updater {
|
||||
return value;
|
||||
}
|
||||
|
||||
public function invalidate(view:IView<Dynamic>):Void {
|
||||
public function invalidate(view:IView):Void {
|
||||
if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view);
|
||||
}
|
||||
|
||||
|
||||
2
haxework/gui/ViewBuilder.hx
Normal file → Executable file
2
haxework/gui/ViewBuilder.hx
Normal file → Executable file
@@ -152,7 +152,7 @@ private class Builder {
|
||||
if (["type", "style"].indexOf(key) > -1) continue;
|
||||
var value = getValue(name, key, Reflect.field(template, key));
|
||||
if (value != null) {
|
||||
exprs.push(Context.parse(name + "." + key + " = cast " + value, getPosition()));
|
||||
exprs.push(Context.parse(name + "." + key + " = " + value, getPosition()));
|
||||
}
|
||||
}
|
||||
return name;
|
||||
|
||||
@@ -5,28 +5,28 @@ import flash.display.Sprite;
|
||||
import haxework.gui.IView;
|
||||
import haxework.gui.GroupView;
|
||||
|
||||
class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
||||
class FrameSwitcher extends GroupView implements IFrameSwitcher {
|
||||
|
||||
public var current(default, null):Null<IView<Dynamic>>;
|
||||
private var frames:Map<String, IView<Dynamic>>;
|
||||
public var current(default, null):Null<IView>;
|
||||
private var frames:Map<String, IView>;
|
||||
|
||||
public var animateFactory(default, default):Class<IAnimate>;
|
||||
private var animate:IAnimate;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
frames = new Map<String, IView<Dynamic>>();
|
||||
frames = new Map<String, IView>();
|
||||
current = null;
|
||||
}
|
||||
|
||||
private function buildAnimate(view:IView<Dynamic>):Null<IAnimate> {
|
||||
private function buildAnimate(view:IView):Null<IAnimate> {
|
||||
if (animateFactory != null) {
|
||||
return Type.createInstance(animateFactory, [view]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function change(id:String):IView<Dynamic> {
|
||||
public function change(id:String):IView {
|
||||
var prev = null;
|
||||
if (current != null) {
|
||||
if (current.id == id) return current;
|
||||
@@ -34,7 +34,8 @@ class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
||||
}
|
||||
current = frames.get(id);
|
||||
addView(current);
|
||||
if (content.stage != null) content.stage.focus = current.content;
|
||||
//ToDo:
|
||||
if (content.stage != null) content.stage.focus = cast(current, SpriteView).contentAsSprite;
|
||||
var onShowMethod:Dynamic = Reflect.field(current, "onShow");
|
||||
if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []);
|
||||
if (animate != null) animate.cancel();
|
||||
@@ -49,7 +50,7 @@ class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
||||
return current;
|
||||
}
|
||||
|
||||
private function removePrev(prev:Null<IView<Dynamic>>):Void {
|
||||
private function removePrev(prev:Null<IView>):Void {
|
||||
if (prev != null) {
|
||||
var onHideMethod:Dynamic = Reflect.field(prev, "onHide");
|
||||
if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []);
|
||||
@@ -57,7 +58,7 @@ class FrameSwitcher extends GroupView implements IFrameSwitcher<Sprite> {
|
||||
}
|
||||
}
|
||||
|
||||
override public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
override public function set_views(value:Array<IView>):Array<IView> {
|
||||
views = [];
|
||||
if (value.length > 0) {
|
||||
for (view in value) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package haxework.gui.frame;
|
||||
|
||||
import haxework.gui.IView;
|
||||
|
||||
interface IFrameSwitcher<C:Content> extends IView<C> {
|
||||
public var current(default, null):Null<IView<Dynamic>>;
|
||||
public function change(id:String):IView<Dynamic>;
|
||||
interface IFrameSwitcher extends IView {
|
||||
public var current(default, null):Null<IView>;
|
||||
public function change(id:String):IView;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class DefaultLayout implements ILayout {
|
||||
|
||||
}
|
||||
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
public function place(group:IGroupView, views:Array<IView>):Void {
|
||||
for (view in views) {
|
||||
setViewWidth(group, view);
|
||||
setViewHeight(group, view);
|
||||
@@ -19,8 +19,8 @@ class DefaultLayout implements ILayout {
|
||||
}
|
||||
}
|
||||
|
||||
private function filterViews(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||
return Lambda.array(Lambda.filter(views, function(view:IView<Dynamic>):Bool {
|
||||
private function filterViews(group:IGroupView, views:Array<IView>):Array<IView> {
|
||||
return Lambda.array(Lambda.filter(views, function(view:IView):Bool {
|
||||
return if (view.inLayout) {
|
||||
true;
|
||||
} else {
|
||||
@@ -33,7 +33,7 @@ class DefaultLayout implements ILayout {
|
||||
}));
|
||||
}
|
||||
|
||||
private function setViewWidth(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
private function setViewWidth(group:IGroupView, view:IView):Void {
|
||||
if (view.widthType == SizeType.PERCENT) {
|
||||
view.w = view.pWidth / 100 * (group.width - view.leftMargin - view.rightMargin - group.leftPadding - group.rightPadding);
|
||||
} else if (group.contentSize && group.width < view.width) {
|
||||
@@ -41,7 +41,7 @@ class DefaultLayout implements ILayout {
|
||||
}
|
||||
}
|
||||
|
||||
private function setViewHeight(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
private function setViewHeight(group:IGroupView, view:IView):Void {
|
||||
if (view.heightType == SizeType.PERCENT) {
|
||||
view.h = view.pHeight / 100 * (group.height - view.topMargin - view.bottomMargin - group.topPadding - group.bottomPadding);
|
||||
} else if (group.contentSize && group.height < view.height) {
|
||||
@@ -49,7 +49,7 @@ class DefaultLayout implements ILayout {
|
||||
}
|
||||
}
|
||||
|
||||
private function placeViewHorizontal(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
private function placeViewHorizontal(group:IGroupView, view:IView):Void {
|
||||
var align:HAlign = view.hAlign;
|
||||
if (align == HAlign.NONE) align = group.layoutHAlign;
|
||||
switch (align) {
|
||||
@@ -63,7 +63,7 @@ class DefaultLayout implements ILayout {
|
||||
}
|
||||
}
|
||||
|
||||
private function placeViewVertical(group:IGroupView<Dynamic>, view:IView<Dynamic>):Void {
|
||||
private function placeViewVertical(group:IGroupView, view:IView):Void {
|
||||
var align:VAlign = view.vAlign;
|
||||
if (align == VAlign.NONE) align = group.layoutVAlign;
|
||||
switch (align) {
|
||||
|
||||
@@ -10,7 +10,7 @@ class HorizontalLayout extends DefaultLayout {
|
||||
super();
|
||||
}
|
||||
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
override public function place(group:IGroupView, views:Array<IView>):Void {
|
||||
views = filterViews(group, views);
|
||||
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package haxework.gui.layout;
|
||||
|
||||
interface ILayout {
|
||||
public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void;
|
||||
public function place(group:IGroupView, views:Array<IView>):Void;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class VerticalLayout extends DefaultLayout {
|
||||
super();
|
||||
}
|
||||
|
||||
override public function place(group:IGroupView<Dynamic>, views:Array<IView<Dynamic>>):Void {
|
||||
override public function place(group:IGroupView, views:Array<IView>):Void {
|
||||
views = filterViews(group, views);
|
||||
|
||||
var fixedSize:Float = group.layoutMargin * (views.length - 1);
|
||||
|
||||
@@ -11,20 +11,19 @@ class HListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new HorizontalLayout(), new VerticalLayout());
|
||||
container.layoutHAlign = HAlign.LEFT;
|
||||
container.layoutVAlign = VAlign.MIDDLE;
|
||||
box.layoutHAlign = HAlign.LEFT;
|
||||
box.layoutVAlign = VAlign.MIDDLE;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var view:IView<Dynamic> = item;
|
||||
itemSize = view.width + view.leftMargin + view.rightMargin + container.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, container.width / itemSize)) + 2;
|
||||
sizeDiff = size - ((container.width - container.layoutMargin - 1) / itemSize);
|
||||
itemSize = item.width + item.leftMargin + item.rightMargin + box.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, box.width / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.width - box.layoutMargin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
container.leftPadding = -value * itemSize;
|
||||
mask.leftMargin = -container.leftPadding;
|
||||
box.leftPadding = -value * itemSize;
|
||||
mask.leftMargin = -box.leftPadding;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import haxework.gui.skin.ISkin;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
|
||||
class HScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
class HScrollSkin implements ISkin<ScrollView> {
|
||||
|
||||
public var foreColor(default, default):Int;
|
||||
public var backColor(default, default):Int;
|
||||
@@ -15,7 +15,7 @@ class HScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
}
|
||||
|
||||
public function draw(view:ScrollView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
|
||||
@@ -35,7 +35,7 @@ class ListView<D> extends GroupView implements ScrollListener {
|
||||
public var selected(default, set):Array<D>;
|
||||
|
||||
private var main:GroupView;
|
||||
private var container:GroupView;
|
||||
private var box:GroupView;
|
||||
private var mask:SpriteView;
|
||||
private var itemSize:Float;
|
||||
|
||||
@@ -50,17 +50,17 @@ class ListView<D> extends GroupView implements ScrollListener {
|
||||
main.pWidth = 100;
|
||||
main.pHeight = 100;
|
||||
addView(main);
|
||||
container = new GroupView(layout);
|
||||
container.pWidth = 100;
|
||||
container.pHeight = 100;
|
||||
main.addView(container);
|
||||
box = new GroupView(layout);
|
||||
box.pWidth = 100;
|
||||
box.pHeight = 100;
|
||||
main.addView(box);
|
||||
mask = new SpriteView();
|
||||
mask.pWidth = 100;
|
||||
mask.pHeight = 100;
|
||||
mask.inLayout = false;
|
||||
mask.skin = new ColorSkin(0xffffff);
|
||||
container.content.mask = mask.content;
|
||||
container.addView(mask);
|
||||
box.content.mask = mask.content;
|
||||
box.addView(mask);
|
||||
dispatcher = new Dispatcher<ListViewListener<D>>();
|
||||
itemSize = 0;
|
||||
offset = 0;
|
||||
@@ -202,14 +202,14 @@ class ListView<D> extends GroupView implements ScrollListener {
|
||||
var item:IListItemView<D> = Type.createInstance(factory, []);
|
||||
items.push(item);
|
||||
setClickListener(item);
|
||||
container.addView(item);
|
||||
box.addView(item);
|
||||
}
|
||||
} else if (diff < 0) {
|
||||
for (i in 0...-diff) {
|
||||
var item:IListItemView<D> = items.pop();
|
||||
item.content.removeEventListener(MouseEvent.CLICK, itemsListeners.get(item));
|
||||
itemsListeners.remove(item);
|
||||
container.removeView(item);
|
||||
box.removeView(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,11 +232,11 @@ class ListView<D> extends GroupView implements ScrollListener {
|
||||
}
|
||||
|
||||
override private function set_layoutMargin(value:Float):Float {
|
||||
return container.layoutMargin = value;
|
||||
return box.layoutMargin = value;
|
||||
}
|
||||
}
|
||||
|
||||
interface IListItemView<D> extends IView<Sprite> {
|
||||
interface IListItemView<D> extends IView {
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):D;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class ScrollView extends SpriteView {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
content.buttonMode = true;
|
||||
contentAsSprite.buttonMode = true;
|
||||
position = 0;
|
||||
ratio = 1;
|
||||
dispatcher = new Dispatcher<ScrollListener>();
|
||||
|
||||
@@ -11,20 +11,19 @@ class VListView<D> extends ListView<D> {
|
||||
|
||||
public function new() {
|
||||
super(new VerticalLayout(), new HorizontalLayout());
|
||||
container.layoutHAlign = HAlign.CENTER;
|
||||
container.layoutVAlign = VAlign.TOP;
|
||||
box.layoutHAlign = HAlign.CENTER;
|
||||
box.layoutVAlign = VAlign.TOP;
|
||||
}
|
||||
|
||||
override private function recalcSize(item:IListItemView<D>):Void {
|
||||
var view:IView<Dynamic> = item;
|
||||
itemSize = view.height + view.topMargin + view.bottomMargin + container.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, container.height / itemSize)) + 2;
|
||||
sizeDiff = size - ((container.height - container.layoutMargin - 1) / itemSize);
|
||||
itemSize = item.height + item.topMargin + item.bottomMargin + box.layoutMargin;
|
||||
size = Math.ceil(Math.max(0, box.height / itemSize)) + 2;
|
||||
sizeDiff = size - ((box.height - box.layoutMargin - 1) / itemSize);
|
||||
}
|
||||
|
||||
override private function set_offsetDiff(value:Float):Float {
|
||||
container.topPadding = -value * itemSize;
|
||||
mask.topMargin = -container.topPadding;
|
||||
box.topPadding = -value * itemSize;
|
||||
mask.topMargin = -box.topPadding;
|
||||
return super.set_offsetDiff(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import haxework.gui.skin.ISkin;
|
||||
import flash.display.Sprite;
|
||||
import flash.display.Graphics;
|
||||
|
||||
class VScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
class VScrollSkin implements ISkin<ScrollView> {
|
||||
|
||||
public var foreColor(default, default):Int;
|
||||
public var backColor(default, default):Int;
|
||||
@@ -15,7 +15,7 @@ class VScrollSkin implements ISkin<Sprite, ScrollView> {
|
||||
}
|
||||
|
||||
public function draw(view:ScrollView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
|
||||
6
haxework/gui/popup/PopupManager.hx
Normal file → Executable file
6
haxework/gui/popup/PopupManager.hx
Normal file → Executable file
@@ -16,7 +16,7 @@ class PopupManager {
|
||||
}
|
||||
|
||||
public function show(popup:PopupView<Dynamic>):Void {
|
||||
cast(Root.instance.view, IGroupView<Dynamic>).addView(popup);
|
||||
cast(Root.instance.view, IGroupView).addView(popup);
|
||||
if (showAnimateFactory != null) {
|
||||
Type.createInstance(showAnimateFactory, [popup]).start(null);
|
||||
}
|
||||
@@ -28,11 +28,11 @@ class PopupManager {
|
||||
popups.remove(popup);
|
||||
if (closeAnimateFactory != null) {
|
||||
Type.createInstance(closeAnimateFactory, [popup]).start(function(_) {
|
||||
cast(Root.instance.view, IGroupView<Dynamic>).removeView(popup);
|
||||
cast(Root.instance.view, IGroupView).removeView(popup);
|
||||
popup.onClose();
|
||||
});
|
||||
} else {
|
||||
cast(Root.instance.view, IGroupView<Dynamic>).removeView(popup);
|
||||
cast(Root.instance.view, IGroupView).removeView(popup);
|
||||
popup.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import haxework.gui.ButtonView;
|
||||
import haxework.gui.skin.ColorSkin;
|
||||
import haxework.gui.GroupView;
|
||||
|
||||
class PopupView<V:IView<Dynamic>> extends GroupView {
|
||||
class PopupView<V:IView> extends GroupView {
|
||||
|
||||
private var buttonId:String;
|
||||
private var contentView:V;
|
||||
|
||||
@@ -9,7 +9,7 @@ import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class BitmapSkin implements ISkin<Sprite, SpriteView> implements ISize {
|
||||
class BitmapSkin implements ISkin<SpriteView> implements ISize {
|
||||
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
@@ -37,7 +37,7 @@ class BitmapSkin implements ISkin<Sprite, SpriteView> implements ISize {
|
||||
|
||||
public function draw(view:SpriteView):Void {
|
||||
if (image == null) return;
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
DrawUtil.draw(view.contentAsSprite.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ButtonBitmapSkin implements ISkin<Sprite, ButtonView> implements ISize {
|
||||
class ButtonBitmapSkin implements ISkin<ButtonView> implements ISize {
|
||||
|
||||
public var width(default, null):Float;
|
||||
public var height(default, null):Float;
|
||||
@@ -64,7 +64,7 @@ class ButtonBitmapSkin implements ISkin<Sprite, ButtonView> implements ISize {
|
||||
public function draw(view:ButtonView):Void {
|
||||
if (images == null) return;
|
||||
var image:BitmapData = view.disabled ? disableImage == null ? disable : disableImage : images.get(view.state);
|
||||
DrawUtil.draw(view.content.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
DrawUtil.draw(view.contentAsSprite.graphics, image, new Rectangle(0, 0, view.width, view.height), fillType, color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import haxework.gui.ButtonView.ButtonState;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ButtonColorSkin implements ISkin<Sprite, ButtonView> {
|
||||
class ButtonColorSkin implements ISkin<ButtonView> {
|
||||
|
||||
public var color(default, set_color):Int;
|
||||
public var alpha(default, default):Float;
|
||||
@@ -28,7 +28,7 @@ class ButtonColorSkin implements ISkin<Sprite, ButtonView> {
|
||||
|
||||
public function draw(view:ButtonView):Void {
|
||||
var color:Int = selectColor(view);
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(color, alpha);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
|
||||
@@ -3,7 +3,7 @@ package haxework.gui.skin;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class ColorSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
class ColorSkin implements ISkin<SpriteView> {
|
||||
|
||||
public var color(default, default):Int;
|
||||
public var alpha(default, default):Float;
|
||||
@@ -13,8 +13,8 @@ class ColorSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
public function draw(view:SpriteView):Void {
|
||||
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(color, alpha);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
|
||||
@@ -3,11 +3,11 @@ package haxework.gui.skin;
|
||||
import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
|
||||
class FakeSkin implements ISkin<Sprite, IView<Sprite>> {
|
||||
class FakeSkin implements ISkin<IView> {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:IView<Sprite>):Void {
|
||||
public function draw(view:IView):Void {
|
||||
/*var g:Graphics = view.content.graphics;
|
||||
g.clear();
|
||||
g.lineStyle(1, 0x00ff00);
|
||||
|
||||
@@ -2,6 +2,6 @@ package haxework.gui.skin;
|
||||
|
||||
import haxework.gui.IView.Content;
|
||||
|
||||
interface ISkin<C:Content, V:IView<C>> {
|
||||
interface ISkin<V:IView> {
|
||||
public function draw(view:V):Void;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import flash.display.Graphics;
|
||||
import flash.display.Sprite;
|
||||
import haxework.gui.skin.ISkin;
|
||||
|
||||
class ProgressSkin implements ISkin<Sprite, ProgressView> {
|
||||
class ProgressSkin implements ISkin<ProgressView> {
|
||||
|
||||
public var foreColor:Int;
|
||||
public var backColor:Int;
|
||||
@@ -12,7 +12,7 @@ class ProgressSkin implements ISkin<Sprite, ProgressView> {
|
||||
public function new() {}
|
||||
|
||||
public function draw(view:ProgressView):Void {
|
||||
var graphics:Graphics = view.content.graphics;
|
||||
var graphics:Graphics = view.contentAsSprite.graphics;
|
||||
graphics.clear();
|
||||
graphics.beginFill(backColor);
|
||||
graphics.drawRect(0, 0, view.width, view.height);
|
||||
|
||||
Reference in New Issue
Block a user