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 /**
17  * @addtogroup UI_Layout
18  * @{
19  *
20  * @brief Defines UI layouts such as <b>FlexLayout</b> and <b>GridLayout</b>.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file layout.h
28  *
29  * @brief Declares the base class of the layout, which indicates the basic data types and operations that may be
30  *        used in the layout.
31  *
32  * @since 1.0
33  * @version 1.0
34  */
35 
36 #ifndef GRAPHIC_LITE_LAYOUT_H
37 #define GRAPHIC_LITE_LAYOUT_H
38 
39 #include "components/ui_view_group.h"
40 
41 namespace OHOS {
42 using DirectionType = uint8_t;
43 using AlignType = uint8_t;
44 /* Arranges child views by row from left to right. */
45 const DirectionType LAYOUT_HOR = 0;
46 /* Arranges child views by row from right to left. */
47 const DirectionType LAYOUT_HOR_R = 1;
48 /* Arranges child views by column from top to bottom. */
49 const DirectionType LAYOUT_VER = 2;
50 /* Arranges child views by column from bottom to top. */
51 const DirectionType LAYOUT_VER_R = 3;
52 
53 /* Places all child views from the start point to the end point. */
54 const AlignType ALIGN_START = 0;
55 /* Places all child views from the end point to the start point. */
56 const AlignType ALIGN_END = 1;
57 /* Places all child views in the center. */
58 const AlignType ALIGN_CENTER = 2;
59 /* Evenly places all child views between the start point and end point. The distance between the start point and
60    the end as well as the distance between the end point and the end is the same as that between child views. */
61 const AlignType ALIGN_EVENLY = 3;
62 /* Evenly places all child views between the start point and end point. The distance between the start point and
63    the end as well as the distance between the end point and the end is half of the distance between child views. */
64 const AlignType ALIGN_AROUND = 4;
65 /* Evenly places all child views between the start point and end point. No left or right margin is reserved. */
66 const AlignType ALIGN_BETWEEN = 5;
67 
68 /**
69  * @brief Defines the base class of the layout, which indicates the basic data types and operations that may be used in
70  *        the layout.
71  *
72  * @since 1.0
73  * @version 1.0
74  */
75 class Layout : public UIViewGroup {
76 public:
77     /**
78      * @brief A default constructor used to create a <b>Layout</b> instance.
79      * @since 1.0
80      * @version 1.0
81      */
Layout()82     Layout() : direction_(LAYOUT_HOR) {}
83 
84     /**
85      * @brief A destructor used to delete the <b>Layout</b> instance.
86      * @since 1.0
87      * @version 1.0
88      */
~Layout()89     virtual ~Layout() {}
90 
91     /**
92      * @brief Sets the layout direction.
93      * @param direction Indicates the direction of the layout. Available values are as follows:
94      *                  LAYOUT_HOR: from left to right
95      *                  LAYOUT_HOR_R: from right to left
96      *                  LAYOUT_VER: from top to bottom
97      *                  LAYOUT_VER_R: from bottom to top
98      * @since 1.0
99      * @version 1.0
100      */
SetLayoutDirection(const DirectionType & direction)101     void SetLayoutDirection(const DirectionType& direction)
102     {
103         direction_ = direction;
104     }
105 
106 protected:
107     DirectionType direction_;
108 };
109 } // namespace OHOS
110 #endif // GRAPHIC_LITE_LAYOUT_H
111