• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16class Test {
17    align:number = 0;
18    fit:number = 0;
19    overflow:number = 0;
20    text:number = 0;
21    width:number = 0;
22    constructor(align:number, fit:number, overflow:number, text:number, width:number) {
23      this.align = align;
24      this.fit = fit;
25      this.overflow = overflow;
26      this.text = text;
27      this.width = width;
28    }
29}
30
31@Entry
32@Component
33struct TestView {
34
35    @State
36    currentTest:Test = new Test(0, 0, 0, 0, 0);
37
38    aligns:string[] = [
39        "TopLeft",
40        "TopCenter",
41        "TopRight",
42        "CenterLeft",
43        "Center",
44        "CenterRight",
45        "BottomLeft",
46        "BottomCenter",
47        "BottomRight"
48    ];
49
50    stackFits:string[] = [
51        "Keep",
52        "Stretch",
53        "Inherit",
54        "FirstChild"
55    ];
56
57    overflows:string[] = [
58        "Clip",
59        "Observable"
60    ];
61
62    texts:string[] = [
63        "Test text",
64        "This is a very long text for demonstration purposes."
65    ];
66
67    widths:number[] = [
68        200,
69        500,
70        800
71    ];
72
73    alignToText(align) {
74        if (align >= this.aligns.length)
75            return "Unknown (" + align + ")";
76
77        return "Align." + this.aligns[align] + "(" + /*Align[this.aligns[align]]*/ + ")";
78    } // alignToText
79
80    fitToText(fit) {
81        if (fit >= this.stackFits.length)
82            return "Unknown (" + fit + ")";
83
84        return "StackFit." + this.stackFits[fit] + "(" + /*StackFit[this.stackFits[fit]]*/ + ")";
85    }
86
87    overflowToText(overflow) {
88        if (overflow >= this.overflows.length)
89            return "Unknown (" + overflow + ")";
90
91        return "Overflow." + this.overflows[overflow] + "(" + /*Overflow[this.overflows[overflow]]*/ + ")";
92    }
93
94    build() {
95        Column(){
96            Row(){
97                Button("Alignment")
98                .onClick(() => {
99                    this.currentTest.align = (this.currentTest.align + 1) % this.aligns.length;
100                })
101                Text(this.alignToText(this.currentTest.align))
102            }
103            Row(){
104                Button("Fit")
105                .onClick(() => {
106                    this.currentTest.fit = (this.currentTest.fit + 1) % this.stackFits.length;
107                })
108                Text(this.fitToText(this.currentTest.fit))
109            }
110            Row(){
111                Button("Overflow")
112                .onClick(() => {
113                    this.currentTest.overflow = (this.currentTest.overflow + 1) % this.overflows.length;
114                })
115                Text(this.overflowToText(this.currentTest.overflow))
116            }
117            Row(){
118                Button("Text")
119                .onClick(() => {
120                    this.currentTest.text = (this.currentTest.text + 1) % this.texts.length;
121                })
122                Text(this.texts[this.currentTest.text])
123            }
124            Row(){
125                Button("Width")
126                .onClick(() => {
127                    this.currentTest.width = (this.currentTest.width + 1) % this.widths.length;
128                })
129                Text("" + this.widths[this.currentTest.width])
130            }
131            Stack(){
132                Column(){
133
134                }
135                .width(350).height(400).backgroundColor(0xaaaaaa)
136                Text(this.texts[this.currentTest.text]).backgroundColor(0x00aaff).fontColor("#ffffff")
137                .width(this.widths[this.currentTest.width])
138            }
139            //.alignment(Align[this.aligns[this.currentTest.align]]).stackFit(StackFit[this.stackFits[this.currentTest.fit]])
140            //.Overflow(Overflow[this.overflows[this.currentTest.overflow]]).backgroundColor(0x0000cd).width(500.0).height(400.0)
141            Stack(){
142                Text("test1")
143                Text("Test2")
144            }
145        }
146        .alignItems(HorizontalAlign.Center)
147    }
148}
149