From d4aeffb8a6fd97726170feb0f2fbbc612d3218f9 Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 27 Feb 2019 11:49:55 +0300 Subject: [PATCH] [demo] update --- demo/src/demo/Demo.hx | 12 +- demo/src/demo/Demo.yaml | 81 ++- demo/src/demo/Style.hx | 45 -- demo/src/demo/Theme.hx | 45 ++ demo/src/demo/form/TailForm.hx | 5 +- src/main/haxework/gui/ButtonView.hx | 158 ++--- src/main/haxework/gui/GroupView.hx | 321 ++++++----- src/main/haxework/gui/HasPaddings.hx | 5 +- src/main/haxework/gui/IView.hx | 3 +- src/main/haxework/gui/LabelView.hx | 19 +- src/main/haxework/gui/SpriteView.hx | 17 +- src/main/haxework/gui/TextView.hx | 439 +++++++------- src/main/haxework/gui/View.hx | 540 +++++++++--------- src/main/haxework/gui/frame/FrameSwitcher.hx | 114 ++-- src/main/haxework/gui/list/LabelListItem.hx | 10 +- src/main/haxework/gui/skin/ButtonColorSkin.hx | 7 +- src/main/haxework/gui/skin/ButtonSkin.hx | 10 - src/main/haxework/gui/skin/Skin.hx | 8 + src/main/haxework/gui/skin/TabColorSkin.hx | 20 + 19 files changed, 992 insertions(+), 867 deletions(-) delete mode 100644 demo/src/demo/Style.hx create mode 100644 demo/src/demo/Theme.hx delete mode 100644 src/main/haxework/gui/skin/ButtonSkin.hx create mode 100644 src/main/haxework/gui/skin/TabColorSkin.hx diff --git a/demo/src/demo/Demo.hx b/demo/src/demo/Demo.hx index 9aa0aa6..0bd0eef 100644 --- a/demo/src/demo/Demo.hx +++ b/demo/src/demo/Demo.hx @@ -1,5 +1,8 @@ package demo; +import haxework.gui.ToggleButtonView; +import haxework.gui.IGroupView; +import haxework.gui.IView; import haxework.resources.Resources; import haxework.resources.IResources; import haxework.gui.frame.IFrameSwitcher; @@ -18,11 +21,16 @@ import haxework.gui.VGroupView; L.push(new TraceLogger()); resources = new Resources(); manager = new LoaderManager(); - Style.register(); + Theme.setColor(0x33aa33); var demo = new Demo(); demo.switcher.change("list_form"); Root.bind(demo); } - @:view public var switcher:IFrameSwitcher; + @:view var switcher:IFrameSwitcher; + @:view var tabs:IGroupView; + + private function onFrameSwicth(frame:IView):Void { + for (view in tabs.views) cast(view, ToggleButtonView).on = view.id == frame.id; + } } diff --git a/demo/src/demo/Demo.yaml b/demo/src/demo/Demo.yaml index e0de12a..aed784e 100644 --- a/demo/src/demo/Demo.yaml +++ b/demo/src/demo/Demo.yaml @@ -3,29 +3,40 @@ pWidth: 100 pHeight: 100 skin: $r:skin:background views: - - $type: haxework.gui.HGroupView + - id: tabs + $type: haxework.gui.HGroupView layoutMargin: 5 layoutHAlign: LEFT leftPadding: 5 pWidth: 100 height: 40 views: - - $type: haxework.gui.ButtonView - skin: $r:skin:button + - id: list_form + $type: haxework.gui.ToggleButtonView + skin: $r:skin:tab contentSize: true - paddings: 8 - text: List Form + paddings: [25, 8] + text: List +onPress: "$code:function(_) switcher.change('list_form')" - - $type: haxework.gui.ButtonView - skin: $r:skin:button + - id: tail_form + $type: haxework.gui.ToggleButtonView + skin: $r:skin:tab contentSize: true - paddings: 8 - text: Tail Form + paddings: [25, 8] + text: Tail +onPress: "$code:function(_) switcher.change('tail_form')" + - id: any_form + $type: haxework.gui.ToggleButtonView + skin: $r:skin:tab + contentSize: true + paddings: [25, 8] + text: Any + +onPress: "$code:function(_) switcher.change('any_form')" - id: switcher $type: haxework.gui.frame.FrameSwitcher - skin: [ $type: [ haxework.gui.skin.Skin.border, 0x33aa33, 1, 2 ] ] - paddings: 5 + skin: $r:skin:border + +onSwitch: $this:onFrameSwicth + padding: 5 pWidth: 100 pHeight: 100 views: @@ -37,3 +48,51 @@ views: $type: demo.form.TailForm pWidth: 100 pHeight: 100 + - id: any_form + $type: haxework.gui.SpriteView + pWidth: 100 + pHeight: 100 + - $type: haxework.gui.HGroupView + layoutMargin: 10 + layoutHAlign: RIGHT + rightPadding: 10 + pWidth: 100 + height: 60 + views: + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: green + +onPress: "$code:function(_) Theme.setColor(0x33aa33)" + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: red + +onPress: "$code:function(_) Theme.setColor(0xaa3333)" + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: yellow + +onPress: "$code:function(_) Theme.setColor(0xaaaa33)" + rightMargin: 30 + + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: OK + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: Apply + - $type: haxework.gui.ButtonView + skin: $r:skin:button + contentSize: true + padding: 8 + text: Cancel + #+onPress: $this:close + +onPress: "$code:function(_) flash.system.System.exit(0)" diff --git a/demo/src/demo/Style.hx b/demo/src/demo/Style.hx deleted file mode 100644 index d8e3d31..0000000 --- a/demo/src/demo/Style.hx +++ /dev/null @@ -1,45 +0,0 @@ -package demo; - -import haxework.gui.list.ScrollBarSkin; -import haxework.resources.IResources; -import haxework.gui.skin.ISkin; -import haxework.gui.skin.ButtonSkin; -import haxework.gui.skin.Skin; -import haxework.gui.skin.TextSkin; - -class Style { - - @:provide static var resources:IResources; - - public static var backColor = 0x33aa33; - public static var textColor = 0xffffff; - public static var borderColor = 0xffffff; - - public static var text:ISkin = new TextSkin(textColor, "Courirer"); - - public static var background:SkinSet = [ - Skin.color(0x00000), - ]; - - public static var button:SkinSet = [ - ButtonSkin.color(backColor), - text, - ]; - - public static var view:SkinSet = [ - Skin.color(backColor), - Skin.border(borderColor), - text, - ]; - - public static var scroll:SkinSet = [ - ScrollBarSkin.vertical(0x55cc55, 0xccffcc), - ]; - - public static function register():Void { - resources.skin.put("background", background); - resources.skin.put("button", button); - resources.skin.put("view", view); - resources.skin.put("scroll", scroll); - } -} diff --git a/demo/src/demo/Theme.hx b/demo/src/demo/Theme.hx new file mode 100644 index 0000000..beb9261 --- /dev/null +++ b/demo/src/demo/Theme.hx @@ -0,0 +1,45 @@ +package demo; + +import haxework.gui.utils.ColorUtils; +import haxework.gui.list.ScrollBarSkin; +import haxework.resources.IResources; +import haxework.gui.skin.ISkin; +import haxework.gui.skin.Skin; +import haxework.gui.skin.TextSkin; + +class Theme { + + @:provide static var resources:IResources; + + public static function setColor(color:Int, textColor:Int = 0xffffff):Void { + var text:ISkin = new TextSkin(textColor, 16, "Courirer"); + var background:SkinSet = [ + Skin.color(0x00000), + ]; + var button:SkinSet = [ + Skin.buttonColor(color), + text, + ]; + var tab:SkinSet = [ + Skin.tabColor(color), + text, + ]; + var view:SkinSet = [ + Skin.color(color), + Skin.border(textColor), + text, + ]; + var scroll:SkinSet = [ + ScrollBarSkin.vertical(color, ColorUtils.diff(color, 128)), + ]; + var border:SkinSet = [ + Skin.border(ColorUtils.multiply(color, 1.5), 1, 2), + ]; + resources.skin.put("background", background); + resources.skin.put("button", button); + resources.skin.put("tab", tab); + resources.skin.put("view", view); + resources.skin.put("scroll", scroll); + resources.skin.put("border", border); + } +} diff --git a/demo/src/demo/form/TailForm.hx b/demo/src/demo/form/TailForm.hx index 5757e8b..ee1b930 100644 --- a/demo/src/demo/form/TailForm.hx +++ b/demo/src/demo/form/TailForm.hx @@ -1,5 +1,6 @@ package demo.form; +import haxework.resources.IResources; import haxework.gui.ButtonView; import haxework.gui.HGroupView; import haxework.gui.IGroupView; @@ -8,13 +9,15 @@ import haxework.gui.TextView; @:template class TailForm extends HGroupView { @:view public var group:IGroupView; + @:provide var resources:IResources; private function init() { for (i in 0...100) { var view = new TextView(); view.width = 100 + 100 * Math.random(); view.height = 100 + 100 * Math.random(); - view.skin = Style.view; + //view.skin = resources.skin.get("view"); + resources.skin.bind("view", view, "skin"); view.text = 'View #${i}'; group.addView(view); } diff --git a/src/main/haxework/gui/ButtonView.hx b/src/main/haxework/gui/ButtonView.hx index 4f09366..564d5a8 100755 --- a/src/main/haxework/gui/ButtonView.hx +++ b/src/main/haxework/gui/ButtonView.hx @@ -4,98 +4,100 @@ import haxework.signal.Signal; import flash.events.MouseEvent; enum ButtonState { - UP; - OVER; - DOWN; + UP; + OVER; + DOWN; } class ButtonView extends LabelView { - public var disabled(default, set):Bool; - public var state(get, null):ButtonState; - public var onPress(default, null):Signal; + public static var TYPE = "button"; - private var overed:Bool; - private var downed:Bool; + public var disabled(default, set):Bool; + public var state(get, null):ButtonState; + public var onPress(default, null):Signal; - public function new() { - super(); - overed = false; - downed = false; - state = ButtonState.UP; - onPress = new Signal(); - content.buttonMode = true; - content.mouseChildren = false; - #if js - content.addEventListener(MouseEvent.MOUSE_UP, onMouseClick); - #else - content.addEventListener(MouseEvent.CLICK, onMouseClick); - #end - #if !mobile - content.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); - content.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); - #end - content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); - content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); - } + private var overed:Bool; + private var downed:Bool; - private function onMouseClick(event:MouseEvent):Void { - #if js if (downed) { #end - event.stopImmediatePropagation(); - if (!disabled) onPress.emit(this); - #if js } #end - } - - private function onMouseOver(event:MouseEvent):Void { - overed = true; - invalidate(); - } - - private function onMouseOut(event:MouseEvent):Void { - overed = false; - invalidate(); - } - - private function onMouseDown(event:MouseEvent):Void { - downed = true; - if (content.stage != null) { - content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); - invalidate(); + public function new() { + super(); + overed = false; + downed = false; + state = ButtonState.UP; + onPress = new Signal(); + content.buttonMode = true; + content.mouseChildren = false; + #if js + content.addEventListener(MouseEvent.MOUSE_UP, onMouseClick); + #else + content.addEventListener(MouseEvent.CLICK, onMouseClick); + #end + #if !mobile + content.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); + content.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); + #end + content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); + content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); } - } - private function onMouseUp(event:MouseEvent):Void { - downed = false; - if (content.stage != null) { - content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); - invalidate(); + private function onMouseClick(event:MouseEvent):Void { + #if js if (downed) { #end + event.stopImmediatePropagation(); + if (!disabled) onPress.emit(this); + #if js } #end } - } - private function set_disabled(value:Bool):Bool { - if (disabled != value) { - disabled = value; - content.buttonMode = !disabled; - invalidate(); + private function onMouseOver(event:MouseEvent):Void { + overed = true; + invalidate(); } - return disabled; - } - private function get_state():ButtonState { - #if mobile + private function onMouseOut(event:MouseEvent):Void { + overed = false; + invalidate(); + } + + private function onMouseDown(event:MouseEvent):Void { + downed = true; + if (content.stage != null) { + content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); + invalidate(); + } + } + + private function onMouseUp(event:MouseEvent):Void { + downed = false; + if (content.stage != null) { + content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); + invalidate(); + } + } + + private function set_disabled(value:Bool):Bool { + if (disabled != value) { + disabled = value; + content.buttonMode = !disabled; + invalidate(); + } + return disabled; + } + + private function get_state():ButtonState { + #if mobile return downed ? ButtonState.DOWN : ButtonState.UP; #else - return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP; - #end - } + return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP; + #end + } - public function dispose():Void { - onPress.dispose(); - content.removeEventListener(MouseEvent.CLICK, onMouseClick); - content.removeEventListener(MouseEvent.MOUSE_UP, onMouseClick); - content.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver); - content.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut); - content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); - content.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); - } + public function dispose():Void { + onPress.dispose(); + content.removeEventListener(MouseEvent.CLICK, onMouseClick); + content.removeEventListener(MouseEvent.MOUSE_UP, onMouseClick); + content.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver); + content.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut); + content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); + content.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); + } } diff --git a/src/main/haxework/gui/GroupView.hx b/src/main/haxework/gui/GroupView.hx index cadc513..ff93248 100755 --- a/src/main/haxework/gui/GroupView.hx +++ b/src/main/haxework/gui/GroupView.hx @@ -8,185 +8,198 @@ import haxework.gui.layout.ILayout; import flash.display.Sprite; class GroupView extends SpriteView implements IGroupView { - public var container(get, null):DisplayObjectContainer; + public var container(get, null):DisplayObjectContainer; - public var views(default, set):Array>; - public var layout(default, default):ILayout; - - public var layoutVAlign(default, set):VAlign; - public var layoutHAlign(default, set):HAlign; - public var layoutMargin(default, set):Float = 0; - - public var leftPadding(default, set):Float; - public var rightPadding(default, set):Float; - public var topPadding(default, set):Float; - public var bottomPadding(default, set):Float; - public var paddings(null, set):Float; + public var views(default, set):Array>; + public var layout(default, default):ILayout; - private var viewsById:Map>; + public var layoutVAlign(default, set):VAlign; + public var layoutHAlign(default, set):HAlign; + public var layoutMargin(default, set):Float = 0; - public function new(?layout:ILayout) { - super(); - this.layout = layout == null ? new DefaultLayout() : layout; - paddings = 0; - //layoutMargin = 0; - layoutHAlign = HAlign.CENTER; - layoutVAlign = VAlign.MIDDLE; - views = []; - viewsById = new Map>(); - } + public var leftPadding(default, set):Float; + public var rightPadding(default, set):Float; + public var topPadding(default, set):Float; + public var bottomPadding(default, set):Float; + public var padding(null, set):Float; + public var paddings(null, set):Array; - inline private function get_container():DisplayObjectContainer { - return content; - } + private var viewsById:Map>; - override public function update():Void { - layout.place(this, views); - for (view in views) { - view.update(); - if (view.index > -1) { - content.setChildIndex(view.content, view.index); - } + public function new(?layout:ILayout) { + super(); + this.layout = layout == null ? new DefaultLayout() : layout; + padding = 0; + //layoutMargin = 0; + layoutHAlign = HAlign.CENTER; + layoutVAlign = VAlign.MIDDLE; + views = []; + viewsById = new Map>(); } - super.update(); - } - public function set_views(value:Array>):Array> { - removeAllViews(); - if (views == null) views = []; - for (view in value) addView(view); - return views; - } - - public function addView(view:IView):IView { - views.push(view); - viewsById.set(view.id, view); - if (view.content != null) content.addChild(view.content); - view.parent = this; - invalidate(); - return view; - } - - 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); - view.parent = this; - invalidate(); - return view; - } - - public function addViewFirst(view:IView):IView { - views.unshift(view); - viewsById.set(view.id, view); - content.addChild(view.content); - view.parent = this; - invalidate(); - return view; - } - - public function removeView(view:IView):IView { - view.parent = null; - viewsById.remove(view.id); - views.remove(view); - if (view.content != null) content.removeChild(view.content); - invalidate(); - return view; - } - - public function removeAllViews():Void { - if (views != null) while (views.length > 0) { - removeView(views[0]); + inline private function get_container():DisplayObjectContainer { + return content; } - } - public function removeViewById(id:String):IView { - if (viewsById.exists(id)) { - return removeView(viewsById.get(id)); - } else { - return null; + override public function update():Void { + layout.place(this, views); + for (view in views) { + view.update(); + if (view.index > -1) { + content.setChildIndex(view.content, view.index); + } + } + super.update(); } - } - public function findViewById>(id:String, ?clazz:Class):Null { - var idd:Array = id.split(":"); - if (idd.length > 1) { - var id0 = idd.shift(); - if (viewsById.exists(id0)) { - var g:GroupView = findViewById(id0); - return g.findViewById(idd.join(":"), clazz); - } else { - return null; - } - } else { - if (viewsById.exists(id)) { - return cast viewsById.get(id); - } else { - return null; - } + public function set_views(value:Array>):Array> { + removeAllViews(); + if (views == null) views = []; + for (view in value) addView(view); + return views; } - } - private function set_layoutVAlign(value:VAlign):VAlign { - if (layoutVAlign != value) { - layoutVAlign = value; - invalidate(); + public function addView(view:IView):IView { + views.push(view); + viewsById.set(view.id, view); + if (view.content != null) content.addChild(view.content); + view.parent = this; + invalidate(); + return view; } - return layoutVAlign; - } - private function set_layoutHAlign(value:HAlign):HAlign { - if (layoutHAlign != value) { - layoutHAlign = value; - invalidate(); + 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); + view.parent = this; + invalidate(); + return view; } - return layoutHAlign; - } - private function set_layoutMargin(value:Float):Float { - if (layoutMargin != value) { - layoutMargin = value; - invalidate(); + public function addViewFirst(view:IView):IView { + views.unshift(view); + viewsById.set(view.id, view); + content.addChild(view.content); + view.parent = this; + invalidate(); + return view; } - return layoutMargin; - } - private function set_leftPadding(value:Float):Float { - if (leftPadding != value) { - leftPadding = value; - invalidate(); + public function removeView(view:IView):IView { + view.parent = null; + viewsById.remove(view.id); + views.remove(view); + if (view.content != null) content.removeChild(view.content); + invalidate(); + return view; } - return leftPadding; - } - private function set_rightPadding(value:Float):Float { - if (rightPadding != value) { - rightPadding = value; - invalidate(); + public function removeAllViews():Void { + if (views != null) while (views.length > 0) { + removeView(views[0]); + } } - return rightPadding; - } - private function set_topPadding(value:Float):Float { - if (topPadding != value) { - topPadding = value; - invalidate(); + public function removeViewById(id:String):IView { + if (viewsById.exists(id)) { + return removeView(viewsById.get(id)); + } else { + return null; + } } - return topPadding; - } - private function set_bottomPadding(value:Float):Float { - if (bottomPadding != value) { - bottomPadding = value; - invalidate(); + public function findViewById>(id:String, ?clazz:Class):Null { + var idd:Array = id.split(":"); + if (idd.length > 1) { + var id0 = idd.shift(); + if (viewsById.exists(id0)) { + var g:GroupView = findViewById(id0); + return g.findViewById(idd.join(":"), clazz); + } else { + return null; + } + } else { + if (viewsById.exists(id)) { + return cast viewsById.get(id); + } else { + return null; + } + } } - return bottomPadding; - } - private function set_paddings(value:Float):Float { - leftPadding = rightPadding = topPadding = bottomPadding = value; - invalidate(); - return value; - } + private function set_layoutVAlign(value:VAlign):VAlign { + if (layoutVAlign != value) { + layoutVAlign = value; + invalidate(); + } + return layoutVAlign; + } + + private function set_layoutHAlign(value:HAlign):HAlign { + if (layoutHAlign != value) { + layoutHAlign = value; + invalidate(); + } + return layoutHAlign; + } + + private function set_layoutMargin(value:Float):Float { + if (layoutMargin != value) { + layoutMargin = value; + invalidate(); + } + return layoutMargin; + } + + private function set_leftPadding(value:Float):Float { + if (leftPadding != value) { + leftPadding = value; + invalidate(); + } + return leftPadding; + } + + private function set_rightPadding(value:Float):Float { + if (rightPadding != value) { + rightPadding = value; + invalidate(); + } + return rightPadding; + } + + private function set_topPadding(value:Float):Float { + if (topPadding != value) { + topPadding = value; + invalidate(); + } + return topPadding; + } + + private function set_bottomPadding(value:Float):Float { + if (bottomPadding != value) { + bottomPadding = value; + invalidate(); + } + return bottomPadding; + } + + private function set_padding(value:Float):Float { + paddings = [value]; + return value; + } + + private function set_paddings(value:Array):Array { + switch (value) { + case [m]: + leftPadding = rightPadding = topPadding = bottomPadding = m; + case [a, b]: + leftPadding = rightPadding = a; + topPadding = bottomPadding = b; + } + invalidate(); + invalidateParent(); + return value; + } } diff --git a/src/main/haxework/gui/HasPaddings.hx b/src/main/haxework/gui/HasPaddings.hx index 1a211dc..0bec5e3 100644 --- a/src/main/haxework/gui/HasPaddings.hx +++ b/src/main/haxework/gui/HasPaddings.hx @@ -5,5 +5,6 @@ interface HasPaddings { public var rightPadding(default, set):Float; public var topPadding(default, set):Float; public var bottomPadding(default, set):Float; - public var paddings(null, set):Float; -} \ No newline at end of file + public var padding(null, set):Float; + public var paddings(null, set):Array; +} diff --git a/src/main/haxework/gui/IView.hx b/src/main/haxework/gui/IView.hx index b1135d8..a9e4681 100755 --- a/src/main/haxework/gui/IView.hx +++ b/src/main/haxework/gui/IView.hx @@ -35,7 +35,8 @@ interface IView { public var rightMargin(default, set):Float; public var topMargin(default, set):Float; public var bottomMargin(default, set):Float; - public var margins(null, set):Float; + public var margin(null, set):Float; + public var margins(null, set):Array; public var content(default, null):C; public var skin(default, set):SkinSet; diff --git a/src/main/haxework/gui/LabelView.hx b/src/main/haxework/gui/LabelView.hx index 618e36b..a969365 100755 --- a/src/main/haxework/gui/LabelView.hx +++ b/src/main/haxework/gui/LabelView.hx @@ -2,17 +2,16 @@ package haxework.gui; import haxework.gui.core.HAlign; import haxework.gui.core.VAlign; -import flash.text.TextFieldAutoSize; class LabelView extends TextView { - public function new() { - super(); - fill = false; - textField.selectable = false; - textField.wordWrap = false; - textField.multiline = true; - layoutHAlign = HAlign.CENTER; - layoutVAlign = VAlign.MIDDLE; - } + public function new() { + super(); + fill = false; + textField.selectable = false; + textField.wordWrap = false; + textField.multiline = true; + layoutHAlign = HAlign.CENTER; + layoutVAlign = VAlign.MIDDLE; + } } diff --git a/src/main/haxework/gui/SpriteView.hx b/src/main/haxework/gui/SpriteView.hx index 80dae7c..77ffcb5 100755 --- a/src/main/haxework/gui/SpriteView.hx +++ b/src/main/haxework/gui/SpriteView.hx @@ -9,20 +9,17 @@ class SpriteView extends View { } override public function update():Void { - super.update(); this.content.graphics.clear(); - for (skin in this.skin) { - skin.draw(this); - } + super.update(); } - #if dev_layout + #if dev_layout override public function update():Void { - super.update(); - var g:Graphics = content.graphics; - g.lineStyle(1, 0x00ff00); - g.drawRect(0, 0, width, height); - g.lineStyle(); + super.update(); + var g:Graphics = content.graphics; + g.lineStyle(1, 0x00ff00); + g.drawRect(0, 0, width, height); + g.lineStyle(); } #end } diff --git a/src/main/haxework/gui/TextView.hx b/src/main/haxework/gui/TextView.hx index 5c1adc1..afbce31 100755 --- a/src/main/haxework/gui/TextView.hx +++ b/src/main/haxework/gui/TextView.hx @@ -11,275 +11,288 @@ import flash.text.TextField; class TextView extends SpriteView implements ITextView { - public var textField(default, null):TextField; - public var text(get, set):String; - private var _text:String; - public var align(default, set):TextFormatAlign; - public var fontFamily(default, set):String; - public var fontEmbed(default, set):Bool; - public var fontColor(default, set):Int; - public var fontSize(default, set):Int; - public var fontBold(default, set):Bool; + public var textField(default, null):TextField; + public var text(get, set):String; + private var _text:String; + public var align(default, set):TextFormatAlign; + public var fontFamily(default, set):String; + public var fontEmbed(default, set):Bool; + public var fontColor(default, set):Int; + public var fontSize(default, set):Int; + public var fontBold(default, set):Bool; - public var layoutHAlign(default, set):HAlign; - public var layoutVAlign(default, set):VAlign; - public var fill(default, set):Bool = true; + public var layoutHAlign(default, set):HAlign; + public var layoutVAlign(default, set):VAlign; + public var fill(default, set):Bool = true; - public var leftPadding(default, set):Float = 0.0; - public var rightPadding(default, set):Float = 0.0; - public var topPadding(default, set):Float = 0.0; - public var bottomPadding(default, set):Float = 0.0; - public var paddings(null, set):Float = 0.0; + public var leftPadding(default, set):Float = 0.0; + public var rightPadding(default, set):Float = 0.0; + public var topPadding(default, set):Float = 0.0; + public var bottomPadding(default, set):Float = 0.0; + public var padding(null, set):Float; + public var paddings(null, set):Array; - public var shadow(default, set):Bool; - public var shadowColor(default, set):Int; + public var shadow(default, set):Bool; + public var shadowColor(default, set):Int; - private var textFormat:TextFormat; + private var textFormat:TextFormat; - private var _textWidth:Float; - private var _textHeight:Float; + private var _textWidth:Float; + private var _textHeight:Float; - public function new() { - super(); - layoutHAlign = HAlign.CENTER; - layoutVAlign = VAlign.MIDDLE; - textField = buildTextField(); - textField.width = 1; - textField.height = 1; - textField.multiline = true; - textField.wordWrap = true; - #if dev_layout + public function new() { + super(); + layoutHAlign = HAlign.CENTER; + layoutVAlign = VAlign.MIDDLE; + textField = buildTextField(); + textField.width = 1; + textField.height = 1; + textField.multiline = true; + textField.wordWrap = true; + #if dev_layout textField.borderColor = 0xff0000; textField.border = true; #end - textFormat = textField.defaultTextFormat; - textFormat.font = "Arial"; - textFormat.size = 16; - textFormat.leading = 0; - textFormat.align = TextFormatAlign.CENTER; - content.addChild(textField); - } + textFormat = textField.defaultTextFormat; + textFormat.font = "Arial"; + textFormat.size = 16; + textFormat.leading = 0; + textFormat.align = TextFormatAlign.CENTER; + content.addChild(textField); + } - private function buildTextField():TextField { - #if bitmap_text + private function buildTextField():TextField { + #if bitmap_text return new BitmapTextField(); #else - return new TextField(); - #end - } - - private function set_fill(value:Bool):Bool { - if (fill != value) { - fill = value; - invalidate(); + return new TextField(); + #end } - return fill; - } - private function set_layoutHAlign(value:HAlign):HAlign { - if (layoutHAlign != value) { - layoutHAlign = value; - invalidate(); + private function set_fill(value:Bool):Bool { + if (fill != value) { + fill = value; + invalidate(); + } + return fill; } - return layoutHAlign; - } - private function set_layoutVAlign(value:VAlign):VAlign { - if (layoutVAlign != value) { - layoutVAlign = value; - invalidate(); + private function set_layoutHAlign(value:HAlign):HAlign { + if (layoutHAlign != value) { + layoutHAlign = value; + invalidate(); + } + return layoutHAlign; } - return layoutVAlign; - } - private function get_text():String { - return textField.text; - } - - private function set_text(value:String):String { - if (_text != value) { - _text = value; - invalidate(); + private function set_layoutVAlign(value:VAlign):VAlign { + if (layoutVAlign != value) { + layoutVAlign = value; + invalidate(); + } + return layoutVAlign; } - return _text; - } - private function set_align(value:TextFormatAlign):TextFormatAlign { - if (align != value) { - align = value; - textFormat.align = value; - invalidate(); + private function get_text():String { + return textField.text; } - return align; - } - private function set_fontFamily(value:String):String { - if (fontFamily != value) { - fontFamily = value; - textFormat.font = fontFamily; - invalidate(); + private function set_text(value:String):String { + if (_text != value) { + _text = value; + invalidate(); + } + return _text; } - return fontFamily; - } - private function set_fontEmbed(value:Bool):Bool { - if (fontEmbed != value) { - fontEmbed = value; - invalidate(); + private function set_align(value:TextFormatAlign):TextFormatAlign { + if (align != value) { + align = value; + textFormat.align = value; + invalidate(); + } + return align; } - return fontEmbed; - } - private function set_fontColor(value:Int):Int { - if (fontColor != value) { - fontColor = value; - textFormat.color = fontColor; - invalidate(); + private function set_fontFamily(value:String):String { + if (fontFamily != value) { + fontFamily = value; + textFormat.font = fontFamily; + invalidate(); + } + return fontFamily; } - return fontColor; - } - private function set_fontSize(value:Int):Int { - if (fontSize != value) { - fontSize = value; - textFormat.size = fontSize; - invalidate(); + private function set_fontEmbed(value:Bool):Bool { + if (fontEmbed != value) { + fontEmbed = value; + invalidate(); + } + return fontEmbed; } - return fontSize; - } - private function set_fontBold(value:Bool):Bool { - if (fontBold != value) { - fontBold = value; - textFormat.bold = fontBold; - invalidate(); + private function set_fontColor(value:Int):Int { + if (fontColor != value) { + fontColor = value; + textFormat.color = fontColor; + invalidate(); + } + return fontColor; } - return fontBold; - } - private function currentText():String { - return _text; - } + private function set_fontSize(value:Int):Int { + if (fontSize != value) { + fontSize = value; + textFormat.size = fontSize; + invalidate(); + } + return fontSize; + } - private function updateTextSize():Void { - var size = TextUtil.getSize(textField); - _textWidth = size.x; - _textHeight = size.y; - } + private function set_fontBold(value:Bool):Bool { + if (fontBold != value) { + fontBold = value; + textFormat.bold = fontBold; + invalidate(); + } + return fontBold; + } - override public function update():Void { - textField.embedFonts = fontEmbed; - textField.defaultTextFormat = textFormat; - textField.autoSize = fill ? TextFieldAutoSize.NONE : TextFieldAutoSize.LEFT; - var t:String = currentText(); - if (t != null) textField.text = t; - textField.setTextFormat(textFormat); - updateTextSize(); - if (contentSize && _text != null && _text.length > 0) { - #if html5 + private function currentText():String { + return _text; + } + + private function updateTextSize():Void { + var size = TextUtil.getSize(textField); + _textWidth = size.x; + _textHeight = size.y; + } + + override public function update():Void { + textField.embedFonts = fontEmbed; + textField.defaultTextFormat = textFormat; + textField.autoSize = fill ? TextFieldAutoSize.NONE : TextFieldAutoSize.LEFT; + var t:String = currentText(); + if (t != null) textField.text = t; + textField.setTextFormat(textFormat); + updateTextSize(); + if (contentSize && _text != null && _text.length > 0) { + #if html5 var h = _textHeight; var w = _textWidth; //if (h > textFormat.size * 1.5) h = h / 2; textField.height = h; textField.width = w; #end - width = textField.width + leftPadding + rightPadding; - height = textField.height + topPadding + bottomPadding; - textField.x = leftPadding; - textField.y = topPadding; - } else { - placeTextField(textField); + width = textField.width + leftPadding + rightPadding; + height = textField.height + topPadding + bottomPadding; + textField.x = leftPadding; + textField.y = topPadding; + } else { + placeTextField(textField); + } + //ToDo: + //var t:Point = content.localToGlobal(new Point(textField.x, textField.y)); + //t.x = Math.round(t.x); + //t.y = Math.round(t.y); + //t = content.globalToLocal(t); + //textField.x = t.x; + //textField.y = t.y; + super.update(); } - //ToDo: - //var t:Point = content.localToGlobal(new Point(textField.x, textField.y)); - //t.x = Math.round(t.x); - //t.y = Math.round(t.y); - //t = content.globalToLocal(t); - //textField.x = t.x; - //textField.y = t.y; - super.update(); - } - private function placeTextField(textField:TextField):Void { - textField.width = width; - textField.height = _textHeight; + private function placeTextField(textField:TextField):Void { + textField.width = width; + textField.height = _textHeight; - textField.x = switch (layoutHAlign) { - case HAlign.NONE: 0; - case HAlign.LEFT: leftPadding; - case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding; - case HAlign.RIGHT: width - textField.width - rightPadding; - default: 0; + textField.x = switch (layoutHAlign) { + case HAlign.NONE: 0; + case HAlign.LEFT: leftPadding; + case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding; + case HAlign.RIGHT: width - textField.width - rightPadding; + default: 0; + } + textField.y = switch (layoutVAlign) { + case VAlign.NONE: 0; + case VAlign.TOP: topPadding; + case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding; + case VAlign.BOTTOM: height - _textHeight - bottomPadding; + default: 0; + } } - textField.y = switch (layoutVAlign) { - case VAlign.NONE: 0; - case VAlign.TOP: topPadding; - case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding; - case VAlign.BOTTOM: height - _textHeight - bottomPadding; - default: 0; + + override private function set_mouseEnabled(value:Bool):Bool { + textField.mouseEnabled = value; + return super.set_mouseEnabled(value); } - } - - override private function set_mouseEnabled(value:Bool):Bool { - textField.mouseEnabled = value; - return super.set_mouseEnabled(value); - } - private function set_leftPadding(value:Float):Float { - if (leftPadding != value) { - leftPadding = value; - invalidate(); + private function set_leftPadding(value:Float):Float { + if (leftPadding != value) { + leftPadding = value; + invalidate(); + } + return leftPadding; } - return leftPadding; - } - private function set_rightPadding(value:Float):Float { - if (rightPadding != value) { - rightPadding = value; - invalidate(); + private function set_rightPadding(value:Float):Float { + if (rightPadding != value) { + rightPadding = value; + invalidate(); + } + return rightPadding; } - return rightPadding; - } - private function set_topPadding(value:Float):Float { - if (topPadding != value) { - topPadding = value; - invalidate(); + private function set_topPadding(value:Float):Float { + if (topPadding != value) { + topPadding = value; + invalidate(); + } + return topPadding; } - return topPadding; - } - private function set_bottomPadding(value:Float):Float { - if (bottomPadding != value) { - bottomPadding = value; - invalidate(); + private function set_bottomPadding(value:Float):Float { + if (bottomPadding != value) { + bottomPadding = value; + invalidate(); + } + return bottomPadding; } - return bottomPadding; - } - private function set_paddings(value:Float):Float { - leftPadding = rightPadding = topPadding = bottomPadding = value; - invalidate(); - return value; - } - - private function set_shadow(value) { - if (Std.is(textField, BitmapTextField)) { - cast(textField, BitmapTextField).shadow = value; - return cast(textField, BitmapTextField).shadow; - } else { - return value; + private function set_padding(value:Float):Float { + paddings = [value]; + return value; } - } - private function set_shadowColor(value) { - if (Std.is(textField, BitmapTextField)) { - cast(textField, BitmapTextField).shadowColor = value; - cast(textField, BitmapTextField).shadow = true; - return cast(textField, BitmapTextField).shadowColor; - } else { - return value; + private function set_paddings(value:Array):Array { + switch (value) { + case [m]: + leftPadding = rightPadding = topPadding = bottomPadding = m; + case [a, b]: + leftPadding = rightPadding = a; + topPadding = bottomPadding = b; + } + invalidate(); + invalidateParent(); + return value; + } + + private function set_shadow(value) { + if (Std.is(textField, BitmapTextField)) { + cast(textField, BitmapTextField).shadow = value; + return cast(textField, BitmapTextField).shadow; + } else { + return value; + } + } + + private function set_shadowColor(value) { + if (Std.is(textField, BitmapTextField)) { + cast(textField, BitmapTextField).shadowColor = value; + cast(textField, BitmapTextField).shadow = true; + return cast(textField, BitmapTextField).shadowColor; + } else { + return value; + } } - } } diff --git a/src/main/haxework/gui/View.hx b/src/main/haxework/gui/View.hx index c69aa29..f321463 100755 --- a/src/main/haxework/gui/View.hx +++ b/src/main/haxework/gui/View.hx @@ -1,334 +1,346 @@ package haxework.gui; -import haxework.gui.skin.ISkin.SkinSet; -import flash.display.InteractiveObject; +import Array; import flash.display.DisplayObject; -import haxework.gui.core.SizeType; -import haxework.gui.core.HAlign; -import haxework.gui.core.VAlign; -import flash.events.Event; +import flash.display.InteractiveObject; import flash.display.Stage; +import flash.events.Event; +import haxework.gui.core.HAlign; +import haxework.gui.core.SizeType; +import haxework.gui.core.VAlign; +import haxework.gui.skin.ISkin.SkinSet; class View implements IView { - private static var counter:Int = 0; - public static var updater(default, null):Updater = new Updater(); + private static var counter:Int = 0; + public static var updater(default, null):Updater = new Updater(); - public var id(default, default):String; + public var id(default, default):String; - public var x(default, set):Float; - public var y(default, set):Float; + public var x(default, set):Float; + public var y(default, set):Float; - public var w(default, set):Float; - public var h(default, set):Float; + public var w(default, set):Float; + public var h(default, set):Float; - public var r(default, set):Float; + public var r(default, set):Float; - public var widthType(default, null):SizeType; - public var heightType(default, null):SizeType; + public var widthType(default, null):SizeType; + public var heightType(default, null):SizeType; - public var width(get, set):Float; - public var height(get, set):Float; + public var width(get, set):Float; + public var height(get, set):Float; - public var pWidth(default, set):Float; - public var pHeight(default, set):Float; + public var pWidth(default, set):Float; + public var pHeight(default, set):Float; - public var contentSize(default, set):Bool; + public var contentSize(default, set):Bool; - public var hAlign(default, set):HAlign; - public var vAlign(default, set):VAlign; + public var hAlign(default, set):HAlign; + public var vAlign(default, set):VAlign; - public var leftMargin(default, set):Float; - public var rightMargin(default, set):Float; - public var topMargin(default, set):Float; - public var bottomMargin(default, set):Float; - public var margins(null, set):Float; + public var leftMargin(default, set):Float; + public var rightMargin(default, set):Float; + public var topMargin(default, set):Float; + public var bottomMargin(default, set):Float; + public var margin(null, set):Float; + public var margins(null, set):Array; - public var content(default, null):C; - public var skin(default, set):SkinSet; + public var content(default, null):C; + public var skin(default, set):SkinSet; - public var parent(default, null):Null; - public var inLayout(default, set):Bool; + public var parent(default, null):Null; + 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 var visible(default, set):Bool; + public var index(default, set):Int; + public var mouseEnabled(default, set):Bool = true; - public function new(content:C) { - id = Type.getClassName(Type.getClass(this)) + counter++; - this.content = content; - x = 0; - y = 0; - width = 1; - height = 1; - margins = 0; - vAlign = VAlign.NONE; - hAlign = HAlign.NONE; - inLayout = true; - visible = true; - index = -1; - skin = []; - } - - public function invalidate():Void { - updater.invalidate(this); - } - - private function invalidateParent():Void { - if (parent != null) - updater.invalidate(parent); - } - - public function update():Void { - if (content != null) { - content.x = x; - content.y = y; + public function new(content:C) { + id = Type.getClassName(Type.getClass(this)) + counter++; + this.content = content; + x = 0; + y = 0; + width = 1; + height = 1; + margin = 0; + vAlign = VAlign.NONE; + hAlign = HAlign.NONE; + inLayout = true; + visible = true; + index = -1; + skin = []; } - /*var skin:ISkin = currentSkin(); - if (contentSize && skin != null && Std.is(skin, ISize)) { - var size:ISize = cast(skin, ISize); - if (!Math.isNaN(size.width)) width = size.width; - if (!Math.isNaN(size.height)) height = size.height; + + public function invalidate():Void { + updater.invalidate(this); } - if (skin != null) skin.draw(this);*/ - } - public function remove():Void { - if (parent != null) parent.removeView(this); - } - - private function set_x(value:Float):Float { - if (x != value) { - x = value; - invalidate(); + private function invalidateParent():Void { + if (parent != null) + updater.invalidate(parent); } - return x; - } - private function set_y(value:Float):Float { - if (y != value) { - y = value; - invalidate(); + + public function update():Void { + if (content != null) { + content.x = x; + content.y = y; + } + for (skin in this.skin) { + skin.draw(this); + } } - return y; - } - private function set_w(value:Float):Float { - if (w != value) { - w = value; - if (!Math.isNaN(r) && r > 0) h = w / r; - invalidate(); + public function remove():Void { + if (parent != null) parent.removeView(this); } - return w; - } - private function set_h(value:Float):Float { - if (h != value) { - h = value; - if (!Math.isNaN(r) && r > 0) w = h * r; - invalidate(); + + private function set_x(value:Float):Float { + if (x != value) { + x = value; + invalidate(); + } + return x; } - return h; - } - private function set_r(value:Float):Float { - if (r != value) { - r = value; - invalidate(); - invalidateParent(); + private function set_y(value:Float):Float { + if (y != value) { + y = value; + invalidate(); + } + return y; } - return r; - } - private function get_width():Float { - return w; - } - - private function get_height():Float { - return h; - } - - private function set_width(value:Float):Float { - if (w != value || widthType != SizeType.NORMAL) { - w = value; - widthType = SizeType.NORMAL; - invalidate(); - invalidateParent(); + private function set_w(value:Float):Float { + if (w != value) { + w = value; + if (!Math.isNaN(r) && r > 0) h = w / r; + invalidate(); + } + return w; } - return w; - } - private function set_height(value:Float):Float { - if (h != value || heightType != SizeType.NORMAL) { - h = value; - heightType = SizeType.NORMAL; - invalidate(); - invalidateParent(); + private function set_h(value:Float):Float { + if (h != value) { + h = value; + if (!Math.isNaN(r) && r > 0) w = h * r; + invalidate(); + } + return h; } - return h; - } - private function set_pWidth(value:Float):Float { - if (pWidth != value || widthType != SizeType.PERCENT) { - pWidth = value; - widthType = SizeType.PERCENT; - invalidate(); - invalidateParent(); + private function set_r(value:Float):Float { + if (r != value) { + r = value; + invalidate(); + invalidateParent(); + } + return r; } - return pWidth; - } - private function set_pHeight(value:Float):Float { - if (pHeight != value || heightType != SizeType.PERCENT) { - pHeight = value; - heightType = SizeType.PERCENT; - invalidate(); - invalidateParent(); + private function get_width():Float { + return w; } - return pHeight; - } - private function set_contentSize(value:Bool):Bool { - if (contentSize != value) { - contentSize = value; - invalidate(); - invalidateParent(); + private function get_height():Float { + return h; } - return contentSize; - } - private function set_hAlign(value:HAlign):HAlign { - if (hAlign != value) { - hAlign = value; - invalidate(); - invalidateParent(); + private function set_width(value:Float):Float { + if (w != value || widthType != SizeType.NORMAL) { + w = value; + widthType = SizeType.NORMAL; + invalidate(); + invalidateParent(); + } + return w; } - return hAlign; - } - private function set_vAlign(value:VAlign):VAlign { - if (vAlign != value) { - vAlign = value; - invalidate(); - invalidateParent(); + private function set_height(value:Float):Float { + if (h != value || heightType != SizeType.NORMAL) { + h = value; + heightType = SizeType.NORMAL; + invalidate(); + invalidateParent(); + } + return h; } - return vAlign; - } - private function set_leftMargin(value:Float):Float { - if (leftMargin != value) { - leftMargin = value; - invalidate(); - invalidateParent(); + private function set_pWidth(value:Float):Float { + if (pWidth != value || widthType != SizeType.PERCENT) { + pWidth = value; + widthType = SizeType.PERCENT; + invalidate(); + invalidateParent(); + } + return pWidth; } - return leftMargin; - } - private function set_rightMargin(value:Float):Float { - if (rightMargin != value) { - rightMargin = value; - invalidate(); - invalidateParent(); + private function set_pHeight(value:Float):Float { + if (pHeight != value || heightType != SizeType.PERCENT) { + pHeight = value; + heightType = SizeType.PERCENT; + invalidate(); + invalidateParent(); + } + return pHeight; } - return rightMargin; - } - private function set_topMargin(value:Float):Float { - if (topMargin != value) { - topMargin = value; - invalidate(); - invalidateParent(); + private function set_contentSize(value:Bool):Bool { + if (contentSize != value) { + contentSize = value; + invalidate(); + invalidateParent(); + } + return contentSize; } - return topMargin; - } - private function set_bottomMargin(value:Float):Float { - if (bottomMargin != value) { - bottomMargin = value; - invalidate(); - invalidateParent(); + private function set_hAlign(value:HAlign):HAlign { + if (hAlign != value) { + hAlign = value; + invalidate(); + invalidateParent(); + } + return hAlign; } - return bottomMargin; - } - private function set_margins(value:Float):Float { - leftMargin = rightMargin = topMargin = bottomMargin = value; - invalidate(); - invalidateParent(); - return value; - } - - private function set_skin(value:SkinSet):SkinSet { - skin = value; - invalidate(); - return skin; - } - - private function set_inLayout(value:Bool):Bool { - if (inLayout != value) { - inLayout = value; - invalidateParent(); + private function set_vAlign(value:VAlign):VAlign { + if (vAlign != value) { + vAlign = value; + invalidate(); + invalidateParent(); + } + return vAlign; } - return inLayout; - } - private function set_visible(value:Bool):Bool { - if (visible != value) { - visible = value; - if (content != null) content.visible = visible; + private function set_leftMargin(value:Float):Float { + if (leftMargin != value) { + leftMargin = value; + invalidate(); + invalidateParent(); + } + return leftMargin; } - return visible; - } - private function set_index(value:Int):Int { - if (index != value) { - index = value; - invalidateParent(); + private function set_rightMargin(value:Float):Float { + if (rightMargin != value) { + rightMargin = value; + invalidate(); + invalidateParent(); + } + return rightMargin; } - return index; - } - private function set_mouseEnabled(value:Bool):Bool { - if (mouseEnabled != value) { - mouseEnabled = value; - if (content != null && Std.is(content, InteractiveObject)) { - cast(content, InteractiveObject).mouseEnabled = mouseEnabled; - } + private function set_topMargin(value:Float):Float { + if (topMargin != value) { + topMargin = value; + invalidate(); + invalidateParent(); + } + return topMargin; + } + + private function set_bottomMargin(value:Float):Float { + if (bottomMargin != value) { + bottomMargin = value; + invalidate(); + invalidateParent(); + } + return bottomMargin; + } + + private function set_margin(value:Float):Float { + margins = [value]; + return value; + } + + private function set_margins(value:Array):Array { + switch (value) { + case [m]: + leftMargin = rightMargin = topMargin = bottomMargin = m; + case [a, b]: + leftMargin = rightMargin = a; + topMargin = bottomMargin = b; + } + + invalidate(); + invalidateParent(); + return value; + } + + private function set_skin(value:SkinSet):SkinSet { + skin = value; + invalidate(); + return skin; + } + + private function set_inLayout(value:Bool):Bool { + if (inLayout != value) { + inLayout = value; + invalidateParent(); + } + return inLayout; + } + + private function set_visible(value:Bool):Bool { + if (visible != value) { + visible = value; + if (content != null) content.visible = visible; + } + return visible; + } + + private function set_index(value:Int):Int { + if (index != value) { + index = value; + invalidateParent(); + } + return index; + } + + private function set_mouseEnabled(value:Bool):Bool { + if (mouseEnabled != value) { + mouseEnabled = value; + if (content != null && Std.is(content, InteractiveObject)) { + cast(content, InteractiveObject).mouseEnabled = mouseEnabled; + } + } + return mouseEnabled; } - return mouseEnabled; - } } class Updater { - public var stage(null, set):Stage; - private var invalidated:Array>; + public var stage(null, set):Stage; + private var invalidated:Array>; - public function new() { - invalidated = []; - } - - private function set_stage(value:Stage):Stage { - value.addEventListener(Event.ENTER_FRAME, update); - return value; - } - - public function invalidate(view:IView):Void { - if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view); - } - - public function update(?_):Void { - var t = Date.now().getTime(); - while (invalidated.length > 0) { - var v = null; - try { - v = invalidated.shift(); - v.update(); - } catch (error:Dynamic) { - L.e("Update", v + "", error); - } + public function new() { + invalidated = []; + } + + private function set_stage(value:Stage):Stage { + value.addEventListener(Event.ENTER_FRAME, update); + return value; + } + + public function invalidate(view:IView):Void { + if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view); + } + + public function update(?_):Void { + var t = Date.now().getTime(); + while (invalidated.length > 0) { + var v = null; + try { + v = invalidated.shift(); + v.update(); + } catch (error:Dynamic) { + L.e("Update", v + "", error); + } + } + t = Date.now().getTime() - t; + if (t > 10) trace("UPDATE(" + t + ")"); } - t = Date.now().getTime() - t; - if (t > 10) trace("UPDATE(" + t + ")"); - } } diff --git a/src/main/haxework/gui/frame/FrameSwitcher.hx b/src/main/haxework/gui/frame/FrameSwitcher.hx index 2dcde1c..1c75f0e 100755 --- a/src/main/haxework/gui/frame/FrameSwitcher.hx +++ b/src/main/haxework/gui/frame/FrameSwitcher.hx @@ -1,74 +1,78 @@ package haxework.gui.frame; +import haxework.signal.Signal; import haxework.animate.IAnimate; 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 var current(default, null):Null>; + public var onSwitch:Signal> = new Signal(); - public var animateFactory(default, default):Class; - private var animate:IAnimate; + private var frames:Map>; - public function new() { - super(); - frames = new Map>(); - current = null; - } + public var animateFactory(default, default):Class; + private var animate:IAnimate; - private function buildAnimate(view:IView):Null { - if (animateFactory != null) { - return Type.createInstance(animateFactory, [view]); + public function new() { + super(); + frames = new Map>(); + current = null; } - return null; - } - public function change(id:String):IView { - var prev = null; - if (current != null) { - if (current.id == id) return current; - prev = current; + private function buildAnimate(view:IView):Null { + if (animateFactory != null) { + return Type.createInstance(animateFactory, [view]); + } + return null; } - current = frames.get(id); - if (current == null) { - throw 'frame "$id" not found'; - } - addView(current); - //ToDo: - if (content.stage != null) content.stage.focus = cast(current, SpriteView).content; - var onShowMethod:Dynamic = Reflect.field(current, "onShow"); - if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []); - if (animate != null) animate.cancel(); - animate = buildAnimate(current); - if (animate != null && prev != null) { - animate.start(function(_) { - removePrev(prev); - }); - } else { - removePrev(prev); - } - return current; - } - private function removePrev(prev:Null>):Void { - if (prev != null) { - var onHideMethod:Dynamic = Reflect.field(prev, "onHide"); - if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []); - removeView(prev); + public function change(id:String):IView { + var prev = null; + if (current != null) { + if (current.id == id) return current; + prev = current; + } + current = frames.get(id); + if (current == null) { + throw 'frame "$id" not found'; + } + addView(current); + //ToDo: + if (content.stage != null) content.stage.focus = cast(current, SpriteView).content; + var onShowMethod:Dynamic = Reflect.field(current, "onShow"); + if (onShowMethod != null) Reflect.callMethod(current, onShowMethod, []); + if (animate != null) animate.cancel(); + animate = buildAnimate(current); + if (animate != null && prev != null) { + animate.start(function(_) { + removePrev(prev); + }); + } else { + removePrev(prev); + } + onSwitch.emit(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); - } + private function removePrev(prev:Null>):Void { + if (prev != null) { + var onHideMethod:Dynamic = Reflect.field(prev, "onHide"); + if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []); + removeView(prev); + } + } + + 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; } - return value; - } } diff --git a/src/main/haxework/gui/list/LabelListItem.hx b/src/main/haxework/gui/list/LabelListItem.hx index 0c5e64e..b2dca78 100644 --- a/src/main/haxework/gui/list/LabelListItem.hx +++ b/src/main/haxework/gui/list/LabelListItem.hx @@ -6,7 +6,7 @@ import haxework.gui.list.ListView.IListItemView; class LabelListItem extends LabelView implements IListItemView { - public var item_index(default, set):Int; + public var item_index(default, default):Int; public var data(default, set):T; public function new() { @@ -15,16 +15,10 @@ class LabelListItem extends LabelView implements IListItemView { pWidth = 100; layoutHAlign = LEFT; } - - private function set_item_index(value:Int):Int { - item_index = value; - skin = item_index % 2 == 1 ? [new ColorSkin(0xdddddd)] : [new ColorSkin(0xcccccc)]; - return item_index; - } - private function set_data(value:T):T { data = value; text = Std.string(value); + skin = item_index % 2 == 1 ? [new ColorSkin(0xdddddd)] : [new ColorSkin(0xcccccc)]; return value; } } diff --git a/src/main/haxework/gui/skin/ButtonColorSkin.hx b/src/main/haxework/gui/skin/ButtonColorSkin.hx index 04ef3a8..69c5cb3 100644 --- a/src/main/haxework/gui/skin/ButtonColorSkin.hx +++ b/src/main/haxework/gui/skin/ButtonColorSkin.hx @@ -19,8 +19,8 @@ class ButtonColorSkin implements ISkin { private function set_color(value:Int):Int { colors = new Map(); colors.set(ButtonState.UP, value); - colors.set(ButtonState.DOWN, ColorUtils.diff(value, -64)); - colors.set(ButtonState.OVER, ColorUtils.diff(value, 64)); + colors.set(ButtonState.DOWN, ColorUtils.diff(value, -32)); + colors.set(ButtonState.OVER, ColorUtils.diff(value, 32)); //disable = ColorUtils.multiply(value, 0.6); return value; } @@ -29,7 +29,8 @@ class ButtonColorSkin implements ISkin { var color:Int = selectColor(view); var graphics:Graphics = view.content.graphics; graphics.beginFill(color, alpha); - graphics.drawRect(0, 0, view.width, view.height); + graphics.lineStyle(2, ColorUtils.multiply(color, 1.5)); + graphics.drawRoundRect(1, 1, view.width - 2, view.height - 2, 5, 5); } private function selectColor(view:ButtonView):Int { diff --git a/src/main/haxework/gui/skin/ButtonSkin.hx b/src/main/haxework/gui/skin/ButtonSkin.hx deleted file mode 100644 index 764ad14..0000000 --- a/src/main/haxework/gui/skin/ButtonSkin.hx +++ /dev/null @@ -1,10 +0,0 @@ -package haxework.gui.skin; - -import haxework.gui.ButtonView; - -class ButtonSkin { - - public static function color(color: Int, alpha: Float = 1.0): ISkin { - return new ButtonColorSkin(color, alpha); - } -} diff --git a/src/main/haxework/gui/skin/Skin.hx b/src/main/haxework/gui/skin/Skin.hx index fb3b90d..617dd3e 100644 --- a/src/main/haxework/gui/skin/Skin.hx +++ b/src/main/haxework/gui/skin/Skin.hx @@ -23,4 +23,12 @@ class Skin { public static function text(fontColor:Int, fontSize:Int, fontFamily:String = null):ISkin { return new TextSkin(fontColor, fontSize, fontFamily); } + + public static function buttonColor(color: Int, alpha: Float = 1.0): ISkin { + return new ButtonColorSkin(color, alpha); + } + + public static function tabColor(color: Int, alpha: Float = 1.0): ISkin { + return new TabColorSkin(color, alpha); + } } diff --git a/src/main/haxework/gui/skin/TabColorSkin.hx b/src/main/haxework/gui/skin/TabColorSkin.hx new file mode 100644 index 0000000..482e669 --- /dev/null +++ b/src/main/haxework/gui/skin/TabColorSkin.hx @@ -0,0 +1,20 @@ +package haxework.gui.skin; + +import flash.display.Graphics; +import haxework.gui.utils.ColorUtils; + +class TabColorSkin extends ButtonColorSkin { + + override public function draw(view:ButtonView):Void { + var color:Int = selectColor(view); + if (Std.is(view, ToggleButtonView)) { + if (!cast(view, ToggleButtonView).on) { + color = ColorUtils.multiply(color, 0.5); + } + } + var graphics:Graphics = view.content.graphics; + graphics.beginFill(color, alpha); + graphics.lineStyle(2, ColorUtils.multiply(color, 1.5)); + graphics.drawRoundRectComplex(1, 1, view.width - 2, view.height - 2, 5, 5, 0, 0); + } +}