@@ -8,39 +8,75 @@ export struct CocosEditBox {
88 cocosWorker: worker.ThreadWorker = WorkerManager.getInstance().getWorker();
99
1010 build(){
11- TextInput({text: this.textInputInfo.text, placeholder: this.textInputInfo.placeHolder})
12- .id('TextInput' + this.textInputInfo.viewTag)
13- .position({x: px2vp(this.textInputInfo.x), y: px2vp(this.textInputInfo.y)})
14- .size({width: px2vp(this.textInputInfo.w), height: px2vp(this.textInputInfo.h)})
15- .padding({top: px2vp(this.textInputInfo.paddingH), right: px2vp(this.textInputInfo.paddingW),
16- bottom: px2vp(this.textInputInfo.paddingH), left: px2vp(this.textInputInfo.paddingW)})
17- .borderRadius(0)
18- .maxLength(this.textInputInfo.maxLength)
19- .type(this.textInputInfo.inputMode)
20- .fontFamily($rawfile(this.textInputInfo.fontPath))
21- .fontSize(px2fp(this.textInputInfo.fontSize))
22- .fontColor(`rgba(${this.textInputInfo.fontColor.r}, ${this.textInputInfo.fontColor.g}, ${this.textInputInfo.fontColor.b}, ${this.textInputInfo.fontColor.a})`)
23- .placeholderFont({size: px2fp(this.textInputInfo.placeholderFontSize), family: $rawfile(this.textInputInfo.placeHolderFontPath)})
24- .placeholderColor(`rgba(${this.textInputInfo.placeholderFontColor.r}, ${this.textInputInfo.placeholderFontColor.g}, ${this.textInputInfo.placeholderFontColor.b}, ${this.textInputInfo.placeholderFontColor.a})`)
25- .backgroundColor(Color.Transparent)
26- .visibility(this.textInputInfo.visible ? Visibility.Visible : Visibility.None)
27- .showPasswordIcon(false)
28- .onVisibleAreaChange([0.0, 1.0], () => {
29- focusControl.requestFocus('TextInput' + this.textInputInfo.viewTag);
30- })
31- .onFocus(() => {
32- this.cocosWorker.postMessage({type: "editBoxOnFocus", viewTag: this.textInputInfo.viewTag});
33- })
34- .onChange((value: string)=>{
35- this.textInputInfo.text = value;
36- this.cocosWorker.postMessage({type: "editBoxOnChange", viewTag: this.textInputInfo.viewTag, value: value});
37- })
38- .onBlur(()=> {
39- this.textInputInfo.visible = false
40- this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
41- })
42- .onSubmit(()=>{
43- this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
44- })
11+ if(this.textInputInfo.multiline){
12+ TextArea({text: this.textInputInfo.text, placeholder: this.textInputInfo.placeHolder})
13+ .id('TextArea'+this.textInputInfo.viewTag)
14+ .position({x: px2vp(this.textInputInfo.x), y: px2vp(this.textInputInfo.y)})
15+ .size({width: px2vp(this.textInputInfo.w), height: px2vp(this.textInputInfo.h)})
16+ .padding({top: px2vp(this.textInputInfo.paddingH), right: px2vp(this.textInputInfo.paddingW),
17+ bottom: px2vp(this.textInputInfo.paddingH), left: px2vp(this.textInputInfo.paddingW)})
18+ .borderRadius(0)
19+ .maxLength(this.textInputInfo.maxLength)
20+ .type(TextAreaType.NORMAL)
21+ .fontFamily($rawfile(this.textInputInfo.fontPath))
22+ .fontSize(px2fp(this.textInputInfo.fontSize))
23+ .fontColor(`rgba(${this.textInputInfo.fontColor.r}, ${this.textInputInfo.fontColor.g}, ${this.textInputInfo.fontColor.b}, ${this.textInputInfo.fontColor.a})`)
24+ .placeholderFont({size: px2fp(this.textInputInfo.placeholderFontSize), family: $rawfile(this.textInputInfo.placeHolderFontPath)})
25+ .placeholderColor(`rgba(${this.textInputInfo.placeholderFontColor.r}, ${this.textInputInfo.placeholderFontColor.g}, ${this.textInputInfo.placeholderFontColor.b}, ${this.textInputInfo.placeholderFontColor.a})`)
26+ .backgroundColor(Color.Transparent)
27+ .visibility(this.textInputInfo.visible ? Visibility.Visible : Visibility.None)
28+ .onVisibleAreaChange([0.0, 1.0], () => {
29+ focusControl.requestFocus('TextArea' + this.textInputInfo.viewTag);
30+ })
31+ .onFocus(() => {
32+ this.cocosWorker.postMessage({type: "editBoxOnFocus", viewTag: this.textInputInfo.viewTag});
33+ })
34+ .onChange((value: string)=>{
35+ this.textInputInfo.text = value;
36+ this.cocosWorker.postMessage({type: "editBoxOnChange", viewTag: this.textInputInfo.viewTag, value: value});
37+ })
38+ .onBlur(()=> {
39+ this.textInputInfo.visible = false
40+ this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
41+ })
42+ .onSubmit(()=>{
43+ this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
44+ })
45+ }else{
46+ TextInput({text: this.textInputInfo.text, placeholder: this.textInputInfo.placeHolder})
47+ .id('TextInput'+this.textInputInfo.viewTag)
48+ .position({x: px2vp(this.textInputInfo.x), y: px2vp(this.textInputInfo.y)})
49+ .size({width: px2vp(this.textInputInfo.w), height: px2vp(this.textInputInfo.h)})
50+ .padding({top: px2vp(this.textInputInfo.paddingH), right: px2vp(this.textInputInfo.paddingW),
51+ bottom: px2vp(this.textInputInfo.paddingH), left: px2vp(this.textInputInfo.paddingW)})
52+ .borderRadius(0)
53+ .maxLength(this.textInputInfo.maxLength)
54+ .type(this.textInputInfo.inputMode)
55+ .fontFamily($rawfile(this.textInputInfo.fontPath))
56+ .fontSize(px2fp(this.textInputInfo.fontSize))
57+ .fontColor(`rgba(${this.textInputInfo.fontColor.r}, ${this.textInputInfo.fontColor.g}, ${this.textInputInfo.fontColor.b}, ${this.textInputInfo.fontColor.a})`)
58+ .placeholderFont({size: px2fp(this.textInputInfo.placeholderFontSize), family: $rawfile(this.textInputInfo.placeHolderFontPath)})
59+ .placeholderColor(`rgba(${this.textInputInfo.placeholderFontColor.r}, ${this.textInputInfo.placeholderFontColor.g}, ${this.textInputInfo.placeholderFontColor.b}, ${this.textInputInfo.placeholderFontColor.a})`)
60+ .backgroundColor(Color.Transparent)
61+ .visibility(this.textInputInfo.visible ? Visibility.Visible : Visibility.None)
62+ .showPasswordIcon(false)
63+ .onVisibleAreaChange([0.0, 1.0], () => {
64+ focusControl.requestFocus('TextInput' + this.textInputInfo.viewTag);
65+ })
66+ .onFocus(() => {
67+ this.cocosWorker.postMessage({type: "editBoxOnFocus", viewTag: this.textInputInfo.viewTag});
68+ })
69+ .onChange((value: string)=>{
70+ this.textInputInfo.text = value;
71+ this.cocosWorker.postMessage({type: "editBoxOnChange", viewTag: this.textInputInfo.viewTag, value: value});
72+ })
73+ .onBlur(()=> {
74+ this.textInputInfo.visible = false
75+ this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
76+ })
77+ .onSubmit(()=>{
78+ this.cocosWorker.postMessage({type: "editBoxOnEnter", viewTag: this.textInputInfo.viewTag, text: this.textInputInfo.text});
79+ })
80+ }
4581 }
46- }
82+ }
0 commit comments