Created
May 30, 2014 11:13
-
-
Save grapefrukt/6330002eec9d0185192c to your computer and use it in GitHub Desktop.
Hack to fix offset/cropped text when scaling a TextField in OpenFL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package flash.text; | |
import openfl.text.TextField; | |
import openfl.text.TextFormat; | |
/** | |
* ... | |
* @author Martin Jonasson, [email protected] | |
*/ | |
#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