88 lines
2.1 KiB
Haxe
Executable File
88 lines
2.1 KiB
Haxe
Executable File
package haxework.gui;
|
|
|
|
import flash.text.TextFormatAlign;
|
|
import haxework.gui.skin.ISize;
|
|
import flash.text.TextFormat;
|
|
import flash.display.Sprite;
|
|
import flash.text.TextField;
|
|
|
|
class TextView extends SpriteView implements ITextView<Sprite, TextField> {
|
|
|
|
public var textField(default, null):TextField;
|
|
public var text(default, set):String;
|
|
public var align(default, set):TextFormatAlign;
|
|
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();
|
|
textField.wordWrap = true;
|
|
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_align(value:TextFormatAlign):TextFormatAlign {
|
|
if (align != value) {
|
|
textFormat.align = align = value;
|
|
invalidate();
|
|
}
|
|
return align;
|
|
}
|
|
|
|
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.defaultTextFormat = textFormat;
|
|
if (text != null) textField.text = text;
|
|
if (contentSize && !Std.is(skin, ISize)) {
|
|
width = textField.width;
|
|
height = textField.height;
|
|
} else {
|
|
textField.width = width;
|
|
textField.height = height;
|
|
}
|
|
super.update();
|
|
}
|
|
|
|
}
|