• 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_POSITION_PARAM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_POSITION_PARAM_H
18 
19 #include <optional>
20 
21 #include "base/geometry/animatable_dimension.h"
22 #include "base/geometry/calc_dimension.h"
23 #include "base/geometry/dimension.h"
24 #include "core/components/common/layout/constants.h"
25 #include "core/pipeline/base/constants.h"
26 
27 namespace OHOS::Ace {
28 
29 constexpr int32_t HORIZONTAL_DIRECTION_RANGE = 3;
30 constexpr int32_t VERTICAL_DIRECTION_RANGE = 6;
31 constexpr int32_t HORIZONTAL_DIRECTION_START_INDEX = 7;
32 constexpr int32_t HORIZONTAL_DIRECTION_END_INDEX = 8;
33 
34 struct PositionParam {
35     std::pair<AnimatableDimension, bool> left = { AnimatableDimension(0.0, DimensionUnit::PX), false };
36     std::pair<AnimatableDimension, bool> right = { AnimatableDimension(0.0, DimensionUnit::PX), false };
37     std::pair<AnimatableDimension, bool> top = { AnimatableDimension(0.0, DimensionUnit::PX), false };
38     std::pair<AnimatableDimension, bool> bottom = { AnimatableDimension(0.0, DimensionUnit::PX), false };
39     std::pair<Dimension, Dimension> anchor = {0.0_px, 0.0_px};
40     PositionType type = PositionType::PTRELATIVE;
41 };
42 
43 struct EdgesParam {
44     std::optional<Dimension> top;
45     std::optional<Dimension> left;
46     std::optional<Dimension> bottom;
47     std::optional<Dimension> right;
48     std::optional<Dimension> start;
49     std::optional<Dimension> end;
50     EdgesParam() = default;
51 
SetTopEdgesParam52     void SetTop(const CalcDimension& top)
53     {
54         this->top = top;
55     }
56 
SetLeftEdgesParam57     void SetLeft(const CalcDimension& left)
58     {
59         this->left = left;
60     }
61 
SetBottomEdgesParam62     void SetBottom(const CalcDimension& bottom)
63     {
64         this->bottom = bottom;
65     }
66 
SetRightEdgesParam67     void SetRight(const CalcDimension& right)
68     {
69         this->right = right;
70     }
71 
72     bool operator==(const EdgesParam& rhs) const
73     {
74         return ((this->top == rhs.top) && (this->left == rhs.left) && (this->bottom == rhs.bottom) &&
75                 (this->right == rhs.right));
76     }
77 
ToStringEdgesParam78     std::string ToString() const
79     {
80         std::string str;
81         str.append("top: [").append(top.has_value() ? top->ToString() : "NA").append("]");
82         str.append("left: [").append(left.has_value() ? left->ToString() : "NA").append("]");
83         str.append("right: [").append(right.has_value() ? right->ToString() : "NA").append("]");
84         str.append("bottom: [").append(bottom.has_value() ? bottom->ToString() : "NA").append("]");
85         return str;
86     }
87 };
88 
89 enum class AlignDirection {
90     LEFT = 0,
91     MIDDLE,
92     RIGHT,
93     TOP,
94     CENTER,
95     BOTTOM,
96     START,
97     END,
98 };
99 struct AlignRule {
100     std::string anchor;
101     union {
102         HorizontalAlign horizontal;
103         VerticalAlign vertical;
104     };
105 
106     bool operator==(const AlignRule& right) const
107     {
108         return ((this->anchor == right.anchor) && (this->vertical == right.vertical) &&
109                 (this->horizontal == right.horizontal));
110     }
111     bool operator!=(const AlignRule& right) const
112     {
113         return !operator==(right);
114     }
115 };
116 
117 enum class ChainStyle {
118     SPREAD,
119     SPREAD_INSIDE,
120     PACKED,
121 };
122 
123 enum class LineDirection {
124     VERTICAL,
125     HORIZONTAL,
126 };
127 
128 enum class BarrierDirection {
129     LEFT,
130     RIGHT,
131     TOP,
132     BOTTOM,
133     START,
134     END,
135 };
136 
137 struct GuidelineInfo {
138     std::string id;
139     LineDirection direction = LineDirection::VERTICAL;
140     std::optional<Dimension> start;
141     std::optional<Dimension> end;
142 
143     bool operator==(const GuidelineInfo& right) const
144     {
145         return ((this->id == right.id) && (this->direction == right.direction) &&
146                 (this->start == right.start) && (this->end == right.end));
147     }
148 };
149 
150 struct ChainInfo {
151     std::optional<LineDirection> direction;
152     std::optional<ChainStyle> style;
153 
154     bool operator==(const ChainInfo& right) const
155     {
156         return ((this->direction == right.direction) && (this->style == right.style));
157     }
158 };
159 
160 struct BarrierInfo {
161     std::string id;
162     BarrierDirection direction = BarrierDirection::LEFT;
163     std::vector<std::string> referencedId;
164 
165     bool operator==(const BarrierInfo& right) const
166     {
167         return ((this->id == right.id) && (this->direction == right.direction) &&
168                 (this->referencedId == right.referencedId));
169     }
170 };
171 } // namespace OHOS::Ace
172 
173 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_POSITION_PARAM_H
174