• 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,
41         bool groupLayoutAll = true) override;
42 
43     float GetChildHeight(LayoutWrapper* layoutWrapper, int32_t childIndex) override;
44 
45     static int32_t CalculateLanesParam(std::optional<float>& minLaneLength, std::optional<float>& maxLaneLength,
46         int32_t lanes, std::optional<float> crossSizeOptional, float laneGutter = 0.0f);
47 
GetGroupLayoutConstraint()48     const LayoutConstraintF& GetGroupLayoutConstraint() const override
49     {
50         return groupLayoutConstraint_;
51     }
52 
53 protected:
54     void UpdateListItemConstraint(Axis axis, const OptionalSizeF& selfIdealSize,
55         LayoutConstraintF& contentConstraint) override;
56     int32_t LayoutALineForward(
57         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float startPos, float& endPos) override;
58     int32_t LayoutALineBackward(
59         LayoutWrapper* layoutWrapper, int32_t& currentIndex, float endPos, float& startPos) override;
60     float CalculateLaneCrossOffset(float crossSize, float childCrossSize, bool isGroup) override;
61     void CalculateLanes(const RefPtr<ListLayoutProperty>& layoutProperty,
62         const LayoutConstraintF& layoutConstraint, std::optional<float> crossSizeOptional, Axis axis) override;
63     int32_t GetLanesFloor(LayoutWrapper* layoutWrapper, int32_t index) override;
64     int32_t GetLanesCeil(LayoutWrapper* layoutWrapper, int32_t index) override;
65     void SetCacheCount(LayoutWrapper* layoutWrapper, int32_t cacheCount) override;
66 
67 private:
68     static void ModifyLaneLength(
69         std::optional<float>& minLaneLength, std::optional<float>& maxLaneLength, float crossSize);
70     int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t index);
71     bool CheckCurRowMeasureFinished(LayoutWrapper* layoutWrapper, int32_t curIndex, bool isGroup);
72     void LayoutCachedALine(LayoutWrapper* layoutWrapper, std::pair<const int, ListItemInfo>& pos,
73         int32_t startIndex, float crossSize);
74     std::pair<bool, bool> CheckACachedItem(const RefPtr<LayoutWrapper>& wrapper, int32_t cnt, bool& isGroup) const;
75     int32_t LayoutCachedForward(LayoutWrapper* layoutWrapper, int32_t cacheCount,
76         int32_t& cachedCount, int32_t curIndex, std::list<PredictLayoutItem>& predictList, bool show) override;
77     int32_t LayoutCachedBackward(LayoutWrapper* layoutWrapper, int32_t cacheCount,
78         int32_t& cachedCount, int32_t curIndex, std::list<PredictLayoutItem>& predictList, bool show) override;
79     int32_t FindLanesStartIndex(LayoutWrapper* layoutWrapper, int32_t startIndex, int32_t index);
80     static int32_t GetLazyForEachIndex(const RefPtr<FrameNode>& host);
81     void MeasureGroup(LayoutWrapper* listWrapper, const RefPtr<LayoutWrapper>& groupWrapper,
82         int32_t index, float& pos, bool forward);
83     void MeasureItem(const RefPtr<LayoutWrapper>& itemWrapper, int32_t index, bool forward);
SetLaneIdx4Divider(int32_t idx)84     void SetLaneIdx4Divider(int32_t idx)
85     {
86         laneIdx4Divider_ = idx;
87     }
88 
89     int32_t lanes_ = 1;
90     std::optional<float> minLaneLength_;
91     std::optional<float> maxLaneLength_;
92     std::map<int32_t, int32_t> lanesItemRange_;
93 
94     LayoutConstraintF groupLayoutConstraint_;
95 };
96 } // namespace OHOS::Ace::NG
97 
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H