Skip to content

Instantly share code, notes, and snippets.

@grapefrukt
Created May 30, 2014 11:13
Show Gist options
  • Save grapefrukt/6330002eec9d0185192c to your computer and use it in GitHub Desktop.
Save grapefrukt/6330002eec9d0185192c to your computer and use it in GitHub Desktop.
Hack to fix offset/cropped text when scaling a TextField in OpenFL
package flash.text;
import openfl.text.TextField;
import openfl.text.TextFormat;
/**
* ...
* @author Martin Jonasson, m@grapefrukt.com
*/
#if flash
typedef RTextField = TextField;
#else
class RTextField extends TextField {
private var _text:String = "";
private var _y:Float = 0;
public static inline var MAGIC_NUMBER:Float = 1.2;
override private function set_defaultTextFormat(inFormat:TextFormat):TextFormat {
super.set_defaultTextFormat(inFormat);
set_y(_y);
return inFormat;
}
override private function get_y():Float {
return _y;
}
override private function set_y(inVal:Float):Float {
_y = inVal;
super.set_y(inVal - getOffset());
return inVal;
}
override private function set_text(inText:String):String {
_text = inText;
super.set_text("\n" + _text);
return _text;
}
override private function get_text():String {
return _text;
}
override private function get_textHeight():Float {
return super.get_textHeight() - getOffset();
}
private inline function getOffset(){
return defaultTextFormat.size * MAGIC_NUMBER;
}
}
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment