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