From 79ae986e9191cbf705e603a98235b31627bed0d6 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 13 Nov 2013 17:41:26 +0400 Subject: [PATCH] added frameswicther --- haxework/frame/FrameSwitcher.hx | 39 ++++++++++++++++++++++++++++++++ haxework/frame/IFrameSwitcher.hx | 8 +++++++ haxework/gui/GroupView.hx | 2 ++ haxework/gui/GuiBuilder.hx | 2 ++ 4 files changed, 51 insertions(+) create mode 100755 haxework/frame/FrameSwitcher.hx create mode 100755 haxework/frame/IFrameSwitcher.hx diff --git a/haxework/frame/FrameSwitcher.hx b/haxework/frame/FrameSwitcher.hx new file mode 100755 index 0000000..9519ce3 --- /dev/null +++ b/haxework/frame/FrameSwitcher.hx @@ -0,0 +1,39 @@ +package haxework.frame; + +import flash.display.Sprite; +import haxework.gui.IView; +import haxework.gui.GroupView; + +class FrameSwitcher extends GroupView implements IFrameSwitcher { + + public var current(default, null):Null>; + private var frames:Map>; + + public function new() { + super(); + frames = new Map>(); + current = null; + } + + public function change(id:String):IView { + if (current != null) { + if (current.id == id) return current; + removeView(current); + } + current = frames.get(id); + addView(current); + return current; + } + + override public function set_views(value:Array>):Array> { + views = []; + if (value.length > 0) { + for (view in value) { + view.pWidth = 100; + view.pHeight = 100; + frames.set(view.id, view); + } + } + return value; + } +} \ No newline at end of file diff --git a/haxework/frame/IFrameSwitcher.hx b/haxework/frame/IFrameSwitcher.hx new file mode 100755 index 0000000..f6a6b1f --- /dev/null +++ b/haxework/frame/IFrameSwitcher.hx @@ -0,0 +1,8 @@ +package haxework.frame; + +import haxework.gui.IView; + +interface IFrameSwitcher extends IView { + public var current(default, null):Null>; + public function change(id:String):IView; +} \ No newline at end of file diff --git a/haxework/gui/GroupView.hx b/haxework/gui/GroupView.hx index bd4902b..238b389 100755 --- a/haxework/gui/GroupView.hx +++ b/haxework/gui/GroupView.hx @@ -51,6 +51,7 @@ class GroupView extends View implements IGroupView { viewsById.set(view.id, view); content.addChild(view.content); view.parent = this; + invalidate(); return view; } @@ -59,6 +60,7 @@ class GroupView extends View implements IGroupView { viewsById.remove(view.id); views.remove(view); content.removeChild(view.content); + invalidate(); return view; } diff --git a/haxework/gui/GuiBuilder.hx b/haxework/gui/GuiBuilder.hx index 42cc3a8..a8f6cf4 100755 --- a/haxework/gui/GuiBuilder.hx +++ b/haxework/gui/GuiBuilder.hx @@ -12,6 +12,8 @@ import haxework.gui.ButtonView; import haxework.gui.skin.ColorSkin; import haxework.gui.skin.ButtonColorSkin; +import haxework.frame.FrameSwitcher; + class GuiBuilder { private function new() {}