/
TextField.ts
48 lines (45 loc) · 1.12 KB
/
TextField.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/// <reference path="DisplayObject.ts" />
module Unpacker{
export class TextField extends DisplayObject{
constructor(stage:any, data:Object, context:any){
super(stage, data, context);
Unpacker.sensibleDefaults(data,{
"text":"",
"textFormat":{}
});
this.DOM.className = "cmt";
this.setTextFormat(data["textFormat"]);
this.DOM.appendChild(document.createTextNode(data["text"]));
}
public setTextFormat(tf:Object):void{
Unpacker.sensibleDefaults(tf,{
"font":"SimHei",
"size":25,
"color":0xffffff,
"bold":false,
"underline":false,
"italic":false,
"margin":0
});
this.DOM.style.fontFamily = tf["font"];
this.DOM.style.fontSize = tf["size"];
this.DOM.style.color = Unpacker.color(tf["color"]);
if (tf["bold"]) {
this.DOM.style.fontWeight = "bold";
}
if (tf["italic"]) {
this.DOM.style.fontStyle = "italic";
}
if (tf["underline"]) {
this.DOM.style.textDecoration = "underline";
}
this.DOM.style.margin = tf["margin"] + "px";
}
set text(t:string){
this.DOM.textContent = t;
}
get text():string{
return this.DOM.textContent;
}
}
}