1
1
package haxe .ui .backend .flixel .textinputs ;
2
2
3
3
import flixel .FlxSprite ;
4
+ import flixel .text .FlxInputText ;
5
+ import flixel .util .FlxColor ;
4
6
import haxe .ui .backend .TextInputImpl .TextInputEvent ;
5
7
import haxe .ui .core .Component ;
6
8
import openfl .events .Event ;
7
9
import openfl .events .KeyboardEvent ;
8
10
9
- #if flixel_text_input
10
-
11
+ #if (flixel >= "5.9.0")
11
12
class FlxTextInput extends TextBase {
12
13
public static var USE_ON_ADDED : Bool = false ;
13
14
public static var USE_ON_REMOVED : Bool = false ;
14
15
15
16
private static inline var PADDING_X : Int = 4 ;
16
17
private static inline var PADDING_Y : Int = 2 ;
17
18
18
- private var tf : flixel.addons.text. FlxTextInput ;
19
+ private var tf : FlxInputText ;
19
20
20
21
public function new () {
21
22
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 );
25
26
tf .pixelPerfectRender = true ;
26
- tf .moves = false ;
27
27
_inputData .vscrollPageStep = 1 ;
28
28
_inputData .vscrollNativeWheel = true ;
29
29
}
30
30
31
31
public override function focus () {
32
- tf .focus = true ;
32
+ tf .startFocus () ;
33
33
}
34
34
35
35
public override function blur () {
36
- tf .focus = false ;
36
+ tf .endFocus () ;
37
37
}
38
38
39
39
public function attach () {
@@ -184,21 +184,23 @@ class FlxTextInput extends TextBase {
184
184
185
185
if (tf .multiline != _displayData .multiline ) {
186
186
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.
188
189
}
189
190
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 ;
192
194
}
193
195
194
- tf .type = ( parentComponent .disabled ? DYNAMIC : INPUT ) ;
196
+ tf .editable = ! parentComponent .disabled ;
195
197
196
198
return measureTextRequired ;
197
199
}
198
200
199
201
private override function validatePosition () {
200
202
_left = Math .round (_left * Toolkit .scaleX );
201
- _top = Math .round (_top * Toolkit .scaleY ) + ( PADDING_Y / 2 ) ;
203
+ _top = Math .round (_top * Toolkit .scaleY );
202
204
}
203
205
204
206
private override function validateDisplay () {
@@ -300,16 +302,16 @@ class FlxTextInput extends TextBase {
300
302
public var onChange (null , set ): TextInputEvent -> Void ;
301
303
private function set_onChange (value : TextInputEvent -> Void ): TextInputEvent -> Void {
302
304
if (_onChange != null ) {
303
- tf .onChange .remove (__onTextInputChangeEvent );
305
+ tf .onTextChange .remove (__onTextInputChangeEvent );
304
306
}
305
307
_onChange = value ;
306
308
if (_onChange != null ) {
307
- tf .onChange .add (__onTextInputChangeEvent );
309
+ tf .onTextChange .add (__onTextInputChangeEvent );
308
310
}
309
311
return value ;
310
312
}
311
313
312
- private function __onTextInputChangeEvent () {
314
+ private function __onTextInputChangeEvent (text : String , action : FlxInputTextChange ) {
313
315
if (_onChange != null ) {
314
316
_onChange ({
315
317
type : " change" ,
@@ -359,7 +361,7 @@ class FlxTextInput extends TextBase {
359
361
}
360
362
*/
361
363
362
- private function onInternalChange () {
364
+ private function onInternalChange (text : String , action : FlxInputTextChange ) {
363
365
_text = tf .text ;
364
366
365
367
measureText ();
@@ -368,8 +370,8 @@ class FlxTextInput extends TextBase {
368
370
_inputData .onChangedCallback ();
369
371
}
370
372
}
371
-
372
- private function onScroll () {
373
+
374
+ private function onScroll (scrollH : Int , scrollV : Int ) {
373
375
_inputData .hscrollPos = tf .scrollH ;
374
376
_inputData .vscrollPos = tf .scrollV - 1 ;
375
377
@@ -388,10 +390,9 @@ class FlxTextInput extends TextBase {
388
390
389
391
public function destroy (component : Component ) {
390
392
tf .visible = false ;
391
- component .remove (tf );
393
+ component .remove (tf , true );
392
394
tf .destroy ();
393
395
tf = null ;
394
396
}
395
397
}
396
-
397
398
#end
0 commit comments