1 /* 2 * Copyright (c) 2021-2022 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_FLEX_FLEX_ITEM_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FLEX_FLEX_ITEM_COMPONENT_H 18 19 #include "core/components/common/layout/grid_column_info.h" 20 #include "core/components/common/layout/position_param.h" 21 #include "core/components/flex/flex_item_element.h" 22 #include "core/components/flex/render_flex_item.h" 23 #include "core/pipeline/base/sole_child_component.h" 24 25 namespace OHOS::Ace { 26 27 class FlexItemComponent : public SoleChildComponent { 28 DECLARE_ACE_TYPE(FlexItemComponent, SoleChildComponent); 29 30 public: FlexItemComponent(double flexGrow,double flexShrink,double flexBasis)31 FlexItemComponent(double flexGrow, double flexShrink, double flexBasis) 32 : flexGrow_(flexGrow), flexShrink_(flexShrink), flexBasis_(Dimension(flexBasis)) {} FlexItemComponent(double flexGrow,double flexShrink,const Dimension & flexBasis)33 FlexItemComponent(double flexGrow, double flexShrink, const Dimension& flexBasis) 34 : flexGrow_(flexGrow), flexShrink_(flexShrink), flexBasis_(flexBasis) {} FlexItemComponent(double flexGrow,double flexShrink,double flexBasis,const RefPtr<Component> & child)35 FlexItemComponent(double flexGrow, double flexShrink, double flexBasis, const RefPtr<Component>& child) 36 : SoleChildComponent(child), flexGrow_(flexGrow), flexShrink_(flexShrink), flexBasis_(Dimension(flexBasis)) {} FlexItemComponent(double flexGrow,double flexShrink,const Dimension & flexBasis,const RefPtr<Component> & child)37 FlexItemComponent(double flexGrow, double flexShrink, const Dimension& flexBasis, const RefPtr<Component>& child) 38 : SoleChildComponent(child), flexGrow_(flexGrow), flexShrink_(flexShrink), flexBasis_(flexBasis) {} FlexItemComponent()39 FlexItemComponent() : FlexItemComponent(0.0, 1.0, -1.0) {} 40 ~FlexItemComponent() override = default; 41 CreateRenderNode()42 RefPtr<RenderNode> CreateRenderNode() override 43 { 44 return RenderFlexItem::Create(); 45 } 46 CreateElement()47 RefPtr<Element> CreateElement() override 48 { 49 return AceType::MakeRefPtr<FlexItemElement>(); 50 } 51 GetFlexGrow()52 double GetFlexGrow() const 53 { 54 return flexGrow_; 55 } 56 GetFlexShrink()57 double GetFlexShrink() const 58 { 59 return flexShrink_; 60 } 61 GetFlexBasis()62 const Dimension& GetFlexBasis() const 63 { 64 return flexBasis_; 65 } 66 SetFlexGrow(double flexGrow)67 void SetFlexGrow(double flexGrow) 68 { 69 flexGrow_ = flexGrow; 70 } 71 SetFlexShrink(double flexShrink)72 void SetFlexShrink(double flexShrink) 73 { 74 flexShrink_ = flexShrink; 75 } 76 SetFlexBasis(const Dimension & flexBasis)77 void SetFlexBasis(const Dimension& flexBasis) 78 { 79 flexBasis_ = flexBasis; 80 } 81 GetStretchFlag()82 bool GetStretchFlag() const 83 { 84 return canStretch_; 85 } 86 SetStretchFlag(bool canStretch)87 void SetStretchFlag(bool canStretch) 88 { 89 canStretch_ = canStretch; 90 } 91 MustStretch()92 bool MustStretch() const 93 { 94 return mustStretch_; 95 } 96 SetMustStretch(bool mustStretch)97 void SetMustStretch(bool mustStretch) 98 { 99 mustStretch_ = mustStretch; 100 } 101 GetAlignSelf()102 FlexAlign GetAlignSelf() const 103 { 104 return alignSelf_; 105 } 106 SetAlignSelf(FlexAlign alignSelf)107 void SetAlignSelf(FlexAlign alignSelf) 108 { 109 alignSelf_ = alignSelf; 110 } 111 GetConstraints()112 const LayoutParam& GetConstraints() const 113 { 114 return constraints_; 115 } 116 SetConstraints(const LayoutParam & constraints)117 void SetConstraints(const LayoutParam& constraints) 118 { 119 constraints_ = constraints; 120 } 121 GetMinWidth()122 const Dimension& GetMinWidth() const 123 { 124 return minWidth_; 125 } 126 SetMinWidth(const Dimension & minWidth)127 void SetMinWidth(const Dimension& minWidth) 128 { 129 minWidth_ = minWidth; 130 } 131 GetMinHeight()132 const Dimension& GetMinHeight() const 133 { 134 return minHeight_; 135 } 136 SetMinHeight(const Dimension & minHeight)137 void SetMinHeight(const Dimension& minHeight) 138 { 139 minHeight_ = minHeight; 140 } 141 GetMaxWidth()142 const Dimension& GetMaxWidth() const 143 { 144 return maxWidth_; 145 } 146 SetMaxWidth(const Dimension & maxWidth)147 void SetMaxWidth(const Dimension& maxWidth) 148 { 149 maxWidth_ = maxWidth; 150 } 151 GetMaxHeight()152 const Dimension& GetMaxHeight() const 153 { 154 return maxHeight_; 155 } 156 SetMaxHeight(const Dimension & maxHeight)157 void SetMaxHeight(const Dimension& maxHeight) 158 { 159 maxHeight_ = maxHeight; 160 } 161 IsHidden()162 bool IsHidden() const 163 { 164 return isHidden_; 165 } 166 SetIsHidden(bool isHidden)167 void SetIsHidden(bool isHidden) 168 { 169 isHidden_ = isHidden; 170 } 171 GetDisplayType()172 DisplayType GetDisplayType() const 173 { 174 return displayType_; 175 } 176 SetDisplayType(DisplayType displayType)177 void SetDisplayType(DisplayType displayType) 178 { 179 displayType_ = displayType; 180 } SetGridColumnInfoBuilder(const RefPtr<GridColumnInfo::Builder> & gridColumnInfoBuilder)181 void SetGridColumnInfoBuilder(const RefPtr<GridColumnInfo::Builder>& gridColumnInfoBuilder) 182 { 183 gridColumnInfoBuilder_ = gridColumnInfoBuilder; 184 } 185 GetGridColumnInfo()186 RefPtr<GridColumnInfo> GetGridColumnInfo() 187 { 188 if (gridColumnInfoBuilder_) { 189 return gridColumnInfoBuilder_->Build(); 190 } else { 191 return nullptr; 192 } 193 } SetChainStyle(const ChainInfo & chainInfo)194 void SetChainStyle(const ChainInfo& chainInfo) {} 195 SetAlignRules(const std::map<AlignDirection,AlignRule> & alignRules)196 void SetAlignRules(const std::map<AlignDirection, AlignRule>& alignRules) 197 { 198 alignRules_ = alignRules; 199 } 200 GetAlignRules()201 const std::map<AlignDirection, AlignRule>& GetAlignRules() const 202 { 203 return alignRules_; 204 } 205 206 private: 207 double flexGrow_ = 0.0; 208 double flexShrink_ = 0.0; 209 Dimension flexBasis_ = 0.0_px; 210 bool canStretch_ = true; // Set this flag to tell Flex whether this child can be stretched. 211 bool mustStretch_ = false; // Set this flag to tell Flex this child must be as large as Flex. 212 213 LayoutParam constraints_; 214 Dimension minWidth_ = Dimension(); 215 Dimension minHeight_ = Dimension(); 216 Dimension maxWidth_ = Dimension(Size::INFINITE_SIZE); 217 Dimension maxHeight_ = Dimension(Size::INFINITE_SIZE); 218 bool isHidden_ = false; 219 220 FlexAlign alignSelf_ = FlexAlign::AUTO; 221 RefPtr<GridColumnInfo::Builder> gridColumnInfoBuilder_; 222 DisplayType displayType_ = DisplayType::NO_SETTING; 223 std::map<AlignDirection, AlignRule> alignRules_; 224 }; 225 226 } // namespace OHOS::Ace 227 228 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FLEX_FLEX_ITEM_COMPONENT_H 229