11package haxe .ui .backend .flixel .textinputs ;
22
33import flixel .FlxSprite ;
4+ import flixel .text .FlxInputText ;
5+ import flixel .util .FlxColor ;
46import haxe .ui .backend .TextInputImpl .TextInputEvent ;
57import haxe .ui .core .Component ;
68import openfl .events .Event ;
79import openfl .events .KeyboardEvent ;
810
9- #if flixel_text_input
10-
11+ #if (flixel >= "5.9.0")
1112class FlxTextInput extends TextBase {
1213 public static var USE_ON_ADDED : Bool = false ;
1314 public static var USE_ON_REMOVED : Bool = false ;
1415
1516 private static inline var PADDING_X : Int = 4 ;
1617 private static inline var PADDING_Y : Int = 2 ;
1718
18- private var tf : flixel.addons.text. FlxTextInput ;
19+ private var tf : FlxInputText ;
1920
2021 public function new () {
2122 super ();
22- tf = new flixel.addons.text. FlxTextInput ( );
23- tf .onChange .add (onInternalChange );
24- tf .onScroll .add (onScroll );
23+ tf = new FlxInputText ( 0 , 0 , 0 , null , 8 , FlxColor . BLACK , FlxColor . TRANSPARENT );
24+ tf .onTextChange .add (onInternalChange );
25+ tf .onScrollChange .add (onScroll );
2526 tf .pixelPerfectRender = true ;
26- tf .moves = false ;
2727 _inputData .vscrollPageStep = 1 ;
2828 _inputData .vscrollNativeWheel = true ;
2929 }
3030
3131 public override function focus () {
32- tf .focus = true ;
32+ tf .startFocus () ;
3333 }
3434
3535 public override function blur () {
36- tf .focus = false ;
36+ tf .endFocus () ;
3737 }
3838
3939 public function attach () {
@@ -184,21 +184,23 @@ class FlxTextInput extends TextBase {
184184
185185 if (tf .multiline != _displayData .multiline ) {
186186 tf .multiline = _displayData .multiline ;
187- measureTextRequired = true ;
187+ // `multiline` only decides whether the user can add new lines,
188+ // so measuring the text is not required.
188189 }
189190
190- if (tf .displayAsPassword != _inputData .password ) {
191- tf .displayAsPassword = _inputData .password ;
191+ if (tf .passwordMode != _inputData .password ) {
192+ tf .passwordMode = _inputData .password ;
193+ measureTextRequired = true ;
192194 }
193195
194- tf .type = ( parentComponent .disabled ? DYNAMIC : INPUT ) ;
196+ tf .editable = ! parentComponent .disabled ;
195197
196198 return measureTextRequired ;
197199 }
198200
199201 private override function validatePosition () {
200202 _left = Math .round (_left * Toolkit .scaleX );
201- _top = Math .round (_top * Toolkit .scaleY ) + ( PADDING_Y / 2 ) ;
203+ _top = Math .round (_top * Toolkit .scaleY );
202204 }
203205
204206 private override function validateDisplay () {
@@ -300,16 +302,16 @@ class FlxTextInput extends TextBase {
300302 public var onChange (null , set ): TextInputEvent -> Void ;
301303 private function set_onChange (value : TextInputEvent -> Void ): TextInputEvent -> Void {
302304 if (_onChange != null ) {
303- tf .onChange .remove (__onTextInputChangeEvent );
305+ tf .onTextChange .remove (__onTextInputChangeEvent );
304306 }
305307 _onChange = value ;
306308 if (_onChange != null ) {
307- tf .onChange .add (__onTextInputChangeEvent );
309+ tf .onTextChange .add (__onTextInputChangeEvent );
308310 }
309311 return value ;
310312 }
311313
312- private function __onTextInputChangeEvent () {
314+ private function __onTextInputChangeEvent (text : String , action : FlxInputTextChange ) {
313315 if (_onChange != null ) {
314316 _onChange ({
315317 type : " change" ,
@@ -359,7 +361,7 @@ class FlxTextInput extends TextBase {
359361 }
360362 */
361363
362- private function onInternalChange () {
364+ private function onInternalChange (text : String , action : FlxInputTextChange ) {
363365 _text = tf .text ;
364366
365367 measureText ();
@@ -368,8 +370,8 @@ class FlxTextInput extends TextBase {
368370 _inputData .onChangedCallback ();
369371 }
370372 }
371-
372- private function onScroll () {
373+
374+ private function onScroll (scrollH : Int , scrollV : Int ) {
373375 _inputData .hscrollPos = tf .scrollH ;
374376 _inputData .vscrollPos = tf .scrollV - 1 ;
375377
@@ -388,10 +390,9 @@ class FlxTextInput extends TextBase {
388390
389391 public function destroy (component : Component ) {
390392 tf .visible = false ;
391- component .remove (tf );
393+ component .remove (tf , true );
392394 tf .destroy ();
393395 tf = null ;
394396 }
395397}
396-
397398#end
0 commit comments