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_ADVANCED_LAYOUT_H 17 #define UI_TEST_ADVANCED_LAYOUT_H 18 19 #include "components/ui_label.h" 20 #include "components/ui_label_button.h" 21 #include "components/ui_scroll_view.h" 22 #include "layout/flex_layout.h" 23 #include "layout/grid_layout.h" 24 #include "ui_test.h" 25 26 namespace OHOS { 27 class UITestAdvancedLayout : public UITest, public UIView::OnClickListener { 28 public: UITestAdvancedLayout()29 UITestAdvancedLayout() : withMargin_(false) {} ~UITestAdvancedLayout()30 ~UITestAdvancedLayout() {} 31 void SetUp() override; 32 void TearDown() override; 33 const UIView* GetTestView() override; 34 35 /** 36 * @brief Test flex layout function. 37 */ 38 void UIKit_Layout_Test_FlexLayout_001(); 39 /** 40 * @brief Test grid layout function. 41 */ 42 void UIKit_Layout_Test_GridLayout_001(); 43 44 bool OnClick(UIView& view, const ClickEvent& event) override; 45 void OnClickButton(const UIView& view); 46 private: 47 UIScrollView* container_ = nullptr; 48 GridLayout* flexController_ = nullptr; 49 GridLayout* gridController_ = nullptr; 50 FlexLayout* fTarget_ = nullptr; 51 GridLayout* gTarget_ = nullptr; 52 53 UILabelButton* resetfBtn_ = nullptr; 54 UILabelButton* horfBtn_ = nullptr; 55 UILabelButton* horfRBtn_ = nullptr; 56 UILabelButton* verfBtn_ = nullptr; 57 UILabelButton* verfRBtn_ = nullptr; 58 UILabelButton* wrapBtn_ = nullptr; 59 UILabelButton* addElefBtn_ = nullptr; 60 UILabelButton* addTextElefBtn_ = nullptr; 61 UILabelButton* majorStartBtn_ = nullptr; 62 UILabelButton* majorEndBtn_ = nullptr; 63 UILabelButton* majorCenterBtn_ = nullptr; 64 UILabelButton* majorEvenBtn_ = nullptr; 65 UILabelButton* majorAroundBtn_ = nullptr; 66 UILabelButton* majorBetBtn_ = nullptr; 67 UILabelButton* secStartBtn_ = nullptr; 68 UILabelButton* secEndBtn_ = nullptr; 69 UILabelButton* secCenterBtn_ = nullptr; 70 UILabelButton* secInvalidBtn_ = nullptr; 71 UILabelButton* marginfBtn_ = nullptr; 72 UILabelButton* layoutChildrenfBtn_ = nullptr; 73 UILabelButton* horgBtn_ = nullptr; 74 UILabelButton* horgRBtn_ = nullptr; 75 UILabelButton* vergBtn_ = nullptr; 76 UILabelButton* vergRBtn_ = nullptr; 77 UILabelButton* incRowsBtn_ = nullptr; 78 UILabelButton* decRowsBtn_ = nullptr; 79 UILabelButton* incColsBtn_ = nullptr; 80 UILabelButton* decColsBtn_ = nullptr; 81 UILabelButton* addElegBtn_ = nullptr; 82 UILabelButton* resetgBtn_ = nullptr; 83 UILabelButton* margingBtn_ = nullptr; 84 UILabelButton* layoutChildrengBtn_ = nullptr; 85 86 int16_t w_ = 10; // 10: width 87 int16_t h_ = 10; // 10: height 88 int16_t rows_ = 0; 89 int16_t cols_ = 0; 90 bool withMargin_; 91 SetUpButton(Layout * controller,UILabelButton * btn,const char * title)92 void SetUpButton(Layout* controller, UILabelButton* btn, const char* title) 93 { 94 controller->Add(btn); 95 btn->Resize(BUTTON_WIDHT2, BUTTON_HEIGHT2); 96 btn->SetText(title); 97 btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); 98 btn->SetOnClickListener(this); 99 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::RELEASED); 100 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::PRESSED); 101 btn->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_STYLE_BORDER_RADIUS_VALUE, UIButton::INACTIVE); 102 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::RELEASED); 103 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::PRESSED); 104 btn->SetStyleForState(STYLE_BACKGROUND_COLOR, BUTTON_STYLE_BACKGROUND_COLOR_VALUE, UIButton::INACTIVE); 105 } 106 AddElement(Layout * layout)107 void AddElement(Layout* layout) 108 { 109 UIView* view = new UIView(); 110 view->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); 111 view->Resize(w_++, h_++); 112 if (withMargin_) { 113 view->SetStyle(STYLE_MARGIN_LEFT, 10); // 10: margin left 114 view->SetStyle(STYLE_MARGIN_RIGHT, 15); // 15: margin right 115 view->SetStyle(STYLE_MARGIN_TOP, 20); // 20: margin top 116 view->SetStyle(STYLE_MARGIN_BOTTOM, 25); // 25: margin bottom 117 } 118 layout->Add(view); 119 } 120 AddTextElement(Layout * layout)121 void AddTextElement(Layout* layout) 122 { 123 UILabel* label = new UILabel(); 124 label->Resize(80, 30); 125 label->SetLineBreakMode(0); 126 label->SetText("Hello, OHOS!"); 127 layout->Add(label); 128 } 129 Clear(Layout * layout)130 void Clear(Layout* layout) const 131 { 132 if (layout == nullptr) { 133 return; 134 } 135 UIView* child = layout->GetChildrenHead(); 136 while (child != nullptr) { 137 UIView* temp = child; 138 child = child->GetNextSibling(); 139 layout->Remove(temp); 140 delete temp; 141 } 142 } 143 }; 144 } // namespace OHOS 145 #endif // UI_TEST_INPUT_EVENT_H 146