[js] textview fix

This commit is contained in:
2015-05-22 17:50:36 +03:00
parent 9b80d545c1
commit 28b94b7470
2 changed files with 30 additions and 6 deletions

View File

@@ -28,6 +28,9 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
private var textFormat:TextFormat;
private var _textWidth:Float;
private var _textHeight:Float;
public function new() {
super();
layoutHAlign = HAlign.CENTER;
@@ -144,6 +147,22 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
return _text;
}
private function updateTextSize():Void {
//ToDo: canvas.getContext("2d").measureText very slow
#if js
var s = 1;
var t = currentText();
if (t != null) for (i in 0...t.length) {
if (t.charCodeAt(i) == 10) s++;
}
_textHeight = textFormat.size * s;
_textWidth = width;
#else
_textWidth = textField.textWidth;
_textHeight = textField.textHeight;
#end
}
override public function update():Void {
textField.embedFonts = fontEmbed;
textField.defaultTextFormat = textFormat;
@@ -151,10 +170,11 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
var t:String = currentText();
if (t != null) textField.text = t;
textField.setTextFormat(textFormat);
updateTextSize();
if (contentSize && !Std.is(skin, ISize)) {
#if html5
var h = textField.textHeight;
//var w = textField.textWidth;
var h = _textHeight;
//var w = _textWidth;
//if (h > textFormat.size * 1.5) h = h / 2;
textField.height = h;
//textField.width = w;
@@ -185,9 +205,9 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
//} else {
textField.width = width;
textField.height = textField.textHeight * 1.185;
textField.height = _textHeight * 1.185;
//#if html5 textField.height = textField.textHeight; #end
//#if html5 textField.height = _textHeight; #end
textField.x = switch (layoutHAlign) {
case HAlign.NONE: 0;
case HAlign.LEFT: paddings;
@@ -198,8 +218,8 @@ class TextView extends SpriteView implements ITextView<Sprite, TextField> {
textField.y = switch (layoutVAlign) {
case VAlign.NONE: 0;
case VAlign.TOP: paddings;
case VAlign.MIDDLE: (height - textField.textHeight) / 2;
case VAlign.BOTTOM: height - textField.textHeight - paddings;
case VAlign.MIDDLE: (height - _textHeight) / 2;
case VAlign.BOTTOM: height - _textHeight - paddings;
default: 0;
}
//}

View File

@@ -1,5 +1,6 @@
package haxework.gui;
import flash.errors.Error;
import haxework.gui.IView.Content;
import haxework.gui.skin.ISize;
import haxework.gui.core.SizeType;
@@ -321,6 +322,7 @@ class Updater {
}
public function update(?_):Void {
var t = Date.now().getTime();
while (invalidated.length > 0) {
var v = null;
try {
@@ -330,6 +332,8 @@ class Updater {
L.e("Update", v + "", error);
}
}
t = Date.now().getTime() - t;
if (t > 10) trace("UPDATE(" + t + ")");
}
}