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