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 49 EdgesParam() = default; 50 SetTopEdgesParam51 void SetTop(const CalcDimension& top) 52 { 53 this->top = top; 54 } 55 SetLeftEdgesParam56 void SetLeft(const CalcDimension& left) 57 { 58 this->left = left; 59 } 60 SetBottomEdgesParam61 void SetBottom(const CalcDimension& bottom) 62 { 63 this->bottom = bottom; 64 } 65 SetRightEdgesParam66 void SetRight(const CalcDimension& right) 67 { 68 this->right = right; 69 } 70 71 bool operator==(const EdgesParam& rhs) const 72 { 73 return ((this->top == rhs.top) && (this->left == rhs.left) && (this->bottom == rhs.bottom) && 74 (this->right == rhs.right)); 75 } 76 ToStringEdgesParam77 std::string ToString() const 78 { 79 std::string str; 80 str.append("top: [").append(top.has_value() ? top->ToString() : "NA").append("]"); 81 str.append("left: [").append(left.has_value() ? left->ToString() : "NA").append("]"); 82 str.append("right: [").append(right.has_value() ? right->ToString() : "NA").append("]"); 83 str.append("bottom: [").append(bottom.has_value() ? bottom->ToString() : "NA").append("]"); 84 return str; 85 } 86 }; 87 88 enum class AlignDirection { 89 LEFT = 0, 90 MIDDLE, 91 RIGHT, 92 TOP, 93 CENTER, 94 BOTTOM, 95 START, 96 END, 97 }; 98 struct AlignRule { 99 std::string anchor; 100 union { 101 HorizontalAlign horizontal; 102 VerticalAlign vertical; 103 }; 104 105 bool operator==(const AlignRule& right) const 106 { 107 return ((this->anchor == right.anchor) && (this->vertical == right.vertical) && 108 (this->horizontal == right.horizontal)); 109 } 110 }; 111 112 enum class ChainStyle { 113 SPREAD, 114 SPREAD_INSIDE, 115 PACKED, 116 }; 117 118 enum class LineDirection { 119 VERTICAL, 120 HORIZONTAL, 121 }; 122 123 enum class BarrierDirection { 124 LEFT, 125 RIGHT, 126 TOP, 127 BOTTOM, 128 START, 129 END, 130 }; 131 132 struct GuidelineInfo { 133 std::string id; 134 LineDirection direction = LineDirection::VERTICAL; 135 std::optional<Dimension> start; 136 std::optional<Dimension> end; 137 138 bool operator==(const GuidelineInfo& right) const 139 { 140 return ((this->id == right.id) && (this->direction == right.direction) && 141 (this->start == right.start) && (this->end == right.end)); 142 } 143 }; 144 145 struct ChainInfo { 146 std::optional<LineDirection> direction; 147 std::optional<ChainStyle> style; 148 149 bool operator==(const ChainInfo& right) const 150 { 151 return ((this->direction == right.direction) && (this->style == right.style)); 152 } 153 }; 154 155 struct BarrierInfo { 156 std::string id; 157 BarrierDirection direction = BarrierDirection::LEFT; 158 std::vector<std::string> referencedId; 159 160 bool operator==(const BarrierInfo& right) const 161 { 162 return ((this->id == right.id) && (this->direction == right.direction) && 163 (this->referencedId == right.referencedId)); 164 } 165 }; 166 } // namespace OHOS::Ace 167 168 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_POSITION_PARAM_H 169