• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_CONTAINER_INFO_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_CONTAINER_INFO_H
18 
19 #include <string>
20 
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/layout/grid_layout_info.h"
23 
24 namespace OHOS::Ace {
25 
26 constexpr int32_t UNDEFINED_INT = -1;
27 constexpr Dimension UNDEFINED_DIMENSION(-1.0, DimensionUnit::VP);
28 
29 class GridContainerInfo : public GridLayoutInfo {
30     DECLARE_ACE_TYPE(GridContainerInfo, GridLayoutInfo);
31 
32 public:
33     class Builder {
34     public:
Builder()35         Builder()
36         {
37             containerInfo_ = AceType::Claim(new GridContainerInfo());
38         }
SetColumns(int32_t columns)39         void SetColumns(int32_t columns)
40         {
41             if (columns > 0) {
42                 containerInfo_->columns_ = columns;
43             }
44         }
SetGutterWidth(const Dimension & gutterWidth)45         void SetGutterWidth(const Dimension& gutterWidth)
46         {
47             if (GreatOrEqual(gutterWidth.Value(), 0.0)) {
48                 containerInfo_->gutterWidth_ = gutterWidth;
49             }
50         }
SetMarginLeft(const Dimension & marginLeft)51         void SetMarginLeft(const Dimension& marginLeft)
52         {
53             if (GreatOrEqual(marginLeft.Value(), 0.0)) {
54                 containerInfo_->marginLeft_ = marginLeft;
55             }
56         }
SetMarginRight(const Dimension & marginRight)57         void SetMarginRight(const Dimension& marginRight)
58         {
59             if (GreatOrEqual(marginRight.Value(), 0.0)) {
60                 containerInfo_->marginRight_ = marginRight;
61             }
62         }
SetPaddingLeft(const Dimension & paddingLeft)63         void SetPaddingLeft(const Dimension& paddingLeft)
64         {
65             if (GreatOrEqual(paddingLeft.Value(), 0.0)) {
66                 containerInfo_->paddingLeft_ = paddingLeft;
67             }
68         }
SetPaddingRight(const Dimension & paddingRight)69         void SetPaddingRight(const Dimension& paddingRight)
70         {
71             if (GreatOrEqual(paddingRight.Value(), 0.0)) {
72                 containerInfo_->paddingRight_ = paddingRight;
73             }
74         }
SetSizeType(const GridSizeType & sizeType)75         void SetSizeType(const GridSizeType& sizeType)
76         {
77             containerInfo_->sizeType_ = sizeType;
78         }
SetColumnType(const GridColumnType & columnType)79         void SetColumnType(const GridColumnType& columnType)
80         {
81             containerInfo_->columnType_ = columnType;
82         }
SetGridTemplateType(const GridTemplateType & templateType)83         void SetGridTemplateType(const GridTemplateType& templateType)
84         {
85             containerInfo_->templateType_ = templateType;
86         }
Build()87         const RefPtr<GridContainerInfo>& Build() const
88         {
89             return containerInfo_;
90         }
91 
92     private:
93         RefPtr<GridContainerInfo> containerInfo_;
94     };
95 
96     DEFINE_COPY_CONSTRUCTOR_AND_COPY_OPERATOR_AND_COMPARE_OPERATOR_WITH_PROPERTIES(GridContainerInfo,
97         (templateType_)(currentSizeType_)(sizeType_)(columns_)(gutterWidth_)(marginLeft_)(marginRight_)\
98         (paddingLeft_)(paddingRight_)(containerWidth_)(columnWidth_)(columnType_));
99 
100     ~GridContainerInfo() override = default;
101 
GetColumnWidth()102     double GetColumnWidth() const
103     {
104         return columnWidth_;
105     }
106 
GetColumnType()107     GridColumnType GetColumnType() const
108     {
109         return columnType_;
110     }
111     GridSizeType GetSizeType() const;
112     int32_t GetColumns() const;
113     Dimension ACE_EXPORT GetGutterWidth() const;
114     Dimension GetMarginLeft() const;
115     Dimension GetMarginRight() const;
116 
117     /*
118      * Use system screen width build column width.
119      */
120     void ACE_EXPORT BuildColumnWidth();
121     void BuildColumnWidth(double width);
122 
123 private:
124     GridContainerInfo() = default;
125     GridTemplateType templateType_ = GridTemplateType::NORMAL;
126     // current used size type
127     GridSizeType currentSizeType_ = GridSizeType::UNDEFINED;
128     GridSizeType sizeType_ = GridSizeType::UNDEFINED;
129     // container total column number
130     int32_t columns_ = UNDEFINED_INT;
131     Dimension gutterWidth_ = UNDEFINED_DIMENSION;
132     Dimension marginLeft_ = UNDEFINED_DIMENSION;
133     Dimension marginRight_ = UNDEFINED_DIMENSION;
134     Dimension paddingLeft_ = UNDEFINED_DIMENSION;
135     Dimension paddingRight_ = UNDEFINED_DIMENSION;
136 
137     double containerWidth_ = 0.0;
138     double columnWidth_ = 0.0;
139     GridColumnType columnType_ = GridColumnType::NONE;
140 };
141 
142 } // namespace OHOS::Ace
143 
144 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_CONTAINER_INFO_H
145