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_LIST_LIST_LANES_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LANES_LAYOUT_ALGORITHM_H 18 19 #include "core/components_ng/pattern/list/list_layout_algorithm.h" 20 21 namespace OHOS::Ace::NG { 22 23 // TextLayoutAlgorithm acts as the underlying text layout. 24 class ACE_EXPORT ListLanesLayoutAlgorithm : public ListLayoutAlgorithm { 25 DECLARE_ACE_TYPE(ListLanesLayoutAlgorithm, ListLayoutAlgorithm); 26 public: SwapLanesItemRange(std::map<int32_t,int32_t> & itemRange)27 void SwapLanesItemRange(std::map<int32_t, int32_t>& itemRange) 28 { 29 lanesItemRange_.swap(itemRange); 30 } SetLanes(int32_t lanes)31 void SetLanes(int32_t lanes) 32 { 33 lanes_ = lanes; 34 } GetLanes()35 int32_t GetLanes() const override 36 { 37 return lanes_; 38 } 39 40 float MeasureAndGetChildHeight(LayoutWrapper* layoutWrapper, int32_t childIndex) override; 41 42 static int32_t CalculateLanesParam(std::optional<float>& minLaneLength, std::optional<float>& maxLaneLength, 43 int32_t lanes, std::optional<float> crossSizeOptional, float laneGutter = 0.0f); 44 45 protected: 46 void UpdateListItemConstraint(Axis axis, const OptionalSizeF& selfIdealSize, 47 LayoutConstraintF& contentConstraint) override; 48 int32_t LayoutALineForward( 49 LayoutWrapper* layoutWrapper, int32_t& currentIndex, float startPos, float& endPos) override; 50 int32_t LayoutALineBackward( 51 LayoutWrapper* layoutWrapper, int32_t& currentIndex, float endPos, float& startPos) override; 52 float CalculateLaneCrossOffset(float crossSize, float childCrossSize) override; 53 void CalculateLanes(const RefPtr<ListLayoutProperty>& layoutProperty, 54 const LayoutConstraintF& layoutConstraint, std::optional<float> crossSizeOptional, Axis axis) override; 55 int32_t GetLanesFloor(LayoutWrapper* layoutWrapper, int32_t index) override; 56 57 private: 58 static void ModifyLaneLength( 59 std::optional<float>& minLaneLength, std::optional<float>& maxLaneLength, float crossSize); 60 int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t index); 61 std::list<int32_t> LayoutCachedItem(LayoutWrapper* layoutWrapper, int32_t cacheCount) override; 62 std::list<int32_t> LayoutCachedALineForward( 63 LayoutWrapper* layoutWrapper, int32_t& index, float& startPos, float crossSize); 64 std::list<int32_t> LayoutCachedALineBackward( 65 LayoutWrapper* layoutWrapper, int32_t& index, float& endPos, float crossSize); 66 static int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t startIndex, int32_t index); 67 static int32_t GetLazyForEachIndex(const RefPtr<FrameNode>& host); 68 69 int32_t lanes_ = 1; 70 std::optional<float> minLaneLength_; 71 std::optional<float> maxLaneLength_; 72 std::map<int32_t, int32_t> lanesItemRange_; 73 74 LayoutConstraintF groupLayoutConstraint_; 75 }; 76 } // namespace OHOS::Ace::NG 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H