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 #ifndef UI_TEST_VIEW_PERCENT_H
17 #define UI_TEST_VIEW_PERCENT_H
18 
19 #include <string>
20 #include "components/ui_label_button.h"
21 #include "components/ui_scroll_view.h"
22 #include "components/ui_view.h"
23 #include "components/ui_view_group.h"
24 #include "graphic_config.h"
25 #include "layout/flex_layout.h"
26 #include "layout/layout.h"
27 #include "ui_test.h"
28 
29 namespace OHOS {
30 constexpr char* UI_TEST_RESET = "reset";
31 constexpr char* UI_TEST_BIGGER = "bigger";
32 constexpr char* UI_TEST_SMALLER = "smaller";
33 class UITestViewPercent : public UITest, public UIView::OnClickListener {
34 public:
UITestViewPercent()35     UITestViewPercent() {}
~UITestViewPercent()36     ~UITestViewPercent() {}
37     void SetUp() override;
38     void TearDown() override;
39     const UIView* GetTestView() override;
40     bool OnClick(UIView& view, const ClickEvent& event) override;
41 
42 private:
SetUpButton(Layout & controller,UILabelButton & btn,const std::string title,const char * id)43     void SetUpButton(Layout& controller, UILabelButton& btn, const std::string title, const char* id)
44     {
45         if (id == nullptr) {
46             return;
47         }
48 
49         controller.Add(&btn);
50         btn.Resize(BUTTON_WIDHT1, BUTTON_HEIGHT1);
51         btn.SetText(title.c_str());
52         btn.SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE);
53         btn.SetOnClickListener(this);
54         btn.SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED);
55         btn.SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED);
56         btn.SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE);
57         btn.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED);
58         btn.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED);
59         btn.SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE);
60         btn.SetViewId(id);
61     }
62     void InitView();
63     void InitFlexLayout();
64     void InitViewGroup() const;
65     void InitContainer();
66     void AddElement(int16_t index);
67     UIScrollView* container_ = nullptr;
68     FlexLayout* flexLayout_ = nullptr;
69     UIViewGroup* viewGroup = nullptr;
70     UIView* view1_ = nullptr;
71     UIView* view2_ = nullptr;
72     UIView* view3_ = nullptr;
73     UILabelButton* resetfBtn_ = nullptr;
74     UILabelButton* BiggerBtn_ = nullptr;
75     UILabelButton* SmallerBtn_ = nullptr;
76 };
77 } // namespace OHOS
78 #endif // UI_TEST_VIEW_PERCENT_H
79 
80