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 GRAPHIC_LITE_GRID_LAYOUT_H
17 #define GRAPHIC_LITE_GRID_LAYOUT_H
18 
19 /**
20  * @addtogroup UI_Layout
21  * @{
22  *
23  * @brief Defines UI layouts such as <b>FlexLayout</b> and <b>GridLayout</b>.
24  *
25  * @since 1.0
26  * @version 1.0
27  */
28 
29 /**
30  * @file grid_layout.h
31  *
32  * @brief Declares a grid layout container. You can perform simple grid layout on child views that the container holds.
33  *
34  * @since 1.0
35  * @version 1.0
36  */
37 
38 #include "layout.h"
39 
40 namespace OHOS {
41 /**
42  * @brief Defines a grid layout container. You can perform simple grid layout on child views that the container holds.
43  *
44  * @since 1.0
45  * @version 1.0
46  */
47 class GridLayout : public Layout {
48 public:
49     /**
50      * @brief A default constructor used to create a <b>GridLayout</b> instance.
51      * @since 1.0
52      * @version 1.0
53      */
GridLayout()54     GridLayout() : rows_(0), cols_(0) {}
55 
56     /**
57      * @brief A destructor used to delete the <b>GridLayout</b> instance.
58      * @since 1.0
59      * @version 1.0
60      */
~GridLayout()61     virtual ~GridLayout() {}
62 
63     /**
64      * @brief Sets the number of rows in a grid.
65      * @param rows Indicates the number of rows to set.
66      * @since 1.0
67      * @version 1.0
68      */
SetRows(const uint16_t & rows)69     void SetRows(const uint16_t& rows)
70     {
71         rows_ = rows;
72     }
73 
74     /**
75      * @brief Sets the number of columns in a grid.
76      * @param cols Indicates the number of columns to set.
77      * @since 1.0
78      * @version 1.0
79      */
SetCols(const uint16_t & cols)80     void SetCols(const uint16_t& cols)
81     {
82         cols_ = cols;
83     }
84 
85     /**
86      * @brief Lays out all child views according to the preset arrangement mode.
87      * @param needInvalidate Specifies whether to refresh the invalidated area after the layout is complete.
88      *                       Value <b>true</b> means to refresh the invalidated area after the layout is complete,
89      *                       and <b>false</b> means the opposite.
90      * @since 1.0
91      * @version 1.0
92      */
93     void LayoutChildren(bool needInvalidate = false) override;
94 
95 private:
96     void LayoutHorizontal();
97     void LayoutVertical();
98 
99     uint16_t rows_;
100     uint16_t cols_;
101 };
102 } // namespace OHOS
103 #endif // GRAPHIC_LITE_GRID_LAYOUT_H
104