1 /*
2  * Copyright (c) 2022 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_SCROLL_SCROLL_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_LAYOUT_ALGORITHM_H
18 
19 #include <map>
20 
21 #include "base/geometry/axis.h"
22 #include "base/memory/referenced.h"
23 #include "core/components/common/layout/grid_system_manager.h"
24 #include "core/components_ng/layout/layout_algorithm.h"
25 #include "core/components_ng/layout/layout_wrapper.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 constexpr int32_t SCROLL_FROM_JUMP = 3;
30 
31 class ACE_EXPORT ScrollLayoutAlgorithm : public LayoutAlgorithm {
32     DECLARE_ACE_TYPE(ScrollLayoutAlgorithm, LayoutAlgorithm);
33 
34 public:
ScrollLayoutAlgorithm(float currentOffset)35     explicit ScrollLayoutAlgorithm(float currentOffset) : currentOffset_(currentOffset) {}
36     ~ScrollLayoutAlgorithm() override = default;
37 
OnReset()38     void OnReset() override {}
39 
SetCurrentOffset(float offset)40     void SetCurrentOffset(float offset)
41     {
42         currentOffset_ = offset;
43     }
44 
GetCurrentOffset()45     float GetCurrentOffset() const
46     {
47         return currentOffset_;
48     }
49 
GetScrollableDistance()50     float GetScrollableDistance() const
51     {
52         return scrollableDistance_;
53     }
54 
GetViewPortLength()55     float GetViewPortLength() const
56     {
57         return viewPortLength_;
58     }
59 
GetViewPort()60     const SizeF& GetViewPort() const
61     {
62         return viewPort_;
63     }
64 
GetViewSize()65     const SizeF& GetViewSize() const
66     {
67         return viewSize_;
68     }
69 
GetViewPortExtent()70     const SizeF& GetViewPortExtent() const
71     {
72         return viewPortExtent_;
73     }
74 
75     void Measure(LayoutWrapper* layoutWrapper) override;
76 
77     void Layout(LayoutWrapper* layoutWrapper) override;
78     void UpdateOverlay(LayoutWrapper* layoutWrapper);
79 
80 private:
81     float currentOffset_ = 0.0f;
82     float scrollableDistance_ = 0.0f;
83     float viewPortLength_ = 0.0f;
84     SizeF viewPort_;
85     SizeF viewPortExtent_;
86     SizeF viewSize_;
87     void UpdateScrollAlignment(Alignment& scrollAlignment);
88 };
89 
90 } // namespace OHOS::Ace::NG
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SCROLL_SCROLL_LAYOUT_ALGORITHM_H
93