• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetGroupLayoutConstraint()45     LayoutConstraintF& GetGroupLayoutConstraint() override
46     {
47         return groupLayoutConstraint_;
48     }
49 
50 protected:
51     void UpdateListItemConstraint(Axis axis, const OptionalSizeF& selfIdealSize,
52         LayoutConstraintF& contentConstraint) override;
53     int32_t LayoutALineForward(
54         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float startPos, float& endPos) override;
55     int32_t LayoutALineBackward(
56         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float endPos, float& startPos) override;
57     float CalculateLaneCrossOffset(float crossSize, float childCrossSize) override;
58     void CalculateLanes(const RefPtr<ListLayoutProperty>& layoutProperty,
59         const LayoutConstraintF& layoutConstraint, std::optional<float> crossSizeOptional, Axis axis) override;
60     int32_t GetLanesFloor(LayoutWrapper* layoutWrapper, int32_t index) override;
61     int32_t GetLanesCeil(LayoutWrapper* layoutWrapper, int32_t index) override;
62     void SetCacheCount(LayoutWrapper* layoutWrapper, int32_t cacheCount) override;
63 
64 private:
65     static void ModifyLaneLength(
66         std::optional<float>& minLaneLength, std::optional<float>& maxLaneLength, float crossSize);
67     int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t index);
68     std::list<int32_t> LayoutCachedItem(LayoutWrapper* layoutWrapper, int32_t cacheCount) override;
69     std::list<int32_t> LayoutCachedALineForward(
70         LayoutWrapper* layoutWrapper, int32_t& index, float& startPos, float crossSize);
71     std::list<int32_t> LayoutCachedALineBackward(
72         LayoutWrapper* layoutWrapper, int32_t& index, float& endPos, float crossSize);
73     static int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t startIndex, int32_t index);
74     static int32_t GetLazyForEachIndex(const RefPtr<FrameNode>& host);
75 
76     int32_t lanes_ = 1;
77     std::optional<float> minLaneLength_;
78     std::optional<float> maxLaneLength_;
79     std::map<int32_t, int32_t> lanesItemRange_;
80 
81     LayoutConstraintF groupLayoutConstraint_;
82 };
83 } // namespace OHOS::Ace::NG
84 
85 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H