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