• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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 
16 #include "ui_test_arc_label.h"
17 #include "common/screen.h"
18 #include "font/ui_font.h"
19 
20 namespace OHOS {
21 namespace {
22 const int16_t GAP = 5;
23 const int16_t TITLE_HEIGHT = 29;
24 const uint16_t CENTER_X = 185;
25 const uint16_t CENTER_Y = 155;
26 const uint16_t RADIUS = 150;
27 } // namespace
28 
SetUp()29 void UITestArcLabel::SetUp()
30 {
31     if (container_ == nullptr) {
32         container_ = new UIScrollView();
33         container_->SetThrowDrag(true);
34         container_->SetHorizontalScrollState(false);
35         container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
36         positionX_ = 0;
37         positionY_ = 0;
38     }
39 }
40 
TearDown()41 void UITestArcLabel::TearDown()
42 {
43     DeleteChildren(container_);
44     container_ = nullptr;
45 }
46 
InnerTestTitle(const char * title,int16_t x,int16_t y) const47 void UITestArcLabel::InnerTestTitle(const char* title, int16_t x, int16_t y) const
48 {
49     UILabel* titleLabel = new UILabel();
50     titleLabel->SetPosition(x, y, Screen::GetInstance().GetWidth(), TITLE_HEIGHT);
51     titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
52     titleLabel->SetText(title);
53     container_->Add(titleLabel);
54 }
55 
GetTestView()56 const UIView* UITestArcLabel::GetTestView()
57 {
58     UIKitUIArcLabelTestDisplay001();
59     UIKitUIArcLabelTestDisplay002();
60     UIKitUIArcLabelTestDisplay003();
61     UIKitUIArcLabelTestDisplay004();
62 
63     UIKitUIArcLabelTestAlign001();
64     UIKitUIArcLabelTestAlign002();
65     UIKitUIArcLabelTestAlign003();
66     return container_;
67 }
68 
UIKitUIArcLabelTestDisplay001()69 void UITestArcLabel::UIKitUIArcLabelTestDisplay001()
70 {
71     const char* title = "显示内部角度从0到270的弧形文本 ";
72     // 0: start angle  270: end angle
73     TestArcLabelDisplay(title, 0, 270, TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE,
74                         VIEW_DISTANCE_TO_TOP_SIDE);
75 }
76 
UIKitUIArcLabelTestDisplay002()77 void UITestArcLabel::UIKitUIArcLabelTestDisplay002()
78 {
79     const char* title = "显示内部角度从0到-270的弧形文本 ";
80     // 0: start angle  -270: end angle  100: y-coordinate
81     TestArcLabelDisplay(title, 0, -270, TextOrientation::INSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 100);
82 }
83 
UIKitUIArcLabelTestDisplay003()84 void UITestArcLabel::UIKitUIArcLabelTestDisplay003()
85 {
86     const char* title = "显示外部角度从0到270的弧形文本 ";
87     // 0: start angle  270: end angle  200: y-coordinate
88     TestArcLabelDisplay(title, 0, 270, TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 200);
89 }
90 
UIKitUIArcLabelTestDisplay004()91 void UITestArcLabel::UIKitUIArcLabelTestDisplay004()
92 {
93     const char* title = "显示外部角度从0到-270的弧形文本 ";
94     // 0: start angle  -270: end angle  300: y-coordinate
95     TestArcLabelDisplay(title, 0, -270, TextOrientation::OUTSIDE, VIEW_DISTANCE_TO_LEFT_SIDE, 300);
96 }
97 
TestArcLabelDisplay(const char * title,const int16_t startAngle,const int16_t endAngle,const TextOrientation orientation,int16_t x,int16_t y)98 void UITestArcLabel::TestArcLabelDisplay(const char* title,
99                                          const int16_t startAngle,
100                                          const int16_t endAngle,
101                                          const TextOrientation orientation,
102                                          int16_t x,
103                                          int16_t y)
104 {
105     if (container_ != nullptr) {
106         InnerTestTitle(title, x, positionY_);
107         UIArcLabel* label = new UIArcLabel();
108         label->SetArcTextCenter(CENTER_X, CENTER_Y + positionY_ + GAP * 4); // 4: 4 times GAP
109         label->SetArcTextRadius(RADIUS);
110         label->SetArcTextAngle(startAngle, endAngle);
111         label->SetArcTextOrientation(orientation);
112         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
113         label->SetText("012345678ABCDEF0123456789ABCDE");
114         label->SetStyle(STYLE_LETTER_SPACE, 10); // 10: space
115         container_->Add(label);
116         positionY_ += (RADIUS * 2) + GAP + TITLE_HEIGHT; // 2: diameter
117     }
118 }
119 
UIKitUIArcLabelTestAlign001()120 void UITestArcLabel::UIKitUIArcLabelTestAlign001()
121 {
122     if (container_ != nullptr) {
123         // 2: half of screen width
124         positionX_ = Screen::GetInstance().GetWidth() / 2 + VIEW_DISTANCE_TO_LEFT_SIDE;
125         positionY_ = 0;
126         InnerTestTitle("弧形文本在0到90度之间左对齐 ", positionX_, positionY_);
127         positionY_ += TITLE_HEIGHT + GAP;
128         UIView* back = new UIView();
129         back->SetPosition(positionX_, positionY_ + GAP);
130         back->Resize(RADIUS, RADIUS);
131         back->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
132         back->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
133 
134         UIArcLabel* label = new UIArcLabel();
135         label->SetArcTextCenter(positionX_, CENTER_Y + positionY_);
136         label->SetArcTextRadius(RADIUS);
137         label->SetArcTextAngle(0, 90);                    // 0: start angle, 90: end angle
138         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
139         label->SetText("LEFT");
140         label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT);
141         label->SetStyle(STYLE_LETTER_SPACE, 6); // 6: space
142 
143         container_->Add(back);
144         container_->Add(label);
145         positionY_ += RADIUS + GAP + TITLE_HEIGHT;
146     }
147 }
148 
UIKitUIArcLabelTestAlign002()149 void UITestArcLabel::UIKitUIArcLabelTestAlign002()
150 {
151     if (container_ != nullptr) {
152         InnerTestTitle("弧形文本在0到90度之间居中对齐 ", positionX_, positionY_);
153         positionY_ += TITLE_HEIGHT + GAP;
154         UIView* back = new UIView();
155         back->SetPosition(positionX_, positionY_ + GAP);
156         back->Resize(RADIUS, RADIUS);
157         back->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
158         back->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
159 
160         UIArcLabel* label = new UIArcLabel();
161         label->SetArcTextCenter(positionX_, CENTER_Y + positionY_);
162         label->SetArcTextRadius(RADIUS);
163         label->SetArcTextAngle(0, 90);                    // 0: start angle, 90: end angle
164         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
165         label->SetText("CENTER");
166         label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
167         label->SetStyle(STYLE_LETTER_SPACE, 6); // 6: space
168 
169         container_->Add(back);
170         container_->Add(label);
171         positionY_ += RADIUS + GAP + TITLE_HEIGHT;
172     }
173 }
174 
UIKitUIArcLabelTestAlign003()175 void UITestArcLabel::UIKitUIArcLabelTestAlign003()
176 {
177     if (container_ != nullptr) {
178         InnerTestTitle("弧形文本在0到90度之间右对齐 ", positionX_, positionY_);
179         positionY_ += TITLE_HEIGHT + GAP;
180         UIView* back = new UIView();
181         back->SetPosition(positionX_, positionY_ + GAP);
182         back->Resize(RADIUS, RADIUS);
183         back->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
184         back->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
185 
186         UIArcLabel* label = new UIArcLabel();
187         label->SetArcTextCenter(positionX_, CENTER_Y + positionY_);
188         label->SetArcTextRadius(RADIUS);
189         label->SetArcTextAngle(0, 90);                    // 0: start angle, 90: end angle
190         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
191         label->SetText("RIGHT");
192         label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT);
193         label->SetStyle(STYLE_LETTER_SPACE, 6); // 6: space
194 
195         container_->Add(back);
196         container_->Add(label);
197         positionY_ += RADIUS + GAP + TITLE_HEIGHT;
198     }
199 }
200 } // namespace OHOS
201