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_WRAP_WRAP_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WRAP_WRAP_COMPONENT_H 18 19 #include "core/components/common/layout/constants.h" 20 #include "core/components/wrap/render_wrap.h" 21 #include "core/components/wrap/wrap_element.h" 22 #include "core/pipeline/base/component_group.h" 23 24 namespace OHOS::Ace { 25 26 class WrapComponent : public ComponentGroup { 27 DECLARE_ACE_TYPE(WrapComponent, ComponentGroup); 28 29 public: WrapComponent(double spacing,double contentSpacing,const std::list<RefPtr<Component>> & children)30 WrapComponent(double spacing, double contentSpacing, const std::list<RefPtr<Component>>& children) 31 : ComponentGroup(children), spacing_(Dimension(spacing, DimensionUnit::PX)), 32 contentSpacing_(Dimension(contentSpacing, DimensionUnit::PX)) 33 {} WrapComponent(const std::list<RefPtr<Component>> & children)34 explicit WrapComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children) {} 35 ~WrapComponent() override = default; 36 CreateRenderNode()37 RefPtr<RenderNode> CreateRenderNode() override 38 { 39 return RenderWrap::Create(); 40 } 41 CreateElement()42 RefPtr<Element> CreateElement() override 43 { 44 return AceType::MakeRefPtr<WrapElement>(); 45 } 46 GetSpacing()47 const Dimension& GetSpacing() const 48 { 49 return spacing_; 50 } 51 SetSpacing(const Dimension & spacing)52 void SetSpacing(const Dimension& spacing) 53 { 54 spacing_ = spacing; 55 } 56 GetContentSpacing()57 const Dimension& GetContentSpacing() const 58 { 59 return contentSpacing_; 60 } 61 SetContentSpacing(const Dimension & contentSpacing)62 void SetContentSpacing(const Dimension& contentSpacing) 63 { 64 contentSpacing_ = contentSpacing; 65 } 66 67 // get/set enum type below GetDirection()68 WrapDirection GetDirection() const 69 { 70 return direction_; 71 } 72 SetDirection(WrapDirection direction)73 void SetDirection(WrapDirection direction) 74 { 75 direction_ = direction; 76 } 77 GetAlignment()78 WrapAlignment GetAlignment() const 79 { 80 return alignment_; 81 } 82 SetAlignment(WrapAlignment alignment)83 void SetAlignment(WrapAlignment alignment) 84 { 85 alignment_ = alignment; 86 } 87 GetCrossAlignment()88 WrapAlignment GetCrossAlignment() const 89 { 90 return crossAlignment_; 91 } 92 SetCrossAlignment(WrapAlignment crossAlignment)93 void SetCrossAlignment(WrapAlignment crossAlignment) 94 { 95 crossAlignment_ = crossAlignment; 96 } 97 GetMainAlignment()98 WrapAlignment GetMainAlignment() const 99 { 100 return mainAlignment_; 101 } 102 SetMainAlignment(WrapAlignment mainAlignment)103 void SetMainAlignment(WrapAlignment mainAlignment) 104 { 105 mainAlignment_ = mainAlignment; 106 } 107 GetDialogStretch()108 bool GetDialogStretch() const 109 { 110 return dialogStretch_; 111 } 112 SetDialogStretch(bool dialogStretch)113 void SetDialogStretch(bool dialogStretch) 114 { 115 dialogStretch_ = dialogStretch; 116 } 117 GetHorizontalMeasure()118 MeasureType GetHorizontalMeasure() const 119 { 120 return horizontalMeasure_; 121 } 122 SetHorizontalMeasure(MeasureType horizontalMeasure)123 void SetHorizontalMeasure(MeasureType horizontalMeasure) 124 { 125 horizontalMeasure_ = horizontalMeasure; 126 } 127 GetVerticalMeasure()128 MeasureType GetVerticalMeasure() const 129 { 130 return verticalMeasure_; 131 } 132 SetVerticalMeasure(MeasureType verticalMeasure)133 void SetVerticalMeasure(MeasureType verticalMeasure) 134 { 135 verticalMeasure_ = verticalMeasure; 136 } 137 138 private: 139 // The direction of main axis 140 WrapDirection direction_ = WrapDirection::HORIZONTAL; 141 // The overall alignment of all children in the wrap component 142 WrapAlignment alignment_ = WrapAlignment::START; 143 // The alignment of all components in current direction 144 WrapAlignment mainAlignment_ = WrapAlignment::SPACE_AROUND; 145 // The alignment in cross direction of all component in one direction group. 146 WrapAlignment crossAlignment_ = WrapAlignment::CENTER; 147 // The space between item in one direction content 148 Dimension spacing_; 149 // The space between each direction content 150 Dimension contentSpacing_; 151 152 MeasureType horizontalMeasure_ = MeasureType::CONTENT; 153 MeasureType verticalMeasure_ = MeasureType::CONTENT; 154 155 bool dialogStretch_ = false; 156 }; 157 158 } // namespace OHOS::Ace 159 160 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WRAP_WRAP_COMPONENT_H 161