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 "graphic_config.h"
17 
18 #if ENABLE_DEBUG
19 #include "ui_test_dump_dom.h"
20 
21 #include "common/screen.h"
22 #include "components/ui_arc_label.h"
23 #include "components/ui_box_progress.h"
24 #include "components/ui_checkbox.h"
25 #include "components/ui_circle_progress.h"
26 #include "components/ui_image_view.h"
27 #include "components/ui_label.h"
28 #include "components/ui_label_button.h"
29 #include "components/ui_radio_button.h"
30 #include "components/ui_slider.h"
31 #include "components/ui_toggle_button.h"
32 #include "dfx/ui_dump_dom_tree.h"
33 #include "imgdecode/cache_manager.h"
34 #include "test_resource_config.h"
35 #include "gfx_utils/graphic_log.h"
36 
37 namespace OHOS {
SetUp()38 void UITestDumpDomTree::SetUp()
39 {
40     if (container_ == nullptr) {
41         container_ = new UIScrollView();
42         container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - BACK_BUTTON_HEIGHT);
43         container_->SetViewId("dump_scroll_view");
44     }
45 }
46 
TearDown()47 void UITestDumpDomTree::TearDown()
48 {
49     TearDown001();
50     if (clickDumpDomListener7_ != nullptr) {
51         delete clickDumpDomListener7_;
52         clickDumpDomListener7_ = nullptr;
53     }
54     if (clickDumpDomListener8_ != nullptr) {
55         delete clickDumpDomListener8_;
56         clickDumpDomListener8_ = nullptr;
57     }
58     if (clickDumpDomListener9_ != nullptr) {
59         delete clickDumpDomListener9_;
60         clickDumpDomListener9_ = nullptr;
61     }
62     if (clickDumpDomListener10_ != nullptr) {
63         delete clickDumpDomListener10_;
64         clickDumpDomListener10_ = nullptr;
65     }
66     if (clickDumpDomListener11_ != nullptr) {
67         delete clickDumpDomListener11_;
68         clickDumpDomListener11_ = nullptr;
69     }
70     if (clickDumpDomListener12_ != nullptr) {
71         delete clickDumpDomListener12_;
72         clickDumpDomListener12_ = nullptr;
73     }
74     positionY_ = 0;
75     DeleteChildren(container_);
76     container_ = nullptr;
77 }
78 
TearDown001()79 void UITestDumpDomTree::TearDown001()
80 {
81     if (clickDumpDomListener1_ != nullptr) {
82         delete clickDumpDomListener1_;
83         clickDumpDomListener1_ = nullptr;
84     }
85     if (clickDumpDomListener2_ != nullptr) {
86         delete clickDumpDomListener2_;
87         clickDumpDomListener2_ = nullptr;
88     }
89     if (clickDumpDomListener3_ != nullptr) {
90         delete clickDumpDomListener3_;
91         clickDumpDomListener3_ = nullptr;
92     }
93     if (clickDumpDomListener4_ != nullptr) {
94         delete clickDumpDomListener4_;
95         clickDumpDomListener4_ = nullptr;
96     }
97     if (clickDumpDomListener5_ != nullptr) {
98         delete clickDumpDomListener5_;
99         clickDumpDomListener5_ = nullptr;
100     }
101     if (clickDumpDomListener6_ != nullptr) {
102         delete clickDumpDomListener6_;
103         clickDumpDomListener6_ = nullptr;
104     }
105 }
106 
GetTestView()107 const UIView* UITestDumpDomTree::GetTestView()
108 {
109     positionY_ = 0;
110     UIKitTestDumpDom001();
111     UIKitTestDumpDom002();
112     UIKitTestDumpDom003();
113     UIKitTestDumpDom004();
114     UIKitTestDumpDom005();
115     UIKitTestDumpDom006();
116     return container_;
117 }
118 
119 class TestBtnOnClickDumpDomListener : public UIView::OnClickListener {
120 public:
TestBtnOnClickDumpDomListener(UIView * uiView,const char * id)121     TestBtnOnClickDumpDomListener(UIView* uiView, const char* id) : uiView_(uiView), id_(id) {}
~TestBtnOnClickDumpDomListener()122     ~TestBtnOnClickDumpDomListener() {}
OnClick(UIView & view,const ClickEvent & event)123     bool OnClick(UIView& view, const ClickEvent& event) override
124     {
125         char* tmpPtr = UIDumpDomTree::GetInstance()->DumpDomNode(id_);
126         if (tmpPtr != nullptr) {
127             cJSON_free(tmpPtr);
128         }
129         uiView_->Invalidate();
130         return true;
131     }
132 
133 private:
134     UIView* uiView_;
135     const char* id_;
136 };
137 
138 class TestBtnOnClickDumpDomTreeListener : public UIView::OnClickListener {
139 public:
TestBtnOnClickDumpDomTreeListener(UIView * uiView,const char * id)140     TestBtnOnClickDumpDomTreeListener(UIView* uiView, const char* id) : uiView_(uiView), id_(id) {}
~TestBtnOnClickDumpDomTreeListener()141     ~TestBtnOnClickDumpDomTreeListener() {}
OnClick(UIView & view,const ClickEvent & event)142     bool OnClick(UIView& view, const ClickEvent& event) override
143     {
144         if (UIDumpDomTree::GetInstance()->DumpDomTree(id_)) {
145             if (id_ == nullptr) {
146                 GRAPHIC_LOGI("dump tree from rootView success\n");
147             } else {
148                 GRAPHIC_LOGI("dump tree from id success\n");
149             }
150         } else {
151             GRAPHIC_LOGI("dump tree failed\n");
152         }
153         uiView_->Invalidate();
154         return true;
155     }
156 
157 private:
158     UIView* uiView_;
159     const char* id_;
160 };
161 
UIKitTestDumpDom001()162 void UITestDumpDomTree::UIKitTestDumpDom001()
163 {
164     if (container_ != nullptr) {
165         UILabel* label = GetTitleLabel("dump checkbox");
166         container_->Add(label);
167         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
168         positionY_ += label->GetHeight();
169 
170         GridLayout* layout = new GridLayout();
171         layout->SetPosition(VIEW_DISTANCE_TO_LEFT_SIDE, VIEW_DISTANCE_TO_TOP_SIDE,
172         // 2: half of screen width; 88: decrease screen width; 180: height
173             Screen::GetInstance().GetWidth() / 2 - 88, 180);
174         layout->SetViewId("dump_group");
175         container_->Add(layout);
176         positionY_ += layout->GetHeight();
177         layout->SetRows(3); // 3: row
178         layout->SetCols(3); // 3: col
179         CreateButtons(layout);
180         layout->LayoutChildren();
181     }
182 }
183 
CreateButtons(GridLayout * layout)184 void UITestDumpDomTree::CreateButtons(GridLayout* layout)
185 {
186     if (layout == nullptr) {
187         return;
188     }
189     UICheckBox* checkBox = new UICheckBox();
190     layout->Add(checkBox);
191     checkBox->SetState(UICheckBox::SELECTED);
192     checkBox->SetViewId("dump_checkbox");
193 
194     UIRadioButton* radioButton = new UIRadioButton("aaa");
195     layout->Add(radioButton);
196     radioButton->SetState(UICheckBox::UNSELECTED);
197     radioButton->SetViewId("dump_radiobutton");
198 
199     UIToggleButton* toggleButton = new UIToggleButton();
200     layout->Add(toggleButton);
201     toggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0);
202     toggleButton->SetViewId("dump_togglebutton");
203 
204     CreateLabelButtons001(layout);
205 }
206 
CreateLabelButtons001(GridLayout * layout)207 void UITestDumpDomTree::CreateLabelButtons001(GridLayout* layout)
208 {
209     UILabelButton* dumpButton1 = GetLabelButton("dump");
210     layout->Add(dumpButton1);
211     /* dump node here */
212     if (clickDumpDomListener1_ == nullptr) {
213         clickDumpDomListener1_ = static_cast<UIView::OnClickListener*>(
214             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton1), "dump_checkbox"));
215     }
216     dumpButton1->SetOnClickListener(clickDumpDomListener1_);
217 
218     UILabelButton* dumpButton2 = GetLabelButton("dump");
219     layout->Add(dumpButton2);
220     /* dump node here */
221     if (clickDumpDomListener2_ == nullptr) {
222         clickDumpDomListener2_ = static_cast<UIView::OnClickListener*>(
223             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton2), "dump_radiobutton"));
224     }
225     dumpButton2->SetOnClickListener(clickDumpDomListener2_);
226 
227     UILabelButton* dumpButton3 = GetLabelButton("dump");
228     layout->Add(dumpButton3);
229     /* dump node here */
230     if (clickDumpDomListener3_ == nullptr) {
231         clickDumpDomListener3_ = static_cast<UIView::OnClickListener*>(
232             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton3), "dump_togglebutton"));
233     }
234     dumpButton3->SetOnClickListener(clickDumpDomListener3_);
235 
236     UILabelButton* dumpButton4 = GetLabelButton("dump_all ");
237     layout->Add(dumpButton4);
238 
239     if (clickDumpDomListener4_ == nullptr) {
240         clickDumpDomListener4_ = static_cast<UIView::OnClickListener*>(
241             new TestBtnOnClickDumpDomTreeListener(static_cast<UIView*>(dumpButton4), nullptr));
242     }
243     dumpButton4->SetOnClickListener(clickDumpDomListener4_);
244 
245     UILabelButton* dumpButton5 = GetLabelButton("dump_group");
246     layout->Add(dumpButton5);
247     if (clickDumpDomListener5_ == nullptr) {
248         clickDumpDomListener5_ = static_cast<UIView::OnClickListener*>(
249             new TestBtnOnClickDumpDomTreeListener(static_cast<UIView*>(dumpButton5), "dump_group"));
250     }
251     dumpButton5->SetOnClickListener(clickDumpDomListener5_);
252 }
253 
UIKitTestDumpDom002()254 void UITestDumpDomTree::UIKitTestDumpDom002()
255 {
256     if (container_ != nullptr) {
257         UIViewGroup* group2 = new UIViewGroup();
258         group2->SetPosition(Screen::GetInstance().GetWidth() / 2, 0); // 2: half of screen width
259         group2->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half of screen width
260         group2->SetHeight(200); // 200: height
261         group2->SetViewId("dump_group2");
262         container_->Add(group2);
263         positionY_ += group2->GetHeight();
264 
265         UILabel* label = GetTitleLabel("dump image");
266         group2->Add(label);
267         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
268 
269         UIImageView* imageView = new UIImageView();
270         imageView->SetPosition(VIEW_DISTANCE_TO_TOP_SIDE, TEXT_DISTANCE_TO_LEFT_SIDE);
271         imageView->SetWidth(50); // 50: width
272         imageView->SetHeight(50); // 50: height
273         imageView->SetSrc(BLUE_RGB888_IMAGE_PATH);
274         imageView->SetViewId("dump_image");
275         group2->Add(imageView);
276 
277         UILabelButton* dumpButton1 = GetLabelButton("dump");
278         dumpButton1->SetPosition(160, 73); // 160: x-coordinate, 73: y-coordinate
279         group2->Add(dumpButton1);
280         dumpButton1->SetText("dump");
281         /* dump node here */
282         if (clickDumpDomListener6_ == nullptr) {
283             clickDumpDomListener6_ = static_cast<UIView::OnClickListener*>(
284                 new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton1), "dump_image"));
285         }
286         dumpButton1->SetOnClickListener(clickDumpDomListener6_);
287     }
288 }
289 
UIKitTestDumpDom003()290 void UITestDumpDomTree::UIKitTestDumpDom003()
291 {
292     if (container_ != nullptr) {
293         UIViewGroup* group5 = new UIViewGroup();
294         group5->SetPosition(0, 260); // 260: y-coordinate
295         group5->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half of screen width
296         group5->SetHeight(200); // 200: height
297         group5->SetViewId("dump_group5");
298         container_->Add(group5);
299         positionY_ += group5->GetHeight();
300 
301         UILabel* label = GetTitleLabel("dump slider progress");
302         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
303         group5->Add(label);
304 
305         UISlider* slider = new UISlider();
306         // 50: new width, 100: new height
307         slider->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, VIEW_DISTANCE_TO_TOP_SIDE, 50, 100);
308         slider->SetValidHeight(250); // 250: valid height
309         slider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
310         slider->SetRange(100, 0); // 100: max
311         slider->SetValue(50);     // 50: value of progress bar
312         slider->SetStep(0);
313         slider->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0, 182, 191).full); // 182, 191: color
314         slider->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(255, 152, 0).full); // 255, 152: color
315         slider->SetKnobWidth(50); // 50: knob width
316         slider->SetKnobStyle(StyleDefault::GetSliderKnobStyle());
317         slider->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr));
318         slider->EnableBackground(true);
319         slider->SetViewId("dump_slider");
320         group5->Add(slider);
321 
322         UILabelButton* dumpButton = GetLabelButton("dump");
323         dumpButton->SetPosition(120, 73); // 120: x-coordinate, 73: y-coordinate
324         /* dump node here */
325         if (clickDumpDomListener7_ == nullptr) {
326             clickDumpDomListener7_ = static_cast<UIView::OnClickListener*>(
327                 new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton), "dump_slider"));
328         }
329         dumpButton->SetOnClickListener(clickDumpDomListener7_);
330         group5->Add(dumpButton);
331     }
332 }
333 
UIKitTestDumpDom004()334 void UITestDumpDomTree::UIKitTestDumpDom004()
335 {
336     if (container_ != nullptr) {
337         UIViewGroup* group4 = new UIViewGroup();
338         group4->SetPosition(Screen::GetInstance().GetWidth() / 2, 260); // 2: half of screen width; 260: y-coordinate
339         group4->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half of screen width
340         group4->SetHeight(100); // 100: height
341         group4->SetViewId("dump_group4");
342         container_->Add(group4);
343         positionY_ += group4->GetHeight();
344 
345         UILabel* label = GetTitleLabel("dump box progress");
346         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
347         group4->Add(label);
348 
349         UIBoxProgress* boxProgress = new UIBoxProgress();
350         // 48: x-coordinate, 68: y-coordinate, 90: new width, 10: new height
351         boxProgress->SetPosition(48, 68, 90, 10);
352         boxProgress->SetDirection(UIBoxProgress::Direction::DIR_LEFT_TO_RIGHT);
353         boxProgress->SetValidHeight(10); // 10: valid height
354         boxProgress->SetValidWidth(100); // 100: valid width
355         boxProgress->SetRange(100, 0); // 100: max
356         boxProgress->SetValue(20); // 20 : value of progress bar
357         boxProgress->SetStep(0);
358         // 182, 191: color
359         boxProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0, 182, 191).full);
360         // 255, 152: color
361         boxProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(255, 152, 0).full);
362         boxProgress->SetImage(static_cast<char*>(nullptr));
363         boxProgress->EnableBackground(true);
364         boxProgress->SetViewId("dump_boxprogress");
365         group4->Add(boxProgress);
366         UILabelButton* dumpButton = GetLabelButton("dump");
367         dumpButton->SetPosition(160, 48); // 160: x-coordinate, 48: y-coordinate
368         /* dump node here */
369         if (clickDumpDomListener8_ == nullptr) {
370             clickDumpDomListener8_ = static_cast<UIView::OnClickListener*>(
371                 new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton), "dump_boxprogress"));
372         }
373         dumpButton->SetOnClickListener(clickDumpDomListener8_);
374         group4->Add(dumpButton);
375     }
376 }
377 
UIKitTestDumpDom005()378 void UITestDumpDomTree::UIKitTestDumpDom005()
379 {
380     if (container_ != nullptr) {
381         UIViewGroup* group3 = new UIViewGroup();
382         group3->SetPosition(0, 450); // 450: y-coordinate
383         group3->SetWidth(Screen::GetInstance().GetWidth() / 2 - VIEW_DISTANCE_TO_LEFT_SIDE); // 2: half of screen width
384         group3->SetHeight(500); // 500: height
385         group3->SetViewId("dump_group3");
386         container_->Add(group3);
387 
388         UILabel* label = GetTitleLabel("dump label");
389         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
390         group3->Add(label);
391 
392         UILabel* label2 = GetTitleLabel("UILabel");
393         label2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
394         label2->SetPosition(48, 58, 90, 29); // 48: x position, 58: y position, 90: width, 29: height
395         label2->SetViewId("dump_label");
396         group3->Add(label2);
397 
398         UILabelButton* labelButton = GetLabelButton("LabelButton");
399         labelButton->SetPosition(48, 108); // 48: x position, 108: y position
400         labelButton->SetViewId("dump_label_button");
401         group3->Add(labelButton);
402 
403         UIArcLabel* label3 = new UIArcLabel();
404         label3->SetArcTextCenter(70, 330); // 70: x position, 330: y position
405         label3->SetArcTextRadius(150);     // 150: radius
406         label3->SetArcTextAngle(0, 270);   // 0: start angle, 270: end angle
407         label3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
408         label3->SetText("012345678ABCDEF");
409         label3->SetStyle(STYLE_LETTER_SPACE, 30); // 30: letter space
410         label3->SetViewId("dump_arc_label");
411         group3->Add(label3);
412 
413         CreateButtons002(group3);
414     }
415 }
416 
CreateButtons002(UIViewGroup * group3)417 void UITestDumpDomTree::CreateButtons002(UIViewGroup* group3)
418 {
419     UILabelButton* dumpButton1 = GetLabelButton("dump");
420     dumpButton1->SetPosition(230, 48); // 230: x-coordinate, 48: y-coordinate
421     /* dump node here */
422     if (clickDumpDomListener9_ == nullptr) {
423         clickDumpDomListener9_ = static_cast<UIView::OnClickListener*>(
424             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton1), "dump_label"));
425     }
426     dumpButton1->SetOnClickListener(clickDumpDomListener9_);
427     group3->Add(dumpButton1);
428 
429     UILabelButton* dumpButton2 = GetLabelButton("dump");
430     dumpButton2->SetPosition(230, 108); // 230: x-coordinate, 108: y-coordinate
431     /* dump node here */
432     if (clickDumpDomListener10_ == nullptr) {
433         clickDumpDomListener10_ = static_cast<UIView::OnClickListener*>(
434             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton2), "dump_label_button"));
435     }
436     dumpButton2->SetOnClickListener(clickDumpDomListener10_);
437     group3->Add(dumpButton2);
438 
439     UILabelButton* dumpButton3 = GetLabelButton("dump");
440     dumpButton3->SetPosition(230, 310); // 230: x position, 310: y position
441     /* dump node here */
442     if (clickDumpDomListener11_ == nullptr) {
443         clickDumpDomListener11_ = static_cast<UIView::OnClickListener*>(
444             new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton3), "dump_arc_label"));
445     }
446     dumpButton3->SetOnClickListener(clickDumpDomListener11_);
447     group3->Add(dumpButton3);
448 }
449 
UIKitTestDumpDom006()450 void UITestDumpDomTree::UIKitTestDumpDom006()
451 {
452     if (container_ != nullptr) {
453         UIViewGroup* group6 = new UIViewGroup();
454         // 2: half of screen width; 450: screen height
455         group6->SetPosition(Screen::GetInstance().GetWidth() / 2, 450);
456         group6->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half of screen width
457         group6->SetHeight(250); // 250: height
458         group6->SetViewId("dump_group6");
459         container_->Add(group6);
460         positionY_ += group6->GetHeight();
461 
462         UILabel* label = GetTitleLabel("dump circle progress");
463         label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, TEXT_DISTANCE_TO_TOP_SIDE);
464         group6->Add(label);
465 
466         UICircleProgress* circleProgress = new UICircleProgress();
467         // 40: y-coordinate, 48: y-coordinate, 150: new width, 150: new height
468         circleProgress->SetPosition(40, 48, 150, 150);
469         circleProgress->SetCenterPosition(50, 50); // 50: x-coordinate, 50: y-coordinate
470         circleProgress->SetRadius(50); // 50: radius
471         circleProgress->SetValue(20); // 20: value of progress bar
472         circleProgress->SetStyle(STYLE_PADDING_LEFT, 10); // 10: padding left
473         circleProgress->SetStyle(STYLE_PADDING_TOP, 5); // 5: padding top
474         circleProgress->SetRange(100, 0); // 100: max
475         circleProgress->SetValue(50); // 50: value of progress bar
476         circleProgress->SetStartAngle(0);
477         circleProgress->SetEndAngle(360); // 360: end angle
478         circleProgress->SetStep(0);
479         circleProgress->SetBackgroundStyle(StyleDefault::GetProgressBackgroundStyle());
480         circleProgress->SetForegroundStyle(StyleDefault::GetProgressForegroundStyle());
481         circleProgress->SetLineColor(Color::White());
482         circleProgress->EnableBackground(true);
483         circleProgress->SetViewId("dump_circle_progress");
484         group6->Add(circleProgress);
485 
486         UILabelButton* dumpButton = GetLabelButton("dump");
487         dumpButton->SetPosition(170, 73); // 170: x-coordinate, 73: y-coordinate
488         /* dump node here */
489         if (clickDumpDomListener12_ == nullptr) {
490             clickDumpDomListener12_ = static_cast<UIView::OnClickListener*>(
491                 new TestBtnOnClickDumpDomListener(static_cast<UIView*>(dumpButton), "dump_circle_progress"));
492         }
493         dumpButton->SetOnClickListener(clickDumpDomListener12_);
494         group6->Add(dumpButton);
495     }
496 }
497 
GetLabelButton(const char * buttonname)498 UILabelButton* UITestDumpDomTree::GetLabelButton(const char* buttonname)
499 {
500     const int16_t labelButtonWidth = 120;
501     const int16_t labelButtonHeight = 40;
502     if (buttonname == nullptr) {
503         return nullptr;
504     }
505     UILabelButton* labelButton = new UILabelButton();
506     if (labelButton == nullptr) {
507         return nullptr;
508     }
509     labelButton->SetPosition(0, 0);
510     labelButton->Resize(labelButtonWidth, labelButtonHeight);
511     labelButton->SetText(buttonname);
512     labelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
513     labelButton->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED);
514     labelButton->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
515     labelButton->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
516     labelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED);
517     labelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED);
518     labelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE);
519     return labelButton;
520 }
521 } // namespace OHOS
522 #endif // ENABLE_DEBUG
523