11package flixel .text ;
22
3- import openfl .display .BitmapData ;
43import flixel .FlxBasic ;
54import flixel .FlxG ;
65import flixel .FlxSprite ;
@@ -12,6 +11,7 @@ import flixel.text.FlxText.FlxTextAlign;
1211import flixel .text .FlxText .FlxTextBorderStyle ;
1312import flixel .util .FlxColor ;
1413import flixel .util .FlxDestroyUtil ;
14+ import openfl .display .BitmapData ;
1515import openfl .geom .ColorTransform ;
1616
1717using flixel .util .FlxColorTransformUtil ;
@@ -94,6 +94,13 @@ class FlxBitmapText extends FlxSprite
9494 * Default value if true.
9595 */
9696 public var autoSize (default , set ): Bool = true ;
97+
98+ /**
99+ * Whether to autmatically adjust the `width`, `height`, `offset` and
100+ * `origin` whenever the size of the text is changed.
101+ * @since 6.1.0
102+ */
103+ public var autoBounds (default , set ): Bool = true ;
97104
98105 /**
99106 * Number of pixels between text and text field border
@@ -1278,11 +1285,8 @@ class FlxBitmapText extends FlxSprite
12781285 borderDrawData .splice (0 , borderDrawData .length );
12791286 }
12801287
1281- // use local var to avoid get_width and recursion
1282- final newWidth = width = Math .abs (scale .x ) * frameWidth ;
1283- final newHeight = height = Math .abs (scale .y ) * frameHeight ;
1284- offset .set (- 0.5 * (newWidth - frameWidth ), - 0.5 * (newHeight - frameHeight ));
1285- centerOrigin ();
1288+ if (autoBounds )
1289+ autoAdjustBounds ();
12861290 }
12871291
12881292 if (! useTiles )
@@ -1397,6 +1401,15 @@ class FlxBitmapText extends FlxSprite
13971401 if (pendingPixelsChange )
13981402 throw " pendingPixelsChange was changed to true while processing changed pixels" ;
13991403 }
1404+
1405+ function autoAdjustBounds ()
1406+ {
1407+ // use local var to avoid get_width and recursion
1408+ final newWidth = width = Math .abs (scale .x ) * frameWidth ;
1409+ final newHeight = height = Math .abs (scale .y ) * frameHeight ;
1410+ offset .set (- 0.5 * (newWidth - frameWidth ), - 0.5 * (newHeight - frameHeight ));
1411+ centerOrigin ();
1412+ }
14001413
14011414 function drawText (posX : Int , posY : Int , isFront : Bool = true , ? bitmap : BitmapData , useTiles : Bool = false ): Void
14021415 {
@@ -1610,6 +1623,14 @@ class FlxBitmapText extends FlxSprite
16101623
16111624 return autoSize = value ;
16121625 }
1626+
1627+ function set_autoBounds (value : Bool ): Bool
1628+ {
1629+ if (autoBounds != value )
1630+ pendingTextChange = true ;
1631+
1632+ return this .autoBounds = value ;
1633+ }
16131634
16141635 function set_padding (value : Int ): Int
16151636 {
0 commit comments