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