addded text view
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"type":"haxework.gui.HGroupView",
|
"type":"haxework.gui.VGroupView",
|
||||||
"layoutHAlign":"~haxework.gui.core.HAlign:CENTER",
|
"layoutHAlign":"~haxework.gui.core.HAlign:CENTER",
|
||||||
"layoutVAlign":"~haxework.gui.core.VAlign:MIDDLE",
|
"layoutVAlign":"~haxework.gui.core.VAlign:MIDDLE",
|
||||||
"paddings":20,
|
"paddings":20,
|
||||||
"layoutMargin":100,
|
"layoutMargin":10,
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"},
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xff0000"},
|
||||||
"views":[
|
"views":[
|
||||||
{
|
{
|
||||||
@@ -22,6 +22,41 @@
|
|||||||
"leftMargin":5,
|
"leftMargin":5,
|
||||||
"rightMargin":10,
|
"rightMargin":10,
|
||||||
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x0000ff"}
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x0000ff"}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"haxework.gui.HGroupView",
|
||||||
|
"layoutHAlign":"~haxework.gui.core.HAlign:LEFT",
|
||||||
|
"layoutVAlign":"~haxework.gui.core.VAlign:MIDDLE",
|
||||||
|
"pWidth":100,
|
||||||
|
"height":30,
|
||||||
|
"paddings":3,
|
||||||
|
"layoutMargin":3,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0xffff00"},
|
||||||
|
"views":[
|
||||||
|
{
|
||||||
|
"type":"haxework.gui.LabelView",
|
||||||
|
"width":100,
|
||||||
|
"pHeight":100,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ffff"},
|
||||||
|
"text":"Text1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"haxework.gui.LabelView",
|
||||||
|
"contentSize":true,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ffff"},
|
||||||
|
"text":"Text2",
|
||||||
|
"fontFamily":"Georgia",
|
||||||
|
"fontColor":"0xffffff"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"haxework.gui.LabelView",
|
||||||
|
"contentSize":true,
|
||||||
|
"skin":{"type":"haxework.gui.skin.ColorSkin", "color":"0x00ffff"},
|
||||||
|
"text":"Text 3333333333 ddd",
|
||||||
|
"fontFamily":"Tahoma",
|
||||||
|
"fontColor":"0xff0000"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,15 @@
|
|||||||
package haxework.gui;
|
package haxework.gui;
|
||||||
|
|
||||||
|
|
||||||
|
//ToDo:
|
||||||
|
import haxework.gui.View;
|
||||||
|
import haxework.gui.GroupView;
|
||||||
|
import haxework.gui.HGroupView;
|
||||||
|
import haxework.gui.VGroupView;
|
||||||
|
import haxework.gui.TextView;
|
||||||
|
import haxework.gui.LabelView;
|
||||||
|
import haxework.gui.skin.ColorSkin;
|
||||||
|
|
||||||
class GuiBuilder {
|
class GuiBuilder {
|
||||||
|
|
||||||
private function new() {}
|
private function new() {}
|
||||||
@@ -27,9 +36,13 @@ class GuiBuilder {
|
|||||||
var a:Array<String> = s.substr(1).split(":");
|
var a:Array<String> = s.substr(1).split(":");
|
||||||
var e:Enum<Dynamic> = Type.resolveEnum(a[0]);
|
var e:Enum<Dynamic> = Type.resolveEnum(a[0]);
|
||||||
value = Type.createEnum(e, a[1]);
|
value = Type.createEnum(e, a[1]);
|
||||||
|
} else if (~/0x[A-Fa-f\d]{6}/.match(value)) {
|
||||||
|
value = Std.parseInt(value);
|
||||||
}
|
}
|
||||||
} else if (Std.is(value, Float)) {
|
} else if (Std.is(value, Float)) {
|
||||||
|
|
||||||
|
} else if (Std.is(value, Bool)) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var o:Dynamic = build(value);
|
var o:Dynamic = build(value);
|
||||||
fill(o, value);
|
fill(o, value);
|
||||||
|
|||||||
9
haxework/gui/ITextView.hx
Executable file
9
haxework/gui/ITextView.hx
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
package haxework.gui;
|
||||||
|
|
||||||
|
interface ITextView<C, T> extends IView<C> {
|
||||||
|
public var textField(default, null):T;
|
||||||
|
public var text(default, set):String;
|
||||||
|
public var fontFamily(default, set):String;
|
||||||
|
public var fontColor(default, set):Int;
|
||||||
|
public var fontSize(default, set):Float;
|
||||||
|
}
|
||||||
@@ -23,6 +23,8 @@ interface IView<C> {
|
|||||||
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 hAlign(default, set):HAlign;
|
public var hAlign(default, set):HAlign;
|
||||||
public var vAlign(default, set):VAlign;
|
public var vAlign(default, set):VAlign;
|
||||||
|
|
||||||
|
|||||||
17
haxework/gui/LabelView.hx
Executable file
17
haxework/gui/LabelView.hx
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
package haxework.gui;
|
||||||
|
|
||||||
|
import flash.text.TextFieldAutoSize;
|
||||||
|
|
||||||
|
class LabelView extends TextView {
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
textField.autoSize = TextFieldAutoSize.CENTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
super.update();
|
||||||
|
textField.x = (width - textField.width) / 2;
|
||||||
|
textField.y = (height - textField.height) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,11 +7,6 @@ import flash.display.DisplayObject;
|
|||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
|
|
||||||
//ToDo:
|
|
||||||
import haxework.gui.HGroupView;
|
|
||||||
import haxework.gui.VGroupView;
|
|
||||||
import haxework.gui.skin.ColorSkin;
|
|
||||||
|
|
||||||
class Root {
|
class Root {
|
||||||
|
|
||||||
private var view:IView<Sprite>;
|
private var view:IView<Sprite>;
|
||||||
|
|||||||
70
haxework/gui/TextView.hx
Executable file
70
haxework/gui/TextView.hx
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
package haxework.gui;
|
||||||
|
|
||||||
|
import flash.text.TextFormat;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
import flash.text.TextField;
|
||||||
|
|
||||||
|
class TextView extends View implements ITextView<Sprite, TextField> {
|
||||||
|
|
||||||
|
public var textField(default, null):TextField;
|
||||||
|
public var text(default, set):String;
|
||||||
|
public var fontFamily(default, set):String;
|
||||||
|
public var fontColor(default, set):Int;
|
||||||
|
public var fontSize(default, set):Float;
|
||||||
|
private var textFormat:TextFormat;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
super();
|
||||||
|
textField = new TextField();
|
||||||
|
textFormat = textField.defaultTextFormat;
|
||||||
|
textFormat.font = "Arial";
|
||||||
|
textFormat.size = 16;
|
||||||
|
content.addChild(textField);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_text(value:String):String {
|
||||||
|
if (text != value) {
|
||||||
|
text = value;
|
||||||
|
textField.text = text;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_fontFamily(value:String):String {
|
||||||
|
if (fontFamily != value) {
|
||||||
|
fontFamily = value;
|
||||||
|
textFormat.font = fontFamily;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontFamily;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_fontColor(value:Int):Int {
|
||||||
|
if (fontColor != value) {
|
||||||
|
fontColor = value;
|
||||||
|
textFormat.color = fontColor;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_fontSize(value:Float):Float {
|
||||||
|
if (fontSize != value) {
|
||||||
|
fontSize = value;
|
||||||
|
textFormat.size = fontSize;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
return fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
override public function update():Void {
|
||||||
|
textField.setTextFormat(textFormat);
|
||||||
|
if (contentSize) {
|
||||||
|
width = textField.width;
|
||||||
|
height = textField.height;
|
||||||
|
}
|
||||||
|
super.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,6 +32,8 @@ class View implements IView<Sprite> {
|
|||||||
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 hAlign(default, set):HAlign;
|
public var hAlign(default, set):HAlign;
|
||||||
public var vAlign(default, set):VAlign;
|
public var vAlign(default, set):VAlign;
|
||||||
|
|
||||||
@@ -152,6 +154,15 @@ class View implements IView<Sprite> {
|
|||||||
return pHeight;
|
return pHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function set_contentSize(value:Bool):Bool {
|
||||||
|
if (contentSize != value) {
|
||||||
|
contentSize = value;
|
||||||
|
invalidate();
|
||||||
|
invalidateParent();
|
||||||
|
}
|
||||||
|
return contentSize;
|
||||||
|
}
|
||||||
|
|
||||||
private function set_hAlign(value:HAlign):HAlign {
|
private function set_hAlign(value:HAlign):HAlign {
|
||||||
if (hAlign != value) {
|
if (hAlign != value) {
|
||||||
hAlign = value;
|
hAlign = value;
|
||||||
|
|||||||
Reference in New Issue
Block a user