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_border_margin_padding.h"
17 #include "common/screen.h"
18 #include "components/text_adapter.h"
19 #include "components/ui_arc_label.h"
20 #include "components/ui_box_progress.h"
21 #include "components/ui_canvas.h"
22 #include "components/ui_circle_progress.h"
23 #include "components/ui_image_animator.h"
24 #include "components/ui_label_button.h"
25 #include "components/ui_list.h"
26 #include "components/ui_qrcode.h"
27 #include "components/ui_radio_button.h"
28 #include "components/ui_slider.h"
29 #include "components/ui_swipe_view.h"
30 #include "test_resource_config.h"
31
32 namespace OHOS {
33 static ImageAnimatorInfo g_imageAnimatorInfo[4] = {
34 {IMAGE_ANIMATOR_0_PATH, {84, 108}, 116, 116, IMG_SRC_FILE_PATH},
35 {IMAGE_ANIMATOR_1_PATH, {84, 108}, 116, 116, IMG_SRC_FILE_PATH},
36 {IMAGE_ANIMATOR_2_PATH, {84, 108}, 116, 116, IMG_SRC_FILE_PATH},
37 {IMAGE_ANIMATOR_3_PATH, {84, 108}, 116, 116, IMG_SRC_FILE_PATH},
38 };
39
40 class MarginListener : public UICheckBox::OnChangeListener {
41 public:
MarginListener(UITestBorderMarginPadding * view)42 explicit MarginListener(UITestBorderMarginPadding* view)
43 {
44 view_ = view;
45 }
46
~MarginListener()47 virtual ~MarginListener() {}
48
OnChange(UICheckBox::UICheckBoxState state)49 bool OnChange(UICheckBox::UICheckBoxState state) override
50 {
51 if (state == UICheckBox::SELECTED) {
52 view_->style_.SetStyle(STYLE_MARGIN_LEFT, MARGIN_SIZE);
53 view_->style_.SetStyle(STYLE_MARGIN_TOP, MARGIN_SIZE);
54 view_->style_.SetStyle(STYLE_MARGIN_RIGHT, MARGIN_SIZE);
55 view_->style_.SetStyle(STYLE_MARGIN_BOTTOM, MARGIN_SIZE);
56 } else {
57 view_->style_.SetStyle(STYLE_MARGIN_LEFT, 0);
58 view_->style_.SetStyle(STYLE_MARGIN_TOP, 0);
59 view_->style_.SetStyle(STYLE_MARGIN_RIGHT, 0);
60 view_->style_.SetStyle(STYLE_MARGIN_BOTTOM, 0);
61 }
62 view_->ReloadTest();
63 return true;
64 }
65
66 private:
67 static constexpr int16_t MARGIN_SIZE = 30;
68 UITestBorderMarginPadding* view_ = nullptr;
69 };
70
71 class BorderListener : public UICheckBox::OnChangeListener {
72 public:
BorderListener(UITestBorderMarginPadding * view)73 explicit BorderListener(UITestBorderMarginPadding* view)
74 {
75 view_ = view;
76 }
77
~BorderListener()78 virtual ~BorderListener() {}
79
OnChange(UICheckBox::UICheckBoxState state)80 bool OnChange(UICheckBox::UICheckBoxState state) override
81 {
82 if (state == UICheckBox::SELECTED) {
83 view_->style_.SetStyle(STYLE_BORDER_WIDTH, 20); // 20: border width
84 view_->style_.SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE);
85 view_->style_.SetStyle(STYLE_BORDER_COLOR, Color::Blue().full);
86 } else {
87 view_->style_.SetStyle(STYLE_BORDER_WIDTH, 0);
88 }
89 view_->ReloadTest();
90 return true;
91 }
92
93 private:
94 UITestBorderMarginPadding* view_ = nullptr;
95 };
96
97 class PaddingListener : public UICheckBox::OnChangeListener {
98 public:
PaddingListener(UITestBorderMarginPadding * view)99 explicit PaddingListener(UITestBorderMarginPadding* view)
100 {
101 view_ = view;
102 }
103
~PaddingListener()104 virtual ~PaddingListener() {}
105
OnChange(UICheckBox::UICheckBoxState state)106 bool OnChange(UICheckBox::UICheckBoxState state) override
107 {
108 if (state == UICheckBox::SELECTED) {
109 view_->style_.SetStyle(STYLE_PADDING_LEFT, PADDING_SIZE);
110 view_->style_.SetStyle(STYLE_PADDING_TOP, PADDING_SIZE);
111 view_->style_.SetStyle(STYLE_PADDING_RIGHT, PADDING_SIZE);
112 view_->style_.SetStyle(STYLE_PADDING_BOTTOM, PADDING_SIZE);
113 } else {
114 view_->style_.SetStyle(STYLE_PADDING_LEFT, 0);
115 view_->style_.SetStyle(STYLE_PADDING_TOP, 0);
116 view_->style_.SetStyle(STYLE_PADDING_RIGHT, 0);
117 view_->style_.SetStyle(STYLE_PADDING_BOTTOM, 0);
118 }
119 view_->ReloadTest();
120 return true;
121 }
122
123 private:
124 static constexpr int16_t PADDING_SIZE = 30;
125 UITestBorderMarginPadding* view_ = nullptr;
126 };
127
SetUp()128 void UITestBorderMarginPadding::SetUp()
129 {
130 if (container_ == nullptr) {
131 container_ = new UIViewGroup();
132 }
133 if (scroll_ == nullptr) {
134 scroll_ = new UIScrollView();
135 }
136 if (layoutButton_ == nullptr) {
137 layoutButton_ = new GridLayout();
138 }
139 if (listScroll_ == nullptr) {
140 listScroll_ = new ListLayout();
141 }
142
143 UIToggleButton* marginBtn = new UIToggleButton();
144 if (marginBtn == nullptr) {
145 return;
146 }
147 marginBtn->SetViewId(UI_TEST_MARGIN_BTN);
148
149 UIToggleButton* borderBtn = new UIToggleButton();
150 if (borderBtn == nullptr) {
151 return;
152 }
153 borderBtn->SetViewId(UI_TEST_BORDER_BTN);
154
155 UIToggleButton* paddingBtn = new UIToggleButton();
156 if (paddingBtn == nullptr) {
157 return;
158 }
159 paddingBtn->SetViewId(UI_TEST_PADDING_BTN);
160
161 SetUpButtons(marginBtn, borderBtn, paddingBtn);
162
163 if (borderListener_ == nullptr) {
164 borderListener_ = new BorderListener(this);
165 }
166 borderBtn->SetOnChangeListener(borderListener_);
167 if (marginListener_ == nullptr) {
168 marginListener_ = new MarginListener(this);
169 }
170 marginBtn->SetOnChangeListener(marginListener_);
171 if (paddingListener_ == nullptr) {
172 paddingListener_ = new PaddingListener(this);
173 }
174 paddingBtn->SetOnChangeListener(paddingListener_);
175
176 SetUpAdapterData();
177 InitStyle();
178 }
179
SetUpButtons(UIToggleButton * marginBtn,UIToggleButton * borderBtn,UIToggleButton * paddingBtn)180 void UITestBorderMarginPadding::SetUpButtons(UIToggleButton* marginBtn,
181 UIToggleButton* borderBtn,
182 UIToggleButton* paddingBtn)
183 {
184 UILabel* labelMargin = new UILabel();
185 UILabel* labelBorder = new UILabel();
186 UILabel* labelPadding = new UILabel();
187
188 container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
189 Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
190
191 scroll_->SetPosition(0, 0, Screen::GetInstance().GetWidth() - BUTTON_GROUP_WIDTH,
192 Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
193 scroll_->SetThrowDrag(true);
194 scroll_->SetHorizontalScrollState(false);
195 scroll_->SetScrollBlankSize(100); // 100 : blank size
196
197 layoutButton_->SetPosition(Screen::GetInstance().GetWidth() - BUTTON_GROUP_WIDTH, 0, BUTTON_GROUP_WIDTH,
198 Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
199 layoutButton_->SetRows(3); // 3: rows
200 layoutButton_->SetCols(2); // 2: cols
201
202 listScroll_ = new ListLayout(ListLayout::VERTICAL);
203 listScroll_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
204 listScroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full);
205 listScroll_->SetPosition(0, 0, Screen::GetInstance().GetWidth() - BUTTON_GROUP_WIDTH,
206 Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
207 scroll_->Add(listScroll_);
208
209 container_->Add(scroll_);
210 container_->Add(layoutButton_);
211 marginBtn->Resize(64, 64); // 64 : button size
212 borderBtn->Resize(64, 64); // 64 : button size
213 paddingBtn->Resize(64, 64); // 64 : button size
214
215 labelMargin->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
216 labelMargin->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 15); // 15: font size
217 labelMargin->SetText("margin ON/OFF");
218 labelMargin->ReMeasure();
219
220 labelBorder->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
221 labelBorder->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 15); // 15: font size
222 labelBorder->SetText("border ON/OFF");
223 labelBorder->ReMeasure();
224
225 labelPadding->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
226 labelPadding->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 15); // 15: font size
227 labelPadding->SetText("padding ON/OFF");
228 labelPadding->ReMeasure();
229
230 layoutButton_->Add(labelMargin);
231 layoutButton_->Add(marginBtn);
232 layoutButton_->Add(labelBorder);
233 layoutButton_->Add(borderBtn);
234 layoutButton_->Add(labelPadding);
235 layoutButton_->Add(paddingBtn);
236 layoutButton_->LayoutChildren();
237 }
238
SetUpAdapterData()239 void UITestBorderMarginPadding::SetUpAdapterData()
240 {
241 if (adapterData_ == nullptr) {
242 adapterData_ = new List<const char*>();
243 adapterData_->PushBack("000");
244 adapterData_->PushBack("111");
245 adapterData_->PushBack("222");
246 adapterData_->PushBack("333");
247 adapterData_->PushBack("444");
248 adapterData_->PushBack("555");
249 adapterData_->PushBack("666");
250 adapterData_->PushBack("777");
251 adapterData_->PushBack("888");
252 adapterData_->PushBack("999");
253 adapterData_->PushBack("AAA");
254 adapterData_->PushBack("BBB");
255 adapterData_->PushBack("CCC");
256 }
257 }
258
TearDown()259 void UITestBorderMarginPadding::TearDown()
260 {
261 if (borderListener_ != nullptr) {
262 delete borderListener_;
263 borderListener_ = nullptr;
264 }
265 if (marginListener_ != nullptr) {
266 delete marginListener_;
267 marginListener_ = nullptr;
268 }
269 if (paddingListener_ != nullptr) {
270 delete paddingListener_;
271 paddingListener_ = nullptr;
272 }
273 if (adapterData_ != nullptr) {
274 adapterData_->Clear();
275 delete adapterData_;
276 adapterData_ = nullptr;
277 }
278 if (picker_ != nullptr) {
279 listScroll_->Remove(picker_);
280 delete picker_;
281 picker_ = nullptr;
282 }
283 if (chart_ != nullptr) {
284 listScroll_->Remove(chart_);
285 chart_->ClearDataSerial();
286 delete dataSerial_;
287 dataSerial_ = nullptr;
288 delete chart_;
289 chart_ = nullptr;
290 }
291 DeleteChildren(container_);
292 container_ = nullptr;
293 scroll_ = nullptr;
294 layoutButton_ = nullptr;
295 listScroll_ = nullptr;
296 }
297
ReloadTest()298 void UITestBorderMarginPadding::ReloadTest()
299 {
300 int16_t heightBefor = listScroll_->GetHeight();
301 int16_t yBefor = listScroll_->GetY();
302
303 scroll_->RemoveAll();
304 if (chart_ != nullptr) {
305 listScroll_->Remove(chart_);
306 chart_->ClearDataSerial();
307 delete dataSerial_;
308 dataSerial_ = nullptr;
309 delete chart_;
310 chart_ = nullptr;
311 }
312
313 if (picker_ != nullptr) {
314 listScroll_->Remove(picker_);
315 delete picker_;
316 picker_ = nullptr;
317 }
318
319 DeleteChildren(listScroll_);
320 listScroll_ = new ListLayout(ListLayout::VERTICAL);
321 listScroll_->SetPosition(0, 0, Screen::GetInstance().GetWidth() - BUTTON_GROUP_WIDTH,
322 Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
323 listScroll_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
324 listScroll_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Olive().full);
325 scroll_->Add(listScroll_);
326 GetTestView();
327
328 int16_t yAfter = listScroll_->GetHeight() * yBefor / heightBefor;
329 scroll_->ScrollBy(0, yAfter);
330 container_->Invalidate();
331 }
332
InitStyle()333 void UITestBorderMarginPadding::InitStyle()
334 {
335 style_.SetStyle(STYLE_MARGIN_LEFT, 0);
336 style_.SetStyle(STYLE_MARGIN_TOP, 0);
337 style_.SetStyle(STYLE_MARGIN_RIGHT, 0);
338 style_.SetStyle(STYLE_MARGIN_BOTTOM, 0);
339
340 style_.SetStyle(STYLE_BORDER_WIDTH, 0);
341
342 style_.SetStyle(STYLE_PADDING_LEFT, 0);
343 style_.SetStyle(STYLE_PADDING_TOP, 0);
344 style_.SetStyle(STYLE_PADDING_RIGHT, 0);
345 style_.SetStyle(STYLE_PADDING_BOTTOM, 0);
346 }
347
GetTestView()348 const UIView* UITestBorderMarginPadding::GetTestView()
349 {
350 UIKitUITestBorderMarginPaddingTest001();
351 UIKitUITestBorderMarginPaddingTest002();
352 UIKitUITestBorderMarginPaddingTest003();
353 UIKitUITestBorderMarginPaddingTest004();
354 UIKitUITestBorderMarginPaddingTest005();
355 UIKitUITestBorderMarginPaddingTest006();
356 UIKitUITestBorderMarginPaddingTest007();
357 UIKitUITestBorderMarginPaddingTest008();
358 UIKitUITestBorderMarginPaddingTest009();
359 UIKitUITestBorderMarginPaddingTest011();
360 UIKitUITestBorderMarginPaddingTest012();
361 UIKitUITestBorderMarginPaddingTest013();
362 UIKitUITestBorderMarginPaddingTest014();
363 UIKitUITestBorderMarginPaddingTest015();
364 UIKitUITestBorderMarginPaddingTest016();
365 UIKitUITestBorderMarginPaddingTest017();
366 UIKitUITestBorderMarginPaddingTest018();
367 return container_;
368 }
369
AddTitle(const char * text)370 void UITestBorderMarginPadding::AddTitle(const char* text)
371 {
372 UILabel* titleLabel = new UILabel();
373 titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
374 titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
375 titleLabel->SetText(text);
376 listScroll_->Add(titleLabel);
377 }
378
UIKitUITestBorderMarginPaddingTest001()379 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest001()
380 {
381 AddTitle("UIView");
382 UIView* view = new UIView();
383 view->SetStyle(style_);
384 view->Resize(200, 100); // 200:size 100: size
385 listScroll_->Add(view);
386 }
387
UIKitUITestBorderMarginPaddingTest002()388 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest002()
389 {
390 AddTitle("UILabel");
391 UILabel* view = new UILabel();
392 view->SetStyle(style_);
393 view->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
394 view->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
395 view->Resize(200, 100); // 200:size 100: size
396 view->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
397 view->SetText("TEST UILABEL");
398 listScroll_->Add(view);
399 }
400
UIKitUITestBorderMarginPaddingTest003()401 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest003()
402 {
403 AddTitle("ArcLabel");
404 UIArcLabel* view = new UIArcLabel();
405 view->SetStyle(style_);
406 view->SetArcTextCenter(180, 180); // 180: text center
407 view->SetArcTextRadius(150); // 150: text radius
408 view->SetArcTextAngle(0, 270); // 0: start angle 270: end angle
409 view->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: font size
410 view->SetText("012345678ABCDEF0123456789ABCDE");
411 listScroll_->Add(view);
412 }
413
UIKitUITestBorderMarginPaddingTest004()414 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest004()
415 {
416 AddTitle("BoxProgress");
417 UIBoxProgress* boxProgress = new UIBoxProgress();
418 boxProgress->SetStyle(style_);
419 boxProgress->SetPosition(10, 10, 100, 10); // 10: x 10: y 100: width 10: height
420 boxProgress->SetValue(20); // 20: value
421 boxProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
422 boxProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
423 listScroll_->Add(boxProgress);
424 }
425
UIKitUITestBorderMarginPaddingTest005()426 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest005()
427 {
428 AddTitle("UIViewGroup");
429 UIViewGroup* group = new UIViewGroup();
430 group->SetStyle(style_);
431 group->Resize(200, 100); // 200: size 100: size
432 listScroll_->Add(group);
433
434 UIButton* button = new UIButton();
435 button->SetPosition(0, 0, 100, 50); // 100: size 50: size
436 group->Add(button);
437 }
438
UIKitUITestBorderMarginPaddingTest006()439 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest006()
440 {
441 AddTitle("UICanvas");
442 UICanvas* canvas = new UICanvas();
443 canvas->SetStyle(style_);
444 canvas->Resize(400, 400); // 400: size
445 Paint paint;
446 paint.SetStrokeWidth(10); // 10: line width
447 // {10, 10}: Start point coordinates x, y; {300, 10}: end point coordinates x, y
448 canvas->DrawLine({10, 10}, {300, 10}, paint);
449
450 paint.SetStrokeColor(Color::Yellow());
451 canvas->DrawCurve({100, 50}, {150, 50}, {150, 50}, {150, 100}, paint);
452
453 paint.SetStyle(Paint::PaintStyle::FILL_STYLE);
454 paint.SetFillColor(Color::Yellow());
455 paint.SetStrokeWidth(30); // 30: line width
456 // {10, 200}: left corner coordinates point, 50: width, 50: rectangle style
457 canvas->DrawRect({10, 200}, 50, 50, paint);
458
459 paint.SetStyle(Paint::PaintStyle::STROKE_FILL_STYLE);
460 paint.SetFillColor(Color::Yellow());
461 paint.SetStrokeColor(Color::Blue());
462 paint.SetStrokeWidth(10); // 10: line width
463 paint.SetOpacity(127); // 127: opacity
464 // {300, 100}: circle center coordinates, 30: circle radius
465 canvas->DrawCircle({300, 100}, 30, paint);
466 listScroll_->Add(canvas);
467 }
468
UIKitUITestBorderMarginPaddingTest007()469 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest007()
470 {
471 AddTitle("UIChart");
472 chart_ = new UIChartPolyline();
473 chart_->SetStyle(style_);
474 chart_->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, VIEW_DISTANCE_TO_TOP_SIDE);
475 chart_->SetWidth(454); // 454: width
476 chart_->SetHeight(250); // 250: height
477
478 dataSerial_ = new UIChartDataSerial();
479 dataSerial_->SetMaxDataCount(5); // 5: number of data points
480 Point pointArray[5] = {{0, 2478}, {1, 2600}, {2, 3000}, {3, 3200}, {4, 3500}};
481 dataSerial_->AddPoints(pointArray, 5); // 5: number of data points
482 dataSerial_->SetLineColor(Color::Red());
483 dataSerial_->SetFillColor(Color::Red());
484 dataSerial_->EnableGradient(true);
485
486 UIXAxis& xAxis = chart_->GetXAxis();
487 UIYAxis& yAxis = chart_->GetYAxis();
488 xAxis.SetMarkNum(5); // 5: number of scales
489 xAxis.SetDataRange(0, 5); // 0: minimum value, 5: maximum value
490 yAxis.SetDataRange(0, 5000); // 0: minimum value, 5000: maximum value
491
492 chart_->SetGradientOpacity(25, 127); // 25: min opacity, 127: max opacity
493 chart_->AddDataSerial(dataSerial_);
494
495 listScroll_->Add(chart_);
496 }
UIKitUITestBorderMarginPaddingTest008()497 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest008()
498 {
499 AddTitle("Button");
500 UIViewGroup* group = new UIViewGroup();
501 group->Resize(Screen::GetInstance().GetWidth() - BUTTON_GROUP_WIDTH, 200); // 200: button UIViewGroup height
502
503 UIButton* button = new UIButton();
504 button->SetStyleForState(STYLE_MARGIN_LEFT, style_.marginLeft_, UIButton::RELEASED);
505 button->SetStyleForState(STYLE_MARGIN_LEFT, style_.marginLeft_, UIButton::PRESSED);
506 button->SetStyleForState(STYLE_MARGIN_TOP, style_.marginTop_, UIButton::RELEASED);
507 button->SetStyleForState(STYLE_MARGIN_TOP, style_.marginTop_, UIButton::PRESSED);
508 button->SetStyleForState(STYLE_MARGIN_RIGHT, style_.marginRight_, UIButton::RELEASED);
509 button->SetStyleForState(STYLE_MARGIN_RIGHT, style_.marginRight_, UIButton::PRESSED);
510 button->SetStyleForState(STYLE_MARGIN_BOTTOM, style_.marginBottom_, UIButton::RELEASED);
511 button->SetStyleForState(STYLE_MARGIN_BOTTOM, style_.marginBottom_, UIButton::PRESSED);
512
513 button->SetStyleForState(STYLE_BORDER_WIDTH, style_.borderWidth_, UIButton::RELEASED);
514 button->SetStyleForState(STYLE_BORDER_WIDTH, style_.borderWidth_, UIButton::PRESSED);
515 button->SetStyleForState(STYLE_BORDER_OPA, style_.borderOpa_, UIButton::RELEASED);
516 button->SetStyleForState(STYLE_BORDER_OPA, style_.borderOpa_, UIButton::PRESSED);
517 button->SetStyleForState(STYLE_BORDER_COLOR, style_.borderColor_.full, UIButton::RELEASED);
518 button->SetStyleForState(STYLE_BORDER_COLOR, style_.borderColor_.full, UIButton::PRESSED);
519
520 button->SetStyleForState(STYLE_PADDING_LEFT, style_.paddingLeft_, UIButton::RELEASED);
521 button->SetStyleForState(STYLE_PADDING_LEFT, style_.paddingLeft_, UIButton::PRESSED);
522 button->SetStyleForState(STYLE_PADDING_TOP, style_.paddingTop_, UIButton::RELEASED);
523 button->SetStyleForState(STYLE_PADDING_TOP, style_.paddingTop_, UIButton::PRESSED);
524 button->SetStyleForState(STYLE_PADDING_RIGHT, style_.paddingRight_, UIButton::RELEASED);
525 button->SetStyleForState(STYLE_PADDING_RIGHT, style_.paddingRight_, UIButton::PRESSED);
526 button->SetStyleForState(STYLE_PADDING_BOTTOM, style_.paddingBottom_, UIButton::RELEASED);
527 button->SetStyleForState(STYLE_PADDING_BOTTOM, style_.paddingBottom_, UIButton::PRESSED);
528
529 button->SetPosition(50, 30, 70, 50); // 50: x 30: y 70: width 50: height
530 group->Add(button);
531
532 UICheckBox* checkbox = new UICheckBox();
533 checkbox->SetStyle(style_);
534 checkbox->SetPosition(200, 30, 50, 50); // 200: x-coordinate, 30: y-coordinate, 50: size
535 group->Add(checkbox);
536
537 UIRadioButton* radioButton = new UIRadioButton();
538 radioButton->SetStyle(style_);
539 radioButton->SetPosition(350, 30, 50, 50); // 350: x-coordinate, 30: y-coordinate, 50: size
540 group->Add(radioButton);
541
542 UIToggleButton* toggleButton = new UIToggleButton();
543 toggleButton->SetStyle(style_);
544 toggleButton->SetPosition(500, 30, 50, 50); // 500: x-coordinate, 30: y-coordinate, 50: size
545 group->Add(toggleButton);
546
547 listScroll_->Add(group);
548 }
549
UIKitUITestBorderMarginPaddingTest009()550 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest009()
551 {
552 AddTitle("UICircleProgress");
553 UICircleProgress* circleProgress = new UICircleProgress();
554 circleProgress->SetStyle(style_);
555 circleProgress->Resize(150, 150); // 150: width 150: height
556 circleProgress->SetCenterPosition(75, 75); // 75: position x 75: position y
557 circleProgress->SetRadius(50); // 50: radius
558 circleProgress->SetValue(20); // 20: value
559 listScroll_->Add(circleProgress);
560 }
561
UIKitUITestBorderMarginPaddingTest010()562 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest010()
563 {
564 AddTitle("UIImageAnimatorView");
565 UIImageAnimatorView* imageAnimator = new UIImageAnimatorView();
566 imageAnimator->SetStyle(style_);
567 imageAnimator->SetPosition(50, 50, 200, 200); // 50 : offset 50 : offset 200 : offset 200: offset
568 imageAnimator->SetImageAnimatorSrc(g_imageAnimatorInfo, 4, 100); // 4: the number of images, 100: updating time
569 imageAnimator->Start();
570 listScroll_->Add(imageAnimator);
571 }
572
UIKitUITestBorderMarginPaddingTest011()573 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest011()
574 {
575 AddTitle("UIImageView");
576 UIImageView* imageView = new UIImageView();
577 imageView->SetStyle(style_);
578 imageView->SetWidth(50); // 50 : size
579 imageView->SetHeight(50); // 50 : size
580 imageView->SetSrc(BLUE_RGB888_IMAGE_PATH);
581 listScroll_->Add(imageView);
582 }
583
UIKitUITestBorderMarginPaddingTest012()584 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest012()
585 {
586 AddTitle("UILabelButton");
587 UILabelButton* button = new UILabelButton();
588 button->SetStyleForState(STYLE_MARGIN_LEFT, style_.marginLeft_, UIButton::RELEASED);
589 button->SetStyleForState(STYLE_MARGIN_LEFT, style_.marginLeft_, UIButton::PRESSED);
590 button->SetStyleForState(STYLE_MARGIN_TOP, style_.marginTop_, UIButton::RELEASED);
591 button->SetStyleForState(STYLE_MARGIN_TOP, style_.marginTop_, UIButton::PRESSED);
592 button->SetStyleForState(STYLE_MARGIN_RIGHT, style_.marginRight_, UIButton::RELEASED);
593 button->SetStyleForState(STYLE_MARGIN_RIGHT, style_.marginRight_, UIButton::PRESSED);
594 button->SetStyleForState(STYLE_MARGIN_BOTTOM, style_.marginBottom_, UIButton::RELEASED);
595 button->SetStyleForState(STYLE_MARGIN_BOTTOM, style_.marginBottom_, UIButton::PRESSED);
596
597 button->SetStyleForState(STYLE_BORDER_WIDTH, style_.borderWidth_, UIButton::RELEASED);
598 button->SetStyleForState(STYLE_BORDER_WIDTH, style_.borderWidth_, UIButton::PRESSED);
599 button->SetStyleForState(STYLE_BORDER_OPA, style_.borderOpa_, UIButton::RELEASED);
600 button->SetStyleForState(STYLE_BORDER_OPA, style_.borderOpa_, UIButton::PRESSED);
601 button->SetStyleForState(STYLE_BORDER_COLOR, style_.borderColor_.full, UIButton::RELEASED);
602 button->SetStyleForState(STYLE_BORDER_COLOR, style_.borderColor_.full, UIButton::PRESSED);
603
604 button->SetStyleForState(STYLE_PADDING_LEFT, style_.paddingLeft_, UIButton::RELEASED);
605 button->SetStyleForState(STYLE_PADDING_LEFT, style_.paddingLeft_, UIButton::PRESSED);
606 button->SetStyleForState(STYLE_PADDING_TOP, style_.paddingTop_, UIButton::RELEASED);
607 button->SetStyleForState(STYLE_PADDING_TOP, style_.paddingTop_, UIButton::PRESSED);
608 button->SetStyleForState(STYLE_PADDING_RIGHT, style_.paddingRight_, UIButton::RELEASED);
609 button->SetStyleForState(STYLE_PADDING_RIGHT, style_.paddingRight_, UIButton::PRESSED);
610 button->SetStyleForState(STYLE_PADDING_BOTTOM, style_.paddingBottom_, UIButton::RELEASED);
611 button->SetStyleForState(STYLE_PADDING_BOTTOM, style_.paddingBottom_, UIButton::PRESSED);
612 button->SetWidth(200); // 200 : size
613 button->SetHeight(50); // 50 : size
614 button->SetText("Test UILabelButton");
615 listScroll_->Add(button);
616 }
617
UIKitUITestBorderMarginPaddingTest013()618 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest013()
619 {
620 AddTitle("UIList");
621 if (adapter_ == nullptr) {
622 adapter_ = new TextAdapter();
623 }
624 adapter_->SetData(adapterData_);
625 adapter_->GetStyle() = style_;
626
627 UIList* list = new UIList(UIList::VERTICAL);
628 list->SetIntercept(true);
629 list->SetStyle(style_);
630 list->Resize(300, 400); // 300 : size, 400 : size
631 list->SetAdapter(adapter_);
632 listScroll_->Add(list);
633 }
634
UIKitUITestBorderMarginPaddingTest014()635 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest014()
636 {
637 AddTitle("UIPicker");
638 picker_ = new UIPicker();
639 picker_->SetIntercept(true);
640 picker_->SetStyle(style_);
641 picker_->SetFontId(16, 18); // 16:back font id 18:high light font id
642 picker_->SetItemHeight(50); // 50: height
643 picker_->SetTextColor(Color::White(), Color::Red());
644 picker_->SetValues(-5, 20); // -5: start 20:end
645 picker_->Resize(300, 400); // 300: picker size 400: picker size
646 listScroll_->Add(picker_);
647 }
648
UIKitUITestBorderMarginPaddingTest015()649 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest015()
650 {
651 AddTitle("UIQrcode");
652 UIQrcode* qrcode = new UIQrcode();
653 qrcode->SetStyle(style_);
654 qrcode->Resize(60, 60); // 60: height
655 qrcode->SetQrcodeInfo("Hello\n Test of GUI");
656 listScroll_->Add(qrcode);
657 }
658
UIKitUITestBorderMarginPaddingTest016()659 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest016()
660 {
661 AddTitle("UIScroll");
662 UIScrollView* scroll = new UIScrollView();
663 scroll->SetIntercept(true);
664 scroll->SetStyle(style_);
665 scroll->Resize(200, 200); // 200: size
666
667 UILabelButton* button = new UILabelButton();
668 button->SetPosition(0, 0, 300, 300); // 300: size
669 button->SetText("button1");
670 scroll->Add(button);
671 listScroll_->Add(scroll);
672 }
UIKitUITestBorderMarginPaddingTest017()673 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest017()
674 {
675 AddTitle("UISlider");
676 UISlider* slider = new UISlider();
677 slider->SetIntercept(true);
678 slider->SetStyle(style_);
679 slider->Resize(50, 300); // 50: width; 300: height
680 slider->SetValidHeight(250); // 250: valid height;
681 slider->SetValue(20); // 20: progress bar current value
682 slider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
683 listScroll_->Add(slider);
684 }
685
UIKitUITestBorderMarginPaddingTest018()686 void UITestBorderMarginPadding::UIKitUITestBorderMarginPaddingTest018()
687 {
688 AddTitle("UISwipe");
689 UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL);
690 swipe->SetIntercept(true);
691 swipe->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
692 swipe->Resize(200, 200); // 200: size
693 swipe->SetBlankSize(100); // 100: is blank size
694 UILabel* view1 = new UILabel();
695 view1->SetStyle(style_);
696 view1->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
697 view1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
698 view1->SetPosition(0, 0, 150, 150); // 150: size
699 view1->SetText("label1");
700 swipe->Add(view1);
701 UILabel* view2 = new UILabel();
702 view2->SetStyle(style_);
703 view2->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
704 view2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
705 view2->SetPosition(0, 0, 150, 150); // 150: size
706 view2->SetText("label2");
707 swipe->Add(view2);
708 UILabel* view3 = new UILabel();
709 view3->SetStyle(style_);
710 view3->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
711 view3->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
712 view3->SetPosition(0, 0, 150, 150); // 150: size
713 view3->SetText("label3");
714 swipe->Add(view3);
715
716 listScroll_->Add(swipe);
717 }
718 } // namespace OHOS
719