1 /*
2  * Copyright (c) 2022-2023 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_NG_PATTERN_PANEL_SLIDING_PANEL_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PANEL_SLIDING_PANEL_LAYOUT_ALGORITHM_H
18 
19 #include <cstdint>
20 #include <optional>
21 
22 #include "base/geometry/axis.h"
23 #include "base/geometry/dimension.h"
24 #include "base/geometry/ng/size_t.h"
25 #include "base/memory/referenced.h"
26 #include "core/components_ng/layout/layout_algorithm.h"
27 #include "core/components_ng/layout/layout_wrapper.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 class ACE_EXPORT SlidingPanelLayoutAlgorithm : public LayoutAlgorithm {
32     DECLARE_ACE_TYPE(SlidingPanelLayoutAlgorithm, LayoutAlgorithm);
33 
34 public:
35     SlidingPanelLayoutAlgorithm() = default;
36     ~SlidingPanelLayoutAlgorithm() override = default;
37 
OnReset()38     void OnReset() override {}
39     void Measure(LayoutWrapper* layoutWrapper) override;
40     void Layout(LayoutWrapper* layoutWrapper) override;
41 
SetCurrentOffset(float offset)42     void SetCurrentOffset(float offset)
43     {
44         currentOffset_ = offset;
45     }
46 
GetCurrentOffset()47     float GetCurrentOffset() const
48     {
49         return currentOffset_;
50     }
51 
SetIsFirstLayout(bool isFirstLayout)52     void SetIsFirstLayout(bool isFirstLayout)
53     {
54         isFirstLayout_ = isFirstLayout;
55     }
56 
GetIsFirstLayout()57     bool GetIsFirstLayout() const
58     {
59         return isFirstLayout_;
60     }
61 
GetFullHeight()62     Dimension GetFullHeight()
63     {
64         return fullHeight_;
65     }
66 
GetHalfHeight()67     Dimension GetHalfHeight()
68     {
69         return halfHeight_;
70     }
71 
GetMiniHeight()72     Dimension GetMiniHeight()
73     {
74         return miniHeight_;
75     }
76 
GetCustomHeight()77     CalcDimension GetCustomHeight()
78     {
79         return customHeight_;
80     }
81 
SetInvisibleFlag(bool invisibleFlag)82     void SetInvisibleFlag(bool invisibleFlag)
83     {
84         invisibleFlag_ = invisibleFlag;
85     }
86 
GetMaxWidth()87     float GetMaxWidth() const
88     {
89         return maxWidth_;
90     }
91 
92 private:
93     RefPtr<LayoutWrapper> GetNodeLayoutWrapperByTag(LayoutWrapper* layoutWrapper, const std::string& tagName) const;
94     void MeasureCloseIcon(
95         const RefPtr<LayoutWrapper>& closeIconWrapper, const RefPtr<LayoutProperty>& layoutProperty) const;
96     float GetMaxWidthByScreenSizeType(const SizeF& maxSize, const SizeF& idealSize) const;
97 
98     float currentOffset_ = 0.0f;
99     bool isFirstLayout_ = true;
100     Dimension fullHeight_;
101     Dimension halfHeight_;
102     Dimension miniHeight_;
103     CalcDimension customHeight_;
104     bool invisibleFlag_ = false;
105     float maxWidth_ = 0.0f;
106     SizeF idealSize_;
107 
108     ACE_DISALLOW_COPY_AND_MOVE(SlidingPanelLayoutAlgorithm);
109 };
110 
111 } // namespace OHOS::Ace::NG
112 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_PANEL_SLIDING_PANEL_LAYOUT_ALGORITHM_H