-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
edit-box.ts
778 lines (688 loc) · 24.3 KB
/
edit-box.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/*
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @category ui
*/
import { UITransform } from '../../../core/components/ui-base';
import { SpriteFrame } from '../../../core/assets/sprite-frame';
import { Component } from '../../../core/components/component';
import { EventHandler as ComponentEventHandler } from '../../../core/components/component-event-handler';
import { ccclass, help, executeInEditMode, executionOrder, menu, requireComponent, tooltip, displayOrder, type, serializable } from 'cc.decorator';
import { Color, Size, Vec3 } from '../../../core/math';
import { EventTouch } from '../../../core/platform';
import { SystemEventType } from '../../../core/platform/event-manager/event-enum';
import { Node } from '../../../core/scene-graph/node';
import { Label, VerticalTextAlignment } from '../label';
import { Sprite } from '../sprite';
import { EditBoxImpl } from './edit-box-impl';
import { EditBoxImplBase } from './edit-box-impl-base';
import { InputFlag, InputMode, KeyboardReturnType } from './types';
import { sys } from '../../../core/platform/sys';
import { EDITOR } from 'internal:constants';
import { legacyCC } from '../../../core/global-exports';
const LEFT_PADDING = 2;
function capitalize (str: string) {
return str.replace(/(?:^|\s)\S/g, (a) => {
return a.toUpperCase();
});
}
function capitalizeFirstLetter (str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
enum EventType {
EDITING_DID_BEGAN = 'editing-did-began',
EDITING_DID_ENDED = 'editing-did-ended',
TEXT_CHANGED = 'text-changed',
EDITING_RETURN = 'editing-return',
}
/**
* @en
* `EditBox` is a component for inputing text, you can use it to gather small amounts of text from users.
*
* @zh
* `EditBox` 组件,用于获取用户的输入文本。
*/
@ccclass('cc.EditBox')
@help('i18n:cc.EditBox')
@executionOrder(100)
@menu('UI/EditBox')
@requireComponent(UITransform)
@executeInEditMode
export class EditBox extends Component {
/**
* @en
* Input string of EditBox.
*
* @zh
* 输入框的初始输入内容,如果为空则会显示占位符的文本。
*/
@displayOrder(1)
@tooltip('输入框的初始输入内容,如果为空则会显示占位符的文本')
get string () {
return this._string;
}
set string (value) {
if (this._maxLength >= 0 && value.length >= this._maxLength) {
value = value.slice(0, this._maxLength);
}
this._string = value;
this._updateString(value);
}
/**
* @en
* The display text of placeholder.
*
* @zh
* 输入框占位符的文本内容。
*/
@displayOrder(2)
@tooltip('输入框占位符的文本内容')
get placeholder () {
if (!this._placeholderLabel) {
return '';
}
return this._placeholderLabel.string;
}
set placeholder (value) {
if (this._placeholderLabel) {
this._placeholderLabel.string = value;
}
}
/**
* @en
* The Label component attached to the node for EditBox's input text label
*
* @zh
* 输入框输入文本节点上挂载的 Label 组件对象
*/
@type(Label)
@displayOrder(3)
@tooltip('输入框输入文本节点上挂载的 Label 组件对象')
get textLabel () {
return this._textLabel;
}
set textLabel (oldValue) {
if (this._textLabel !== oldValue) {
this._textLabel = oldValue;
if (this._textLabel) {
this._updateTextLabel();
this._updateLabels();
}
}
}
/**
* @en
* The Label component attached to the node for EditBox's placeholder text label.
*
* @zh
* 输入框占位符节点上挂载的 Label 组件对象。
*/
@type(Label)
@displayOrder(4)
@tooltip('输入框占位符节点上挂载的 Label 组件对象')
get placeholderLabel () {
return this._placeholderLabel;
}
set placeholderLabel (oldValue) {
if (this._placeholderLabel !== oldValue) {
this._placeholderLabel = oldValue;
if (this._placeholderLabel) {
this._updatePlaceholderLabel();
this._updateLabels();
}
}
}
/**
* @en
* The background image of EditBox.
*
* @zh
* 输入框的背景图片。
*/
@type(SpriteFrame)
@displayOrder(5)
@tooltip('输入框的背景图片')
get backgroundImage () {
return this._backgroundImage;
}
set backgroundImage (value: SpriteFrame | null) {
if (this._backgroundImage === value) {
return;
}
this._backgroundImage = value;
this._createBackgroundSprite();
}
/**
* @en
* Set the input flags that are to be applied to the EditBox.
*
* @zh
* 指定输入标志位,可以指定输入方式为密码或者单词首字母大写。
*/
@type(InputFlag)
@displayOrder(6)
@tooltip('指定输入标志位,可以指定输入方式为密码或者单词首字母大写')
get inputFlag () {
return this._inputFlag;
}
set inputFlag (value) {
this._inputFlag = value;
this._updateString(this._string);
}
/**
* @en
* Set the input mode of the edit box.
* If you pass ANY, it will create a multiline EditBox.
*
* @zh
* 指定输入模式: ANY表示多行输入,其它都是单行输入,移动平台上还可以指定键盘样式。
*/
@type(InputMode)
@displayOrder(7)
@tooltip('指定输入模式: ANY 表示多行输入,其它都是单行输入,移动平台上还可以指定键盘样式')
get inputMode () {
return this._inputMode;
}
set inputMode (oldValue) {
if (this._inputMode !== oldValue) {
this._inputMode = oldValue;
this._updateTextLabel();
this._updatePlaceholderLabel();
}
}
/**
* @en
* The return key type of EditBox.
* Note: it is meaningless for web platforms and desktop platforms.
*
* @zh
* 指定移动设备上面回车按钮的样式。
* 注意:这个选项对 web 平台与 desktop 平台无效。
*/
@type(KeyboardReturnType)
@displayOrder(8)
@tooltip('指定移动设备上面回车按钮的样式')
get returnType () {
return this._returnType;
}
set returnType (value: KeyboardReturnType) {
this._returnType = value;
}
/**
* @en
* The maximize input length of EditBox.
* - If pass a value less than 0, it won't limit the input number of characters.
* - If pass 0, it doesn't allow input any characters.
*
* @zh
* 输入框最大允许输入的字符个数。
* - 如果值为小于 0 的值,则不会限制输入字符个数。
* - 如果值为 0,则不允许用户进行任何输入。
*/
@displayOrder(9)
@tooltip('输入框最大允许输入的字符个数')
get maxLength () {
return this._maxLength;
}
set maxLength (value: number) {
this._maxLength = value;
}
/**
* @en
* Set the tabIndex of the DOM input element (only useful on Web).
*
* @zh
* 修改 DOM 输入元素的 tabIndex(这个属性只有在 Web 上面修改有意义)。
*/
@displayOrder(10)
@tooltip('修改 DOM 输入元素的 tabIndex(这个属性只有在 Web 上面修改有意义)')
get tabIndex () {
return this._tabIndex;
}
set tabIndex (value) {
if (this._tabIndex !== value) {
this._tabIndex = value;
if (this._impl) {
this._impl.setTabIndex(value);
}
}
}
public static _EditBoxImpl = EditBoxImplBase;
public static KeyboardReturnType = KeyboardReturnType;
public static InputFlag = InputFlag;
public static InputMode = InputMode;
public static EventType = EventType;
/**
* @en
* The event handler to be called when EditBox began to edit text.
*
* @zh
* 开始编辑文本输入框触发的事件回调。
*/
@type([ComponentEventHandler])
@displayOrder(11)
@tooltip('该事件在用户点击输入框获取焦点的时候被触发')
public editingDidBegan: ComponentEventHandler[] = [];
/**
* @en
* The event handler to be called when EditBox text changes.
*
* @zh
* 编辑文本输入框时触发的事件回调。
*/
@type([ComponentEventHandler])
@serializable
@displayOrder(12)
@tooltip('编辑文本输入框时触发的事件回调')
public textChanged: ComponentEventHandler[] = [];
/**
* @en
* The event handler to be called when EditBox edit ends.
*
* @zh
* 结束编辑文本输入框时触发的事件回调。
*/
@type([ComponentEventHandler])
@serializable
@displayOrder(13)
@tooltip('在单行模式下面,一般是在用户按下回车或者点击屏幕输入框以外的地方调用该函数。 如果是多行输入,一般是在用户点击屏幕输入框以外的地方调用该函数')
public editingDidEnded: ComponentEventHandler[] = [];
/**
* @en
* The event handler to be called when return key is pressed. Windows is not supported.
*
* @zh
* 当用户按下回车按键时的事件回调,目前不支持 windows 平台
*/
@type([ComponentEventHandler])
@serializable
@displayOrder(14)
@tooltip('该事件在用户按下回车键的时候被触发, 如果是单行输入框,按回车键还会使输入框失去焦点')
public editingReturn: ComponentEventHandler[] = [];
public _impl: EditBoxImplBase | null = null;
public _background: Sprite | null = null;
@serializable
protected _textLabel: Label | null = null;
@serializable
protected _placeholderLabel: Label | null = null;
@serializable
protected _returnType = KeyboardReturnType.DEFAULT;
@serializable
protected _useOriginalSize = true;
@serializable
protected _string = '';
@serializable
protected _tabIndex = 0;
@serializable
protected _backgroundImage: SpriteFrame | null = null;
@serializable
protected _inputFlag = InputFlag.DEFAULT;
@serializable
protected _inputMode = InputMode.ANY;
@serializable
protected _maxLength = 20;
private _isLabelVisible = false;
public __preload () {
this._init();
}
public onEnable () {
if (!EDITOR) {
this._registerEvent();
}
if (this._impl) {
this._impl.onEnable();
}
}
public update () {
if (this._impl) {
this._impl.update();
}
}
public onDisable () {
if (!EDITOR) {
this._unregisterEvent();
}
if (this._impl) {
this._impl.onDisable();
}
}
public onDestroy () {
if (this._impl) {
this._impl.clear();
}
}
/**
* @en Let the EditBox get focus
* @zh 让当前 EditBox 获得焦点。
*/
public setFocus () {
if (this._impl) {
this._impl.setFocus(true);
}
}
/**
* @en Let the EditBox get focus
* @zh 让当前 EditBox 获得焦点
*/
public focus () {
if (this._impl) {
this._impl.setFocus(true);
}
}
/**
* @en Let the EditBox lose focus
* @zh 让当前 EditBox 失去焦点
*/
public blur () {
if (this._impl) {
this._impl.setFocus(false);
}
}
/**
* @en Determine whether EditBox is getting focus or not.
* @zh 判断 EditBox 是否获得了焦点。
* Note: only available on Web at the moment.
*/
public isFocused () {
if (this._impl) {
return this._impl.isFocused();
}
return false;
}
public _editBoxEditingDidBegan () {
ComponentEventHandler.emitEvents(this.editingDidBegan, this);
this.node.emit(EventType.EDITING_DID_BEGAN, this);
}
public _editBoxEditingDidEnded () {
ComponentEventHandler.emitEvents(this.editingDidEnded, this);
this.node.emit(EventType.EDITING_DID_ENDED, this);
}
public _editBoxTextChanged (text: string) {
text = this._updateLabelStringStyle(text, true);
this.string = text;
ComponentEventHandler.emitEvents(this.textChanged, text, this);
this.node.emit(EventType.TEXT_CHANGED, this);
}
public _editBoxEditingReturn () {
ComponentEventHandler.emitEvents(this.editingReturn, this);
this.node.emit(EventType.EDITING_RETURN, this);
}
public _showLabels () {
this._isLabelVisible = true;
this._updateLabels();
}
public _hideLabels () {
this._isLabelVisible = false;
if (this._textLabel) {
this._textLabel.node.active = false;
}
if (this._placeholderLabel) {
this._placeholderLabel.node.active = false;
}
}
protected _onTouchBegan (event: EventTouch) {
event.propagationStopped = true;
}
protected _onTouchCancel (event: EventTouch) {
event.propagationStopped = true;
}
protected _onTouchEnded (event: EventTouch) {
if (this._impl) {
this._impl.beginEditing();
}
event.propagationStopped = true;
}
protected _init () {
this._createBackgroundSprite();
this._updatePlaceholderLabel();
this._updateTextLabel();
this._isLabelVisible = true;
this.node.on(SystemEventType.SIZE_CHANGED, this._resizeChildNodes, this);
const impl = this._impl = new EditBox._EditBoxImpl();
impl.init(this);
this._updateString(this._string);
this._syncSize();
}
protected _createBackgroundSprite () {
if (!this._background) {
this._background = this.node.getComponent(Sprite);
if (!this._background) {
this._background = this.node.addComponent(Sprite);
}
}
this._background!.type = Sprite.Type.SLICED;
this._background!.spriteFrame = this._backgroundImage;
}
protected _updateTextLabel () {
let textLabel = this._textLabel;
// If textLabel doesn't exist, create one.
if (!textLabel) {
let node = this.node.getChildByName('TEXT_LABEL');
if (!node) {
node = new Node('TEXT_LABEL');
}
textLabel = node!.getComponent(Label);
if (!textLabel) {
textLabel = node!.addComponent(Label);
}
node!.parent = this.node;
this._textLabel = textLabel;
}
// update
const transformComp = this._textLabel!.node._uiProps.uiTransformComp;
transformComp!.setAnchorPoint(0, 1);
textLabel!.overflow = Label.Overflow.CLAMP;
if (this._inputMode === InputMode.ANY) {
textLabel!.verticalAlign = VerticalTextAlignment.TOP;
textLabel!.enableWrapText = true;
}
else {
textLabel!.verticalAlign = VerticalTextAlignment.CENTER;
textLabel!.enableWrapText = false;
}
textLabel!.string = this._updateLabelStringStyle(this._string);
}
protected _updatePlaceholderLabel () {
let placeholderLabel = this._placeholderLabel;
// If placeholderLabel doesn't exist, create one.
if (!placeholderLabel) {
let node = this.node.getChildByName('PLACEHOLDER_LABEL');
if (!node) {
node = new Node('PLACEHOLDER_LABEL');
}
placeholderLabel = node!.getComponent(Label);
if (!placeholderLabel) {
placeholderLabel = node!.addComponent(Label);
}
node!.parent = this.node;
this._placeholderLabel = placeholderLabel;
}
// update
const transform = this._placeholderLabel!.node._uiProps.uiTransformComp;
transform!.setAnchorPoint(0, 1);
placeholderLabel!.overflow = Label.Overflow.CLAMP;
if (this._inputMode === InputMode.ANY) {
placeholderLabel!.verticalAlign = VerticalTextAlignment.TOP;
placeholderLabel!.enableWrapText = true;
}
else {
placeholderLabel!.verticalAlign = VerticalTextAlignment.CENTER;
placeholderLabel!.enableWrapText = false;
}
placeholderLabel!.string = this.placeholder;
}
protected _syncSize () {
let trans = this.node._uiProps.uiTransformComp!;
const size = trans.contentSize;
if (this._background) {
let bgTrans = this._background.node._uiProps.uiTransformComp!;
bgTrans.anchorPoint = trans.anchorPoint;
bgTrans.setContentSize(size);
}
this._updateLabelPosition(size);
if (this._impl) {
this._impl.setSize(size.width, size.height);
}
}
protected _updateLabels () {
if (this._isLabelVisible) {
const content = this._string;
if (this._textLabel) {
this._textLabel.node.active = (content !== '');
}
if (this._placeholderLabel) {
this._placeholderLabel.node.active = (content === '');
}
}
}
protected _updateString (text: string) {
const textLabel = this._textLabel;
// Not inited yet
if (!textLabel) {
return;
}
let displayText = text;
if (displayText) {
displayText = this._updateLabelStringStyle(displayText);
}
textLabel.string = displayText;
this._updateLabels();
}
protected _updateLabelStringStyle (text: string, ignorePassword: boolean = false) {
const inputFlag = this._inputFlag;
if (!ignorePassword && inputFlag === InputFlag.PASSWORD) {
let passwordString = '';
const len = text.length;
for (let i = 0; i < len; ++i) {
passwordString += '\u25CF';
}
text = passwordString;
} else if (inputFlag === InputFlag.INITIAL_CAPS_ALL_CHARACTERS) {
text = text.toUpperCase();
} else if (inputFlag === InputFlag.INITIAL_CAPS_WORD) {
text = capitalize(text);
} else if (inputFlag === InputFlag.INITIAL_CAPS_SENTENCE) {
text = capitalizeFirstLetter(text);
}
return text;
}
protected _registerEvent () {
this.node.on(SystemEventType.TOUCH_START, this._onTouchBegan, this);
this.node.on(SystemEventType.TOUCH_END, this._onTouchEnded, this);
}
protected _unregisterEvent () {
this.node.off(SystemEventType.TOUCH_START, this._onTouchBegan, this);
this.node.off(SystemEventType.TOUCH_END, this._onTouchEnded, this);
}
protected _updateLabelPosition (size: Size) {
let trans = this.node._uiProps.uiTransformComp!;
const offX = -trans.anchorX * trans.width;
const offY = -trans.anchorY * trans.height;
const placeholderLabel = this._placeholderLabel;
const textLabel = this._textLabel;
if (textLabel) {
textLabel.node._uiProps.uiTransformComp!.setContentSize(size.width - LEFT_PADDING, size.height);
textLabel.node.position = new Vec3 (offX + LEFT_PADDING, offY + size.height, textLabel.node.position.z);
textLabel.verticalAlign = this._inputMode === InputMode.ANY ? VerticalTextAlignment.TOP : VerticalTextAlignment.CENTER;
textLabel.enableWrapText = this._inputMode === InputMode.ANY ? true : false;
}
if (placeholderLabel) {
placeholderLabel.node._uiProps.uiTransformComp!.setContentSize(size.width - LEFT_PADDING, size.height);
placeholderLabel.lineHeight = size.height;
placeholderLabel.node.position = new Vec3 (offX + LEFT_PADDING, offY + size.height, placeholderLabel.node.position.z);
placeholderLabel.verticalAlign = this._inputMode === InputMode.ANY ?
VerticalTextAlignment.TOP : VerticalTextAlignment.CENTER;
placeholderLabel.enableWrapText = this._inputMode === InputMode.ANY ? true : false;
}
}
protected _resizeChildNodes () {
let trans = this.node._uiProps.uiTransformComp!;
const textLabelNode = this._textLabel && this._textLabel.node;
if (textLabelNode) {
textLabelNode.position = new Vec3(-trans.width / 2, trans.height / 2, textLabelNode.position.z);
textLabelNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize);
}
const placeholderLabelNode = this._placeholderLabel && this._placeholderLabel.node;
if (placeholderLabelNode) {
placeholderLabelNode.position = new Vec3(-trans.width / 2, trans.height / 2, placeholderLabelNode.position.z);
placeholderLabelNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize);
}
const backgroundNode = this._background && this._background.node;
if (backgroundNode) {
backgroundNode._uiProps.uiTransformComp!.setContentSize(trans.contentSize);
}
}
}
if (sys.isBrowser){
EditBox._EditBoxImpl = EditBoxImpl;
}
/**
* @en
* Note: This event is emitted from the node to which the component belongs.
* @zh
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
* @event editing-did-began
* @param {Event.EventCustom} event
* @param {EditBox} editbox - The EditBox component.
*/
/**
* @en
* Note: This event is emitted from the node to which the component belongs.
* @zh
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
* @event editing-did-ended
* @param {Event.EventCustom} event
* @param {EditBox} editbox - The EditBox component.
*/
/**
* @en
* Note: This event is emitted from the node to which the component belongs.
* @zh
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
* @event text-changed
* @param {Event.EventCustom} event
* @param {EditBox} editbox - The EditBox component.
*/
/**
* @en
* Note: This event is emitted from the node to which the component belongs.
* @zh
* 注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
* @event editing-return
* @param {Event.EventCustom} event
* @param {EditBox} editbox - The EditBox component.
*/
/**
* @en if you don't need the EditBox and it isn't in any running Scene, you should
* call the destroy method on this component or the associated node explicitly.
* Otherwise, the created DOM element won't be removed from web page.
* @zh
* 如果你不再使用 EditBox,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。
* 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。
* @example
* ```
* editbox.node.parent = null; // or editbox.node.removeFromParent(false);
* // when you don't need editbox anymore
* editbox.node.destroy();
* ```
* @return {Boolean} whether it is the first time the destroy being called
*/