[demo] update
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package demo;
|
package demo;
|
||||||
|
|
||||||
|
import haxework.gui.ToggleButtonView;
|
||||||
|
import haxework.gui.IGroupView;
|
||||||
|
import haxework.gui.IView;
|
||||||
import haxework.resources.Resources;
|
import haxework.resources.Resources;
|
||||||
import haxework.resources.IResources;
|
import haxework.resources.IResources;
|
||||||
import haxework.gui.frame.IFrameSwitcher;
|
import haxework.gui.frame.IFrameSwitcher;
|
||||||
@@ -18,11 +21,16 @@ import haxework.gui.VGroupView;
|
|||||||
L.push(new TraceLogger());
|
L.push(new TraceLogger());
|
||||||
resources = new Resources();
|
resources = new Resources();
|
||||||
manager = new LoaderManager();
|
manager = new LoaderManager();
|
||||||
Style.register();
|
Theme.setColor(0x33aa33);
|
||||||
var demo = new Demo();
|
var demo = new Demo();
|
||||||
demo.switcher.change("list_form");
|
demo.switcher.change("list_form");
|
||||||
Root.bind(demo);
|
Root.bind(demo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:view public var switcher:IFrameSwitcher;
|
@:view var switcher:IFrameSwitcher;
|
||||||
|
@:view var tabs:IGroupView;
|
||||||
|
|
||||||
|
private function onFrameSwicth(frame:IView<Dynamic>):Void {
|
||||||
|
for (view in tabs.views) cast(view, ToggleButtonView).on = view.id == frame.id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,29 +3,40 @@ pWidth: 100
|
|||||||
pHeight: 100
|
pHeight: 100
|
||||||
skin: $r:skin:background
|
skin: $r:skin:background
|
||||||
views:
|
views:
|
||||||
- $type: haxework.gui.HGroupView
|
- id: tabs
|
||||||
|
$type: haxework.gui.HGroupView
|
||||||
layoutMargin: 5
|
layoutMargin: 5
|
||||||
layoutHAlign: LEFT
|
layoutHAlign: LEFT
|
||||||
leftPadding: 5
|
leftPadding: 5
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
height: 40
|
height: 40
|
||||||
views:
|
views:
|
||||||
- $type: haxework.gui.ButtonView
|
- id: list_form
|
||||||
skin: $r:skin:button
|
$type: haxework.gui.ToggleButtonView
|
||||||
|
skin: $r:skin:tab
|
||||||
contentSize: true
|
contentSize: true
|
||||||
paddings: 8
|
paddings: [25, 8]
|
||||||
text: List Form
|
text: List
|
||||||
+onPress: "$code:function(_) switcher.change('list_form')"
|
+onPress: "$code:function(_) switcher.change('list_form')"
|
||||||
- $type: haxework.gui.ButtonView
|
- id: tail_form
|
||||||
skin: $r:skin:button
|
$type: haxework.gui.ToggleButtonView
|
||||||
|
skin: $r:skin:tab
|
||||||
contentSize: true
|
contentSize: true
|
||||||
paddings: 8
|
paddings: [25, 8]
|
||||||
text: Tail Form
|
text: Tail
|
||||||
+onPress: "$code:function(_) switcher.change('tail_form')"
|
+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
|
- id: switcher
|
||||||
$type: haxework.gui.frame.FrameSwitcher
|
$type: haxework.gui.frame.FrameSwitcher
|
||||||
skin: [ $type: [ haxework.gui.skin.Skin.border, 0x33aa33, 1, 2 ] ]
|
skin: $r:skin:border
|
||||||
paddings: 5
|
+onSwitch: $this:onFrameSwicth
|
||||||
|
padding: 5
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 100
|
pHeight: 100
|
||||||
views:
|
views:
|
||||||
@@ -37,3 +48,51 @@ views:
|
|||||||
$type: demo.form.TailForm
|
$type: demo.form.TailForm
|
||||||
pWidth: 100
|
pWidth: 100
|
||||||
pHeight: 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)"
|
||||||
|
|||||||
@@ -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<Dynamic> = 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
45
demo/src/demo/Theme.hx
Normal file
45
demo/src/demo/Theme.hx
Normal file
@@ -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<Dynamic> = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package demo.form;
|
package demo.form;
|
||||||
|
|
||||||
|
import haxework.resources.IResources;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.gui.HGroupView;
|
import haxework.gui.HGroupView;
|
||||||
import haxework.gui.IGroupView;
|
import haxework.gui.IGroupView;
|
||||||
@@ -8,13 +9,15 @@ import haxework.gui.TextView;
|
|||||||
|
|
||||||
@:template class TailForm extends HGroupView {
|
@:template class TailForm extends HGroupView {
|
||||||
@:view public var group:IGroupView;
|
@:view public var group:IGroupView;
|
||||||
|
@:provide var resources:IResources;
|
||||||
|
|
||||||
private function init() {
|
private function init() {
|
||||||
for (i in 0...100) {
|
for (i in 0...100) {
|
||||||
var view = new TextView();
|
var view = new TextView();
|
||||||
view.width = 100 + 100 * Math.random();
|
view.width = 100 + 100 * Math.random();
|
||||||
view.height = 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}';
|
view.text = 'View #${i}';
|
||||||
group.addView(view);
|
group.addView(view);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,98 +4,100 @@ import haxework.signal.Signal;
|
|||||||
import flash.events.MouseEvent;
|
import flash.events.MouseEvent;
|
||||||
|
|
||||||
enum ButtonState {
|
enum ButtonState {
|
||||||
UP;
|
UP;
|
||||||
OVER;
|
OVER;
|
||||||
DOWN;
|
DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ButtonView extends LabelView {
|
class ButtonView extends LabelView {
|
||||||
|
|
||||||
public var disabled(default, set):Bool;
|
public static var TYPE = "button";
|
||||||
public var state(get, null):ButtonState;
|
|
||||||
public var onPress(default, null):Signal<ButtonView>;
|
|
||||||
|
|
||||||
private var overed:Bool;
|
public var disabled(default, set):Bool;
|
||||||
private var downed:Bool;
|
public var state(get, null):ButtonState;
|
||||||
|
public var onPress(default, null):Signal<ButtonView>;
|
||||||
|
|
||||||
public function new() {
|
private var overed:Bool;
|
||||||
super();
|
private var downed:Bool;
|
||||||
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 onMouseClick(event:MouseEvent):Void {
|
public function new() {
|
||||||
#if js if (downed) { #end
|
super();
|
||||||
event.stopImmediatePropagation();
|
overed = false;
|
||||||
if (!disabled) onPress.emit(this);
|
downed = false;
|
||||||
#if js } #end
|
state = ButtonState.UP;
|
||||||
}
|
onPress = new Signal();
|
||||||
|
content.buttonMode = true;
|
||||||
private function onMouseOver(event:MouseEvent):Void {
|
content.mouseChildren = false;
|
||||||
overed = true;
|
#if js
|
||||||
invalidate();
|
content.addEventListener(MouseEvent.MOUSE_UP, onMouseClick);
|
||||||
}
|
#else
|
||||||
|
content.addEventListener(MouseEvent.CLICK, onMouseClick);
|
||||||
private function onMouseOut(event:MouseEvent):Void {
|
#end
|
||||||
overed = false;
|
#if !mobile
|
||||||
invalidate();
|
content.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
|
||||||
}
|
content.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
|
||||||
|
#end
|
||||||
private function onMouseDown(event:MouseEvent):Void {
|
content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
downed = true;
|
content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
if (content.stage != null) {
|
|
||||||
content.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function onMouseUp(event:MouseEvent):Void {
|
private function onMouseClick(event:MouseEvent):Void {
|
||||||
downed = false;
|
#if js if (downed) { #end
|
||||||
if (content.stage != null) {
|
event.stopImmediatePropagation();
|
||||||
content.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
if (!disabled) onPress.emit(this);
|
||||||
invalidate();
|
#if js } #end
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function set_disabled(value:Bool):Bool {
|
private function onMouseOver(event:MouseEvent):Void {
|
||||||
if (disabled != value) {
|
overed = true;
|
||||||
disabled = value;
|
invalidate();
|
||||||
content.buttonMode = !disabled;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return disabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_state():ButtonState {
|
private function onMouseOut(event:MouseEvent):Void {
|
||||||
#if mobile
|
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;
|
return downed ? ButtonState.DOWN : ButtonState.UP;
|
||||||
#else
|
#else
|
||||||
return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP;
|
return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP;
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dispose():Void {
|
public function dispose():Void {
|
||||||
onPress.dispose();
|
onPress.dispose();
|
||||||
content.removeEventListener(MouseEvent.CLICK, onMouseClick);
|
content.removeEventListener(MouseEvent.CLICK, onMouseClick);
|
||||||
content.removeEventListener(MouseEvent.MOUSE_UP, onMouseClick);
|
content.removeEventListener(MouseEvent.MOUSE_UP, onMouseClick);
|
||||||
content.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
|
content.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
|
||||||
content.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
|
content.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
|
||||||
content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
content.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
|
||||||
content.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
content.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,185 +8,198 @@ import haxework.gui.layout.ILayout;
|
|||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
|
|
||||||
class GroupView extends SpriteView implements IGroupView {
|
class GroupView extends SpriteView implements IGroupView {
|
||||||
public var container(get, null):DisplayObjectContainer;
|
public var container(get, null):DisplayObjectContainer;
|
||||||
|
|
||||||
public var views(default, set):Array<IView<Dynamic>>;
|
public var views(default, set):Array<IView<Dynamic>>;
|
||||||
public var layout(default, default):ILayout;
|
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;
|
|
||||||
|
|
||||||
private var viewsById:Map<String, IView<Dynamic>>;
|
public var layoutVAlign(default, set):VAlign;
|
||||||
|
public var layoutHAlign(default, set):HAlign;
|
||||||
|
public var layoutMargin(default, set):Float = 0;
|
||||||
|
|
||||||
public function new(?layout:ILayout) {
|
public var leftPadding(default, set):Float;
|
||||||
super();
|
public var rightPadding(default, set):Float;
|
||||||
this.layout = layout == null ? new DefaultLayout() : layout;
|
public var topPadding(default, set):Float;
|
||||||
paddings = 0;
|
public var bottomPadding(default, set):Float;
|
||||||
//layoutMargin = 0;
|
public var padding(null, set):Float;
|
||||||
layoutHAlign = HAlign.CENTER;
|
public var paddings(null, set):Array<Float>;
|
||||||
layoutVAlign = VAlign.MIDDLE;
|
|
||||||
views = [];
|
|
||||||
viewsById = new Map<String, IView<Dynamic>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline private function get_container():DisplayObjectContainer {
|
private var viewsById:Map<String, IView<Dynamic>>;
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function update():Void {
|
public function new(?layout:ILayout) {
|
||||||
layout.place(this, views);
|
super();
|
||||||
for (view in views) {
|
this.layout = layout == null ? new DefaultLayout() : layout;
|
||||||
view.update();
|
padding = 0;
|
||||||
if (view.index > -1) {
|
//layoutMargin = 0;
|
||||||
content.setChildIndex(view.content, view.index);
|
layoutHAlign = HAlign.CENTER;
|
||||||
}
|
layoutVAlign = VAlign.MIDDLE;
|
||||||
|
views = [];
|
||||||
|
viewsById = new Map<String, IView<Dynamic>>();
|
||||||
}
|
}
|
||||||
super.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
inline private function get_container():DisplayObjectContainer {
|
||||||
removeAllViews();
|
return content;
|
||||||
if (views == null) views = [];
|
|
||||||
for (view in value) addView(view);
|
|
||||||
return views;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addView(view:IView<Dynamic>):IView<Dynamic> {
|
|
||||||
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<Dynamic>, index:Int):IView<Dynamic> {
|
|
||||||
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<Dynamic>):IView<Dynamic> {
|
|
||||||
views.unshift(view);
|
|
||||||
viewsById.set(view.id, view);
|
|
||||||
content.addChild(view.content);
|
|
||||||
view.parent = this;
|
|
||||||
invalidate();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeView(view:IView<Dynamic>):IView<Dynamic> {
|
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function removeViewById(id:String):IView<Dynamic> {
|
override public function update():Void {
|
||||||
if (viewsById.exists(id)) {
|
layout.place(this, views);
|
||||||
return removeView(viewsById.get(id));
|
for (view in views) {
|
||||||
} else {
|
view.update();
|
||||||
return null;
|
if (view.index > -1) {
|
||||||
|
content.setChildIndex(view.content, view.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.update();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V> {
|
public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||||
var idd:Array<String> = id.split(":");
|
removeAllViews();
|
||||||
if (idd.length > 1) {
|
if (views == null) views = [];
|
||||||
var id0 = idd.shift();
|
for (view in value) addView(view);
|
||||||
if (viewsById.exists(id0)) {
|
return views;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function set_layoutVAlign(value:VAlign):VAlign {
|
public function addView(view:IView<Dynamic>):IView<Dynamic> {
|
||||||
if (layoutVAlign != value) {
|
views.push(view);
|
||||||
layoutVAlign = value;
|
viewsById.set(view.id, view);
|
||||||
invalidate();
|
if (view.content != null) content.addChild(view.content);
|
||||||
|
view.parent = this;
|
||||||
|
invalidate();
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
return layoutVAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_layoutHAlign(value:HAlign):HAlign {
|
public function insertView(view:IView<Dynamic>, index:Int):IView<Dynamic> {
|
||||||
if (layoutHAlign != value) {
|
if (index < 0) index = views.length + index;
|
||||||
layoutHAlign = value;
|
views.insert(index, view);
|
||||||
invalidate();
|
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 {
|
public function addViewFirst(view:IView<Dynamic>):IView<Dynamic> {
|
||||||
if (layoutMargin != value) {
|
views.unshift(view);
|
||||||
layoutMargin = value;
|
viewsById.set(view.id, view);
|
||||||
invalidate();
|
content.addChild(view.content);
|
||||||
|
view.parent = this;
|
||||||
|
invalidate();
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
return layoutMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_leftPadding(value:Float):Float {
|
public function removeView(view:IView<Dynamic>):IView<Dynamic> {
|
||||||
if (leftPadding != value) {
|
view.parent = null;
|
||||||
leftPadding = value;
|
viewsById.remove(view.id);
|
||||||
invalidate();
|
views.remove(view);
|
||||||
|
if (view.content != null) content.removeChild(view.content);
|
||||||
|
invalidate();
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
return leftPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_rightPadding(value:Float):Float {
|
public function removeAllViews():Void {
|
||||||
if (rightPadding != value) {
|
if (views != null) while (views.length > 0) {
|
||||||
rightPadding = value;
|
removeView(views[0]);
|
||||||
invalidate();
|
}
|
||||||
}
|
}
|
||||||
return rightPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_topPadding(value:Float):Float {
|
public function removeViewById(id:String):IView<Dynamic> {
|
||||||
if (topPadding != value) {
|
if (viewsById.exists(id)) {
|
||||||
topPadding = value;
|
return removeView(viewsById.get(id));
|
||||||
invalidate();
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return topPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_bottomPadding(value:Float):Float {
|
public function findViewById<V:IView<Dynamic>>(id:String, ?clazz:Class<V>):Null<V> {
|
||||||
if (bottomPadding != value) {
|
var idd:Array<String> = id.split(":");
|
||||||
bottomPadding = value;
|
if (idd.length > 1) {
|
||||||
invalidate();
|
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 {
|
private function set_layoutVAlign(value:VAlign):VAlign {
|
||||||
leftPadding = rightPadding = topPadding = bottomPadding = value;
|
if (layoutVAlign != value) {
|
||||||
invalidate();
|
layoutVAlign = value;
|
||||||
return 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<Float>):Array<Float> {
|
||||||
|
switch (value) {
|
||||||
|
case [m]:
|
||||||
|
leftPadding = rightPadding = topPadding = bottomPadding = m;
|
||||||
|
case [a, b]:
|
||||||
|
leftPadding = rightPadding = a;
|
||||||
|
topPadding = bottomPadding = b;
|
||||||
|
}
|
||||||
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,6 @@ interface HasPaddings {
|
|||||||
public var rightPadding(default, set):Float;
|
public var rightPadding(default, set):Float;
|
||||||
public var topPadding(default, set):Float;
|
public var topPadding(default, set):Float;
|
||||||
public var bottomPadding(default, set):Float;
|
public var bottomPadding(default, set):Float;
|
||||||
public var paddings(null, set):Float;
|
public var padding(null, set):Float;
|
||||||
}
|
public var paddings(null, set):Array<Float>;
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ interface IView<C:DisplayObject> {
|
|||||||
public var rightMargin(default, set):Float;
|
public var rightMargin(default, set):Float;
|
||||||
public var topMargin(default, set):Float;
|
public var topMargin(default, set):Float;
|
||||||
public var bottomMargin(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<Float>;
|
||||||
|
|
||||||
public var content(default, null):C;
|
public var content(default, null):C;
|
||||||
public var skin(default, set):SkinSet;
|
public var skin(default, set):SkinSet;
|
||||||
|
|||||||
@@ -2,17 +2,16 @@ package haxework.gui;
|
|||||||
|
|
||||||
import haxework.gui.core.HAlign;
|
import haxework.gui.core.HAlign;
|
||||||
import haxework.gui.core.VAlign;
|
import haxework.gui.core.VAlign;
|
||||||
import flash.text.TextFieldAutoSize;
|
|
||||||
|
|
||||||
class LabelView extends TextView {
|
class LabelView extends TextView {
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
fill = false;
|
fill = false;
|
||||||
textField.selectable = false;
|
textField.selectable = false;
|
||||||
textField.wordWrap = false;
|
textField.wordWrap = false;
|
||||||
textField.multiline = true;
|
textField.multiline = true;
|
||||||
layoutHAlign = HAlign.CENTER;
|
layoutHAlign = HAlign.CENTER;
|
||||||
layoutVAlign = VAlign.MIDDLE;
|
layoutVAlign = VAlign.MIDDLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,17 @@ class SpriteView extends View<Sprite> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override public function update():Void {
|
override public function update():Void {
|
||||||
super.update();
|
|
||||||
this.content.graphics.clear();
|
this.content.graphics.clear();
|
||||||
for (skin in this.skin) {
|
super.update();
|
||||||
skin.draw(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if dev_layout
|
#if dev_layout
|
||||||
override public function update():Void {
|
override public function update():Void {
|
||||||
super.update();
|
super.update();
|
||||||
var g:Graphics = content.graphics;
|
var g:Graphics = content.graphics;
|
||||||
g.lineStyle(1, 0x00ff00);
|
g.lineStyle(1, 0x00ff00);
|
||||||
g.drawRect(0, 0, width, height);
|
g.drawRect(0, 0, width, height);
|
||||||
g.lineStyle();
|
g.lineStyle();
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,275 +11,288 @@ import flash.text.TextField;
|
|||||||
|
|
||||||
class TextView extends SpriteView implements ITextView {
|
class TextView extends SpriteView implements ITextView {
|
||||||
|
|
||||||
public var textField(default, null):TextField;
|
public var textField(default, null):TextField;
|
||||||
public var text(get, set):String;
|
public var text(get, set):String;
|
||||||
private var _text:String;
|
private var _text:String;
|
||||||
public var align(default, set):TextFormatAlign;
|
public var align(default, set):TextFormatAlign;
|
||||||
public var fontFamily(default, set):String;
|
public var fontFamily(default, set):String;
|
||||||
public var fontEmbed(default, set):Bool;
|
public var fontEmbed(default, set):Bool;
|
||||||
public var fontColor(default, set):Int;
|
public var fontColor(default, set):Int;
|
||||||
public var fontSize(default, set):Int;
|
public var fontSize(default, set):Int;
|
||||||
public var fontBold(default, set):Bool;
|
public var fontBold(default, set):Bool;
|
||||||
|
|
||||||
public var layoutHAlign(default, set):HAlign;
|
public var layoutHAlign(default, set):HAlign;
|
||||||
public var layoutVAlign(default, set):VAlign;
|
public var layoutVAlign(default, set):VAlign;
|
||||||
public var fill(default, set):Bool = true;
|
public var fill(default, set):Bool = true;
|
||||||
|
|
||||||
public var leftPadding(default, set):Float = 0.0;
|
public var leftPadding(default, set):Float = 0.0;
|
||||||
public var rightPadding(default, set):Float = 0.0;
|
public var rightPadding(default, set):Float = 0.0;
|
||||||
public var topPadding(default, set):Float = 0.0;
|
public var topPadding(default, set):Float = 0.0;
|
||||||
public var bottomPadding(default, set):Float = 0.0;
|
public var bottomPadding(default, set):Float = 0.0;
|
||||||
public var paddings(null, set):Float = 0.0;
|
public var padding(null, set):Float;
|
||||||
|
public var paddings(null, set):Array<Float>;
|
||||||
|
|
||||||
public var shadow(default, set):Bool;
|
public var shadow(default, set):Bool;
|
||||||
public var shadowColor(default, set):Int;
|
public var shadowColor(default, set):Int;
|
||||||
|
|
||||||
private var textFormat:TextFormat;
|
private var textFormat:TextFormat;
|
||||||
|
|
||||||
private var _textWidth:Float;
|
private var _textWidth:Float;
|
||||||
private var _textHeight:Float;
|
private var _textHeight:Float;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
layoutHAlign = HAlign.CENTER;
|
layoutHAlign = HAlign.CENTER;
|
||||||
layoutVAlign = VAlign.MIDDLE;
|
layoutVAlign = VAlign.MIDDLE;
|
||||||
textField = buildTextField();
|
textField = buildTextField();
|
||||||
textField.width = 1;
|
textField.width = 1;
|
||||||
textField.height = 1;
|
textField.height = 1;
|
||||||
textField.multiline = true;
|
textField.multiline = true;
|
||||||
textField.wordWrap = true;
|
textField.wordWrap = true;
|
||||||
#if dev_layout
|
#if dev_layout
|
||||||
textField.borderColor = 0xff0000;
|
textField.borderColor = 0xff0000;
|
||||||
textField.border = true;
|
textField.border = true;
|
||||||
#end
|
#end
|
||||||
textFormat = textField.defaultTextFormat;
|
textFormat = textField.defaultTextFormat;
|
||||||
textFormat.font = "Arial";
|
textFormat.font = "Arial";
|
||||||
textFormat.size = 16;
|
textFormat.size = 16;
|
||||||
textFormat.leading = 0;
|
textFormat.leading = 0;
|
||||||
textFormat.align = TextFormatAlign.CENTER;
|
textFormat.align = TextFormatAlign.CENTER;
|
||||||
content.addChild(textField);
|
content.addChild(textField);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildTextField():TextField {
|
private function buildTextField():TextField {
|
||||||
#if bitmap_text
|
#if bitmap_text
|
||||||
return new BitmapTextField();
|
return new BitmapTextField();
|
||||||
#else
|
#else
|
||||||
return new TextField();
|
return new TextField();
|
||||||
#end
|
#end
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fill(value:Bool):Bool {
|
|
||||||
if (fill != value) {
|
|
||||||
fill = value;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return fill;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_layoutHAlign(value:HAlign):HAlign {
|
private function set_fill(value:Bool):Bool {
|
||||||
if (layoutHAlign != value) {
|
if (fill != value) {
|
||||||
layoutHAlign = value;
|
fill = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return fill;
|
||||||
}
|
}
|
||||||
return layoutHAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_layoutVAlign(value:VAlign):VAlign {
|
private function set_layoutHAlign(value:HAlign):HAlign {
|
||||||
if (layoutVAlign != value) {
|
if (layoutHAlign != value) {
|
||||||
layoutVAlign = value;
|
layoutHAlign = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return layoutHAlign;
|
||||||
}
|
}
|
||||||
return layoutVAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_text():String {
|
private function set_layoutVAlign(value:VAlign):VAlign {
|
||||||
return textField.text;
|
if (layoutVAlign != value) {
|
||||||
}
|
layoutVAlign = value;
|
||||||
|
invalidate();
|
||||||
private function set_text(value:String):String {
|
}
|
||||||
if (_text != value) {
|
return layoutVAlign;
|
||||||
_text = value;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return _text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_align(value:TextFormatAlign):TextFormatAlign {
|
private function get_text():String {
|
||||||
if (align != value) {
|
return textField.text;
|
||||||
align = value;
|
|
||||||
textFormat.align = value;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return align;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontFamily(value:String):String {
|
private function set_text(value:String):String {
|
||||||
if (fontFamily != value) {
|
if (_text != value) {
|
||||||
fontFamily = value;
|
_text = value;
|
||||||
textFormat.font = fontFamily;
|
invalidate();
|
||||||
invalidate();
|
}
|
||||||
|
return _text;
|
||||||
}
|
}
|
||||||
return fontFamily;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontEmbed(value:Bool):Bool {
|
private function set_align(value:TextFormatAlign):TextFormatAlign {
|
||||||
if (fontEmbed != value) {
|
if (align != value) {
|
||||||
fontEmbed = value;
|
align = value;
|
||||||
invalidate();
|
textFormat.align = value;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return align;
|
||||||
}
|
}
|
||||||
return fontEmbed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontColor(value:Int):Int {
|
private function set_fontFamily(value:String):String {
|
||||||
if (fontColor != value) {
|
if (fontFamily != value) {
|
||||||
fontColor = value;
|
fontFamily = value;
|
||||||
textFormat.color = fontColor;
|
textFormat.font = fontFamily;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontFamily;
|
||||||
}
|
}
|
||||||
return fontColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontSize(value:Int):Int {
|
private function set_fontEmbed(value:Bool):Bool {
|
||||||
if (fontSize != value) {
|
if (fontEmbed != value) {
|
||||||
fontSize = value;
|
fontEmbed = value;
|
||||||
textFormat.size = fontSize;
|
invalidate();
|
||||||
invalidate();
|
}
|
||||||
|
return fontEmbed;
|
||||||
}
|
}
|
||||||
return fontSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_fontBold(value:Bool):Bool {
|
private function set_fontColor(value:Int):Int {
|
||||||
if (fontBold != value) {
|
if (fontColor != value) {
|
||||||
fontBold = value;
|
fontColor = value;
|
||||||
textFormat.bold = fontBold;
|
textFormat.color = fontColor;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontColor;
|
||||||
}
|
}
|
||||||
return fontBold;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function currentText():String {
|
private function set_fontSize(value:Int):Int {
|
||||||
return _text;
|
if (fontSize != value) {
|
||||||
}
|
fontSize = value;
|
||||||
|
textFormat.size = fontSize;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
private function updateTextSize():Void {
|
private function set_fontBold(value:Bool):Bool {
|
||||||
var size = TextUtil.getSize(textField);
|
if (fontBold != value) {
|
||||||
_textWidth = size.x;
|
fontBold = value;
|
||||||
_textHeight = size.y;
|
textFormat.bold = fontBold;
|
||||||
}
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontBold;
|
||||||
|
}
|
||||||
|
|
||||||
override public function update():Void {
|
private function currentText():String {
|
||||||
textField.embedFonts = fontEmbed;
|
return _text;
|
||||||
textField.defaultTextFormat = textFormat;
|
}
|
||||||
textField.autoSize = fill ? TextFieldAutoSize.NONE : TextFieldAutoSize.LEFT;
|
|
||||||
var t:String = currentText();
|
private function updateTextSize():Void {
|
||||||
if (t != null) textField.text = t;
|
var size = TextUtil.getSize(textField);
|
||||||
textField.setTextFormat(textFormat);
|
_textWidth = size.x;
|
||||||
updateTextSize();
|
_textHeight = size.y;
|
||||||
if (contentSize && _text != null && _text.length > 0) {
|
}
|
||||||
#if html5
|
|
||||||
|
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 h = _textHeight;
|
||||||
var w = _textWidth;
|
var w = _textWidth;
|
||||||
//if (h > textFormat.size * 1.5) h = h / 2;
|
//if (h > textFormat.size * 1.5) h = h / 2;
|
||||||
textField.height = h;
|
textField.height = h;
|
||||||
textField.width = w;
|
textField.width = w;
|
||||||
#end
|
#end
|
||||||
width = textField.width + leftPadding + rightPadding;
|
width = textField.width + leftPadding + rightPadding;
|
||||||
height = textField.height + topPadding + bottomPadding;
|
height = textField.height + topPadding + bottomPadding;
|
||||||
textField.x = leftPadding;
|
textField.x = leftPadding;
|
||||||
textField.y = topPadding;
|
textField.y = topPadding;
|
||||||
} else {
|
} else {
|
||||||
placeTextField(textField);
|
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 {
|
private function placeTextField(textField:TextField):Void {
|
||||||
textField.width = width;
|
textField.width = width;
|
||||||
textField.height = _textHeight;
|
textField.height = _textHeight;
|
||||||
|
|
||||||
textField.x = switch (layoutHAlign) {
|
textField.x = switch (layoutHAlign) {
|
||||||
case HAlign.NONE: 0;
|
case HAlign.NONE: 0;
|
||||||
case HAlign.LEFT: leftPadding;
|
case HAlign.LEFT: leftPadding;
|
||||||
case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding;
|
case HAlign.CENTER: (width - textField.width) / 2 + leftPadding - rightPadding;
|
||||||
case HAlign.RIGHT: width - textField.width - rightPadding;
|
case HAlign.RIGHT: width - textField.width - rightPadding;
|
||||||
default: 0;
|
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;
|
override private function set_mouseEnabled(value:Bool):Bool {
|
||||||
case VAlign.TOP: topPadding;
|
textField.mouseEnabled = value;
|
||||||
case VAlign.MIDDLE: (height - _textHeight) / 2 + topPadding - bottomPadding;
|
return super.set_mouseEnabled(value);
|
||||||
case VAlign.BOTTOM: height - _textHeight - bottomPadding;
|
|
||||||
default: 0;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override private function set_mouseEnabled(value:Bool):Bool {
|
|
||||||
textField.mouseEnabled = value;
|
|
||||||
return super.set_mouseEnabled(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function set_leftPadding(value:Float):Float {
|
private function set_leftPadding(value:Float):Float {
|
||||||
if (leftPadding != value) {
|
if (leftPadding != value) {
|
||||||
leftPadding = value;
|
leftPadding = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return leftPadding;
|
||||||
}
|
}
|
||||||
return leftPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_rightPadding(value:Float):Float {
|
private function set_rightPadding(value:Float):Float {
|
||||||
if (rightPadding != value) {
|
if (rightPadding != value) {
|
||||||
rightPadding = value;
|
rightPadding = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return rightPadding;
|
||||||
}
|
}
|
||||||
return rightPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_topPadding(value:Float):Float {
|
private function set_topPadding(value:Float):Float {
|
||||||
if (topPadding != value) {
|
if (topPadding != value) {
|
||||||
topPadding = value;
|
topPadding = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return topPadding;
|
||||||
}
|
}
|
||||||
return topPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_bottomPadding(value:Float):Float {
|
private function set_bottomPadding(value:Float):Float {
|
||||||
if (bottomPadding != value) {
|
if (bottomPadding != value) {
|
||||||
bottomPadding = value;
|
bottomPadding = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
}
|
||||||
|
return bottomPadding;
|
||||||
}
|
}
|
||||||
return bottomPadding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_paddings(value:Float):Float {
|
private function set_padding(value:Float):Float {
|
||||||
leftPadding = rightPadding = topPadding = bottomPadding = value;
|
paddings = [value];
|
||||||
invalidate();
|
return value;
|
||||||
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) {
|
private function set_paddings(value:Array<Float>):Array<Float> {
|
||||||
if (Std.is(textField, BitmapTextField)) {
|
switch (value) {
|
||||||
cast(textField, BitmapTextField).shadowColor = value;
|
case [m]:
|
||||||
cast(textField, BitmapTextField).shadow = true;
|
leftPadding = rightPadding = topPadding = bottomPadding = m;
|
||||||
return cast(textField, BitmapTextField).shadowColor;
|
case [a, b]:
|
||||||
} else {
|
leftPadding = rightPadding = a;
|
||||||
return value;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,334 +1,346 @@
|
|||||||
package haxework.gui;
|
package haxework.gui;
|
||||||
|
|
||||||
import haxework.gui.skin.ISkin.SkinSet;
|
import Array;
|
||||||
import flash.display.InteractiveObject;
|
|
||||||
import flash.display.DisplayObject;
|
import flash.display.DisplayObject;
|
||||||
import haxework.gui.core.SizeType;
|
import flash.display.InteractiveObject;
|
||||||
import haxework.gui.core.HAlign;
|
|
||||||
import haxework.gui.core.VAlign;
|
|
||||||
import flash.events.Event;
|
|
||||||
import flash.display.Stage;
|
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<C:DisplayObject> implements IView<C> {
|
class View<C:DisplayObject> implements IView<C> {
|
||||||
|
|
||||||
private static var counter:Int = 0;
|
private static var counter:Int = 0;
|
||||||
public static var updater(default, null):Updater = new Updater();
|
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 x(default, set):Float;
|
||||||
public var y(default, set):Float;
|
public var y(default, set):Float;
|
||||||
|
|
||||||
public var w(default, set):Float;
|
public var w(default, set):Float;
|
||||||
public var h(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 widthType(default, null):SizeType;
|
||||||
public var heightType(default, null):SizeType;
|
public var heightType(default, null):SizeType;
|
||||||
|
|
||||||
public var width(get, set):Float;
|
public var width(get, set):Float;
|
||||||
public var height(get, set):Float;
|
public var height(get, set):Float;
|
||||||
|
|
||||||
public var pWidth(default, set):Float;
|
public var pWidth(default, set):Float;
|
||||||
public var pHeight(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 hAlign(default, set):HAlign;
|
||||||
public var vAlign(default, set):VAlign;
|
public var vAlign(default, set):VAlign;
|
||||||
|
|
||||||
public var leftMargin(default, set):Float;
|
public var leftMargin(default, set):Float;
|
||||||
public var rightMargin(default, set):Float;
|
public var rightMargin(default, set):Float;
|
||||||
public var topMargin(default, set):Float;
|
public var topMargin(default, set):Float;
|
||||||
public var bottomMargin(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<Float>;
|
||||||
|
|
||||||
public var content(default, null):C;
|
public var content(default, null):C;
|
||||||
public var skin(default, set):SkinSet;
|
public var skin(default, set):SkinSet;
|
||||||
|
|
||||||
public var parent(default, null):Null<IGroupView>;
|
public var parent(default, null):Null<IGroupView>;
|
||||||
public var inLayout(default, set):Bool;
|
public var inLayout(default, set):Bool;
|
||||||
|
|
||||||
public var visible(default, set):Bool;
|
public var visible(default, set):Bool;
|
||||||
public var index(default, set):Int;
|
public var index(default, set):Int;
|
||||||
public var mouseEnabled(default, set):Bool = true;
|
public var mouseEnabled(default, set):Bool = true;
|
||||||
|
|
||||||
public function new(content:C) {
|
public function new(content:C) {
|
||||||
id = Type.getClassName(Type.getClass(this)) + counter++;
|
id = Type.getClassName(Type.getClass(this)) + counter++;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
width = 1;
|
width = 1;
|
||||||
height = 1;
|
height = 1;
|
||||||
margins = 0;
|
margin = 0;
|
||||||
vAlign = VAlign.NONE;
|
vAlign = VAlign.NONE;
|
||||||
hAlign = HAlign.NONE;
|
hAlign = HAlign.NONE;
|
||||||
inLayout = true;
|
inLayout = true;
|
||||||
visible = true;
|
visible = true;
|
||||||
index = -1;
|
index = -1;
|
||||||
skin = [];
|
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;
|
|
||||||
}
|
}
|
||||||
/*var skin:ISkin<Dynamic> = currentSkin();
|
|
||||||
if (contentSize && skin != null && Std.is(skin, ISize)) {
|
public function invalidate():Void {
|
||||||
var size:ISize = cast(skin, ISize);
|
updater.invalidate(this);
|
||||||
if (!Math.isNaN(size.width)) width = size.width;
|
|
||||||
if (!Math.isNaN(size.height)) height = size.height;
|
|
||||||
}
|
}
|
||||||
if (skin != null) skin.draw(this);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public function remove():Void {
|
private function invalidateParent():Void {
|
||||||
if (parent != null) parent.removeView(this);
|
if (parent != null)
|
||||||
}
|
updater.invalidate(parent);
|
||||||
|
|
||||||
private function set_x(value:Float):Float {
|
|
||||||
if (x != value) {
|
|
||||||
x = value;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return x;
|
|
||||||
}
|
public function update():Void {
|
||||||
private function set_y(value:Float):Float {
|
if (content != null) {
|
||||||
if (y != value) {
|
content.x = x;
|
||||||
y = value;
|
content.y = y;
|
||||||
invalidate();
|
}
|
||||||
|
for (skin in this.skin) {
|
||||||
|
skin.draw(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_w(value:Float):Float {
|
public function remove():Void {
|
||||||
if (w != value) {
|
if (parent != null) parent.removeView(this);
|
||||||
w = value;
|
|
||||||
if (!Math.isNaN(r) && r > 0) h = w / r;
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
return w;
|
|
||||||
}
|
private function set_x(value:Float):Float {
|
||||||
private function set_h(value:Float):Float {
|
if (x != value) {
|
||||||
if (h != value) {
|
x = value;
|
||||||
h = value;
|
invalidate();
|
||||||
if (!Math.isNaN(r) && r > 0) w = h * r;
|
}
|
||||||
invalidate();
|
return x;
|
||||||
}
|
}
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_r(value:Float):Float {
|
private function set_y(value:Float):Float {
|
||||||
if (r != value) {
|
if (y != value) {
|
||||||
r = value;
|
y = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
invalidateParent();
|
}
|
||||||
|
return y;
|
||||||
}
|
}
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function get_width():Float {
|
private function set_w(value:Float):Float {
|
||||||
return w;
|
if (w != value) {
|
||||||
}
|
w = value;
|
||||||
|
if (!Math.isNaN(r) && r > 0) h = w / r;
|
||||||
private function get_height():Float {
|
invalidate();
|
||||||
return h;
|
}
|
||||||
}
|
return w;
|
||||||
|
|
||||||
private function set_width(value:Float):Float {
|
|
||||||
if (w != value || widthType != SizeType.NORMAL) {
|
|
||||||
w = value;
|
|
||||||
widthType = SizeType.NORMAL;
|
|
||||||
invalidate();
|
|
||||||
invalidateParent();
|
|
||||||
}
|
}
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_height(value:Float):Float {
|
private function set_h(value:Float):Float {
|
||||||
if (h != value || heightType != SizeType.NORMAL) {
|
if (h != value) {
|
||||||
h = value;
|
h = value;
|
||||||
heightType = SizeType.NORMAL;
|
if (!Math.isNaN(r) && r > 0) w = h * r;
|
||||||
invalidate();
|
invalidate();
|
||||||
invalidateParent();
|
}
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_pWidth(value:Float):Float {
|
private function set_r(value:Float):Float {
|
||||||
if (pWidth != value || widthType != SizeType.PERCENT) {
|
if (r != value) {
|
||||||
pWidth = value;
|
r = value;
|
||||||
widthType = SizeType.PERCENT;
|
invalidate();
|
||||||
invalidate();
|
invalidateParent();
|
||||||
invalidateParent();
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
return pWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_pHeight(value:Float):Float {
|
private function get_width():Float {
|
||||||
if (pHeight != value || heightType != SizeType.PERCENT) {
|
return w;
|
||||||
pHeight = value;
|
|
||||||
heightType = SizeType.PERCENT;
|
|
||||||
invalidate();
|
|
||||||
invalidateParent();
|
|
||||||
}
|
}
|
||||||
return pHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_contentSize(value:Bool):Bool {
|
private function get_height():Float {
|
||||||
if (contentSize != value) {
|
return h;
|
||||||
contentSize = value;
|
|
||||||
invalidate();
|
|
||||||
invalidateParent();
|
|
||||||
}
|
}
|
||||||
return contentSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_hAlign(value:HAlign):HAlign {
|
private function set_width(value:Float):Float {
|
||||||
if (hAlign != value) {
|
if (w != value || widthType != SizeType.NORMAL) {
|
||||||
hAlign = value;
|
w = value;
|
||||||
invalidate();
|
widthType = SizeType.NORMAL;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return w;
|
||||||
}
|
}
|
||||||
return hAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_vAlign(value:VAlign):VAlign {
|
private function set_height(value:Float):Float {
|
||||||
if (vAlign != value) {
|
if (h != value || heightType != SizeType.NORMAL) {
|
||||||
vAlign = value;
|
h = value;
|
||||||
invalidate();
|
heightType = SizeType.NORMAL;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
return vAlign;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_leftMargin(value:Float):Float {
|
private function set_pWidth(value:Float):Float {
|
||||||
if (leftMargin != value) {
|
if (pWidth != value || widthType != SizeType.PERCENT) {
|
||||||
leftMargin = value;
|
pWidth = value;
|
||||||
invalidate();
|
widthType = SizeType.PERCENT;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return pWidth;
|
||||||
}
|
}
|
||||||
return leftMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_rightMargin(value:Float):Float {
|
private function set_pHeight(value:Float):Float {
|
||||||
if (rightMargin != value) {
|
if (pHeight != value || heightType != SizeType.PERCENT) {
|
||||||
rightMargin = value;
|
pHeight = value;
|
||||||
invalidate();
|
heightType = SizeType.PERCENT;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return pHeight;
|
||||||
}
|
}
|
||||||
return rightMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_topMargin(value:Float):Float {
|
private function set_contentSize(value:Bool):Bool {
|
||||||
if (topMargin != value) {
|
if (contentSize != value) {
|
||||||
topMargin = value;
|
contentSize = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
invalidateParent();
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return contentSize;
|
||||||
}
|
}
|
||||||
return topMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_bottomMargin(value:Float):Float {
|
private function set_hAlign(value:HAlign):HAlign {
|
||||||
if (bottomMargin != value) {
|
if (hAlign != value) {
|
||||||
bottomMargin = value;
|
hAlign = value;
|
||||||
invalidate();
|
invalidate();
|
||||||
invalidateParent();
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return hAlign;
|
||||||
}
|
}
|
||||||
return bottomMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_margins(value:Float):Float {
|
private function set_vAlign(value:VAlign):VAlign {
|
||||||
leftMargin = rightMargin = topMargin = bottomMargin = value;
|
if (vAlign != value) {
|
||||||
invalidate();
|
vAlign = value;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
return value;
|
invalidateParent();
|
||||||
}
|
}
|
||||||
|
return vAlign;
|
||||||
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 {
|
private function set_leftMargin(value:Float):Float {
|
||||||
if (visible != value) {
|
if (leftMargin != value) {
|
||||||
visible = value;
|
leftMargin = value;
|
||||||
if (content != null) content.visible = visible;
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return leftMargin;
|
||||||
}
|
}
|
||||||
return visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_index(value:Int):Int {
|
private function set_rightMargin(value:Float):Float {
|
||||||
if (index != value) {
|
if (rightMargin != value) {
|
||||||
index = value;
|
rightMargin = value;
|
||||||
invalidateParent();
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return rightMargin;
|
||||||
}
|
}
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function set_mouseEnabled(value:Bool):Bool {
|
private function set_topMargin(value:Float):Float {
|
||||||
if (mouseEnabled != value) {
|
if (topMargin != value) {
|
||||||
mouseEnabled = value;
|
topMargin = value;
|
||||||
if (content != null && Std.is(content, InteractiveObject)) {
|
invalidate();
|
||||||
cast(content, InteractiveObject).mouseEnabled = mouseEnabled;
|
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<Float>):Array<Float> {
|
||||||
|
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 {
|
class Updater {
|
||||||
|
|
||||||
public var stage(null, set):Stage;
|
public var stage(null, set):Stage;
|
||||||
private var invalidated:Array<IView<Dynamic>>;
|
private var invalidated:Array<IView<Dynamic>>;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
invalidated = [];
|
invalidated = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function set_stage(value:Stage):Stage {
|
private function set_stage(value:Stage):Stage {
|
||||||
value.addEventListener(Event.ENTER_FRAME, update);
|
value.addEventListener(Event.ENTER_FRAME, update);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invalidate(view:IView<Dynamic>):Void {
|
public function invalidate(view:IView<Dynamic>):Void {
|
||||||
if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view);
|
if (Lambda.indexOf(invalidated, view) == -1) invalidated.push(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(?_):Void {
|
public function update(?_):Void {
|
||||||
var t = Date.now().getTime();
|
var t = Date.now().getTime();
|
||||||
while (invalidated.length > 0) {
|
while (invalidated.length > 0) {
|
||||||
var v = null;
|
var v = null;
|
||||||
try {
|
try {
|
||||||
v = invalidated.shift();
|
v = invalidated.shift();
|
||||||
v.update();
|
v.update();
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
L.e("Update", v + "", error);
|
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 + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,78 @@
|
|||||||
package haxework.gui.frame;
|
package haxework.gui.frame;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
import haxework.animate.IAnimate;
|
import haxework.animate.IAnimate;
|
||||||
import haxework.gui.IView;
|
import haxework.gui.IView;
|
||||||
import haxework.gui.GroupView;
|
import haxework.gui.GroupView;
|
||||||
|
|
||||||
class FrameSwitcher extends GroupView implements IFrameSwitcher {
|
class FrameSwitcher extends GroupView implements IFrameSwitcher {
|
||||||
|
|
||||||
public var current(default, null):Null<IView<Dynamic>>;
|
public var current(default, null):Null<IView<Dynamic>>;
|
||||||
private var frames:Map<String, IView<Dynamic>>;
|
public var onSwitch:Signal<IView<Dynamic>> = new Signal();
|
||||||
|
|
||||||
public var animateFactory(default, default):Class<IAnimate>;
|
private var frames:Map<String, IView<Dynamic>>;
|
||||||
private var animate:IAnimate;
|
|
||||||
|
|
||||||
public function new() {
|
public var animateFactory(default, default):Class<IAnimate>;
|
||||||
super();
|
private var animate:IAnimate;
|
||||||
frames = new Map<String, IView<Dynamic>>();
|
|
||||||
current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function buildAnimate(view:IView<Dynamic>):Null<IAnimate> {
|
public function new() {
|
||||||
if (animateFactory != null) {
|
super();
|
||||||
return Type.createInstance(animateFactory, [view]);
|
frames = new Map<String, IView<Dynamic>>();
|
||||||
|
current = null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function change(id:String):IView<Dynamic> {
|
private function buildAnimate(view:IView<Dynamic>):Null<IAnimate> {
|
||||||
var prev = null;
|
if (animateFactory != null) {
|
||||||
if (current != null) {
|
return Type.createInstance(animateFactory, [view]);
|
||||||
if (current.id == id) return current;
|
}
|
||||||
prev = current;
|
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<IView<Dynamic>>):Void {
|
public function change(id:String):IView<Dynamic> {
|
||||||
if (prev != null) {
|
var prev = null;
|
||||||
var onHideMethod:Dynamic = Reflect.field(prev, "onHide");
|
if (current != null) {
|
||||||
if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []);
|
if (current.id == id) return current;
|
||||||
removeView(prev);
|
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<IView<Dynamic>>):Array<IView<Dynamic>> {
|
private function removePrev(prev:Null<IView<Dynamic>>):Void {
|
||||||
views = [];
|
if (prev != null) {
|
||||||
if (value.length > 0) {
|
var onHideMethod:Dynamic = Reflect.field(prev, "onHide");
|
||||||
for (view in value) {
|
if (onHideMethod != null) Reflect.callMethod(prev, onHideMethod, []);
|
||||||
view.pWidth = 100;
|
removeView(prev);
|
||||||
view.pHeight = 100;
|
}
|
||||||
frames.set(view.id, view);
|
}
|
||||||
}
|
|
||||||
|
override public function set_views(value:Array<IView<Dynamic>>):Array<IView<Dynamic>> {
|
||||||
|
views = [];
|
||||||
|
if (value.length > 0) {
|
||||||
|
for (view in value) {
|
||||||
|
view.pWidth = 100;
|
||||||
|
view.pHeight = 100;
|
||||||
|
frames.set(view.id, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import haxework.gui.list.ListView.IListItemView;
|
|||||||
|
|
||||||
class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
||||||
|
|
||||||
public var item_index(default, set):Int;
|
public var item_index(default, default):Int;
|
||||||
public var data(default, set):T;
|
public var data(default, set):T;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
@@ -15,16 +15,10 @@ class LabelListItem<T> extends LabelView implements IListItemView<T> {
|
|||||||
pWidth = 100;
|
pWidth = 100;
|
||||||
layoutHAlign = LEFT;
|
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 {
|
private function set_data(value:T):T {
|
||||||
data = value;
|
data = value;
|
||||||
text = Std.string(value);
|
text = Std.string(value);
|
||||||
|
skin = item_index % 2 == 1 ? [new ColorSkin(0xdddddd)] : [new ColorSkin(0xcccccc)];
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ class ButtonColorSkin implements ISkin<ButtonView> {
|
|||||||
private function set_color(value:Int):Int {
|
private function set_color(value:Int):Int {
|
||||||
colors = new Map<ButtonState, Int>();
|
colors = new Map<ButtonState, Int>();
|
||||||
colors.set(ButtonState.UP, value);
|
colors.set(ButtonState.UP, value);
|
||||||
colors.set(ButtonState.DOWN, ColorUtils.diff(value, -64));
|
colors.set(ButtonState.DOWN, ColorUtils.diff(value, -32));
|
||||||
colors.set(ButtonState.OVER, ColorUtils.diff(value, 64));
|
colors.set(ButtonState.OVER, ColorUtils.diff(value, 32));
|
||||||
//disable = ColorUtils.multiply(value, 0.6);
|
//disable = ColorUtils.multiply(value, 0.6);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,8 @@ class ButtonColorSkin implements ISkin<ButtonView> {
|
|||||||
var color:Int = selectColor(view);
|
var color:Int = selectColor(view);
|
||||||
var graphics:Graphics = view.content.graphics;
|
var graphics:Graphics = view.content.graphics;
|
||||||
graphics.beginFill(color, alpha);
|
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 {
|
private function selectColor(view:ButtonView):Int {
|
||||||
|
|||||||
@@ -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<ButtonView> {
|
|
||||||
return new ButtonColorSkin(color, alpha);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,4 +23,12 @@ class Skin {
|
|||||||
public static function text(fontColor:Int, fontSize:Int, fontFamily:String = null):ISkin<ITextView> {
|
public static function text(fontColor:Int, fontSize:Int, fontFamily:String = null):ISkin<ITextView> {
|
||||||
return new TextSkin(fontColor, fontSize, fontFamily);
|
return new TextSkin(fontColor, fontSize, fontFamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function buttonColor(color: Int, alpha: Float = 1.0): ISkin<ButtonView> {
|
||||||
|
return new ButtonColorSkin(color, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function tabColor(color: Int, alpha: Float = 1.0): ISkin<ButtonView> {
|
||||||
|
return new TabColorSkin(color, alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main/haxework/gui/skin/TabColorSkin.hx
Normal file
20
src/main/haxework/gui/skin/TabColorSkin.hx
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user