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_STACK_STACK_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_STACK_COMPONENT_H
18 
19 #include "core/pipeline/base/component_group.h"
20 #ifdef WEARABLE_PRODUCT
21 #include "core/components/flex/flex_component.h"
22 #endif
23 #include "core/components/common/layout/constants.h"
24 #include "core/components/common/properties/alignment.h"
25 #include "core/components/stack/render_stack.h"
26 #include "core/components/stack/stack_element.h"
27 
28 namespace OHOS::Ace {
29 
30 class ACE_EXPORT StackComponent : public ComponentGroup {
31     DECLARE_ACE_TYPE(StackComponent, ComponentGroup);
32 
33 public:
StackComponent(const Alignment & align,StackFit fit,Overflow overflow,const std::list<RefPtr<Component>> & children)34     StackComponent(
35         const Alignment& align, StackFit fit, Overflow overflow, const std::list<RefPtr<Component>>& children)
36         : ComponentGroup(children), align_(align), fit_(fit), overflow_(overflow)
37     {}
38     ~StackComponent() override = default;
39 
CreateElement()40     RefPtr<Element> CreateElement() override
41     {
42         return AceType::MakeRefPtr<StackElement>();
43     }
44 
CreateRenderNode()45     RefPtr<RenderNode> CreateRenderNode() override
46     {
47         return RenderStack::Create();
48     }
49 
GetAlignment()50     const Alignment& GetAlignment() const
51     {
52         return align_;
53     }
54 
SetAlignment(const Alignment & align)55     void SetAlignment(const Alignment& align)
56     {
57         align_ = align;
58     }
59 
GetStackFit()60     StackFit GetStackFit() const
61     {
62         return fit_;
63     }
64 
SetStackFit(StackFit fit)65     void SetStackFit(StackFit fit)
66     {
67         fit_ = fit;
68     }
69 
GetOverflow()70     Overflow GetOverflow() const
71     {
72         return overflow_;
73     }
74 
SetOverflow(Overflow overflow)75     void SetOverflow(Overflow overflow)
76     {
77         overflow_ = overflow;
78     }
79 
GetMainStackSize()80     MainStackSize GetMainStackSize() const
81     {
82         return mainStackSize_;
83     }
84 
SetMainStackSize(MainStackSize mainStackSize)85     void SetMainStackSize(MainStackSize mainStackSize)
86     {
87         mainStackSize_ = mainStackSize;
88     }
89 
HasNavigationBar()90     bool HasNavigationBar() const
91     {
92         return navigationBar_ != nullptr;
93     }
94 
95     void SetNavigationBar(const RefPtr<Component>& navigationBar);
96 
97 private:
98     Alignment align_;
99     StackFit fit_ { StackFit::KEEP };
100     Overflow overflow_ { Overflow::CLIP };
101     MainStackSize mainStackSize_ { MainStackSize::NORMAL };
102     RefPtr<Component> navigationBar_;
103 };
104 
105 } // namespace OHOS::Ace
106 
107 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_STACK_COMPONENT_H
108