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