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_FLEX_FLEX_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FLEX_FLEX_COMPONENT_H 18 19 #include "base/utils/macros.h" 20 #include "core/components/common/layout/align_declaration.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/flex/flex_element.h" 23 #include "core/components/flex/render_flex.h" 24 #include "core/pipeline/base/component_group.h" 25 26 namespace OHOS::Ace { 27 28 class ACE_EXPORT FlexComponent : public ComponentGroup { 29 DECLARE_ACE_TYPE(FlexComponent, ComponentGroup); 30 31 public: FlexComponent(FlexDirection direction,FlexAlign mainAxisAlign,FlexAlign crossAxisAlign,const std::list<RefPtr<Component>> & children)32 FlexComponent(FlexDirection direction, FlexAlign mainAxisAlign, FlexAlign crossAxisAlign, 33 const std::list<RefPtr<Component>>& children) 34 : ComponentGroup(children), direction_(direction), mainAxisAlign_(mainAxisAlign), 35 crossAxisAlign_(crossAxisAlign) 36 {} 37 ~FlexComponent() override = default; 38 CreateRenderNode()39 RefPtr<RenderNode> CreateRenderNode() override 40 { 41 return RenderFlex::Create(); 42 } 43 CreateElement()44 RefPtr<Element> CreateElement() override 45 { 46 return AceType::MakeRefPtr<FlexElement>(); 47 } 48 GetDirection()49 FlexDirection GetDirection() const 50 { 51 return direction_; 52 } 53 SetDirection(FlexDirection direction)54 void SetDirection(FlexDirection direction) 55 { 56 direction_ = direction; 57 } 58 GetCrossAxisAlign()59 FlexAlign GetCrossAxisAlign() const 60 { 61 return crossAxisAlign_; 62 } 63 SetCrossAxisAlign(FlexAlign align)64 void SetCrossAxisAlign(FlexAlign align) 65 { 66 crossAxisAlign_ = align; 67 } 68 GetMainAxisAlign()69 FlexAlign GetMainAxisAlign() const 70 { 71 return mainAxisAlign_; 72 } 73 SetMainAxisAlign(FlexAlign align)74 void SetMainAxisAlign(FlexAlign align) 75 { 76 mainAxisAlign_ = align; 77 } 78 GetMainAxisSize()79 MainAxisSize GetMainAxisSize() const 80 { 81 return mainAxisSize_; 82 } 83 SetMainAxisSize(MainAxisSize mainAxisSize)84 void SetMainAxisSize(MainAxisSize mainAxisSize) 85 { 86 mainAxisSize_ = mainAxisSize; 87 } 88 GetCrossAxisSize()89 CrossAxisSize GetCrossAxisSize() const 90 { 91 return crossAxisSize_; 92 } 93 SetCrossAxisSize(CrossAxisSize crossAxisSize)94 void SetCrossAxisSize(CrossAxisSize crossAxisSize) 95 { 96 crossAxisSize_ = crossAxisSize; 97 } 98 GetBaseline()99 TextBaseline GetBaseline() const 100 { 101 return baseline_; 102 } 103 SetBaseline(TextBaseline baseline)104 void SetBaseline(TextBaseline baseline) 105 { 106 baseline_ = baseline; 107 } 108 IsStretchToParent()109 bool IsStretchToParent() const 110 { 111 return stretchToParent_; 112 } 113 SetStretchToParent(bool flag)114 void SetStretchToParent(bool flag) 115 { 116 stretchToParent_ = flag; 117 } 118 GetUseViewPortFlag()119 bool GetUseViewPortFlag() const 120 { 121 return useViewPort_; 122 } 123 SetUseViewPortFlag(bool flag)124 void SetUseViewPortFlag(bool flag) 125 { 126 useViewPort_ = flag; 127 } 128 ContainsNavigation()129 bool ContainsNavigation() const 130 { 131 return containsNavigation_; 132 } 133 SetContainsNavigation(bool containsNavigation)134 void SetContainsNavigation(bool containsNavigation) 135 { 136 containsNavigation_ = containsNavigation; 137 } 138 GetOverflow()139 Overflow GetOverflow() const 140 { 141 return overflow_; 142 } 143 SetOverflow(Overflow overflow)144 void SetOverflow(Overflow overflow) 145 { 146 overflow_ = overflow; 147 } 148 SetSpace(const Dimension & space)149 void SetSpace(const Dimension& space) 150 { 151 space_ = space; 152 } 153 GetSpace()154 const Dimension& GetSpace() const 155 { 156 return space_; 157 } 158 SetAlignDeclarationPtr(AlignDeclaration * alignPtr)159 void SetAlignDeclarationPtr(AlignDeclaration* alignPtr) 160 { 161 alignPtr_ = alignPtr; 162 } 163 GetAlignDeclarationPtr()164 AlignDeclarationPtr GetAlignDeclarationPtr() const 165 { 166 return alignPtr_; 167 } 168 169 private: 170 FlexDirection direction_ = FlexDirection::ROW; 171 FlexAlign mainAxisAlign_ = FlexAlign::FLEX_START; 172 FlexAlign crossAxisAlign_ = FlexAlign::FLEX_START; 173 MainAxisSize mainAxisSize_ = MainAxisSize::MAX; 174 CrossAxisSize crossAxisSize_ = CrossAxisSize::MIN; 175 TextBaseline baseline_ = TextBaseline::ALPHABETIC; 176 Overflow overflow_ = Overflow::CLIP; 177 Dimension space_; 178 179 AlignDeclarationPtr alignPtr_ = nullptr; 180 181 bool stretchToParent_ = false; 182 bool useViewPort_ = false; 183 bool containsNavigation_ = false; 184 }; 185 186 class RowComponent : public FlexComponent { 187 DECLARE_ACE_TYPE(RowComponent, FlexComponent); 188 189 public: RowComponent(FlexAlign mainAxisAlign,FlexAlign crossAxisAlign,const std::list<RefPtr<Component>> & children)190 RowComponent(FlexAlign mainAxisAlign, FlexAlign crossAxisAlign, const std::list<RefPtr<Component>>& children) 191 : FlexComponent(FlexDirection::ROW, mainAxisAlign, crossAxisAlign, children) 192 {} 193 ~RowComponent() override = default; 194 CreateElement()195 RefPtr<Element> CreateElement() override 196 { 197 return AceType::MakeRefPtr<RowElement>(); 198 } 199 }; 200 201 class ColumnComponent : public FlexComponent { 202 DECLARE_ACE_TYPE(ColumnComponent, FlexComponent); 203 204 public: ColumnComponent(FlexAlign mainAxisAlign,FlexAlign crossAxisAlign,const std::list<RefPtr<Component>> & children)205 ColumnComponent(FlexAlign mainAxisAlign, FlexAlign crossAxisAlign, const std::list<RefPtr<Component>>& children) 206 : FlexComponent(FlexDirection::COLUMN, mainAxisAlign, crossAxisAlign, children) 207 {} 208 ~ColumnComponent() override = default; 209 CreateElement()210 RefPtr<Element> CreateElement() override 211 { 212 return AceType::MakeRefPtr<ColumnElement>(); 213 } 214 }; 215 216 } // namespace OHOS::Ace 217 218 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FLEX_FLEX_COMPONENT_H 219