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_ITEM_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_ITEM_LAYOUT_ALGORITHM_H
18 
19 #include "base/geometry/axis.h"
20 #include "core/components_ng/layout/layout_algorithm.h"
21 #include "core/components_ng/layout/layout_wrapper.h"
22 #include "core/components_v2/list/list_properties.h"
23 
24 namespace OHOS::Ace::NG {
25 class ACE_EXPORT ListItemLayoutAlgorithm : public BoxLayoutAlgorithm {
26     DECLARE_ACE_TYPE(ListItemLayoutAlgorithm, BoxLayoutAlgorithm);
27 public:
ListItemLayoutAlgorithm(int32_t startNodeIndex,int32_t endNodeIndex,int32_t childNodeIndex)28     ListItemLayoutAlgorithm(int32_t startNodeIndex, int32_t endNodeIndex, int32_t childNodeIndex)
29         :startNodeIndex_(startNodeIndex), endNodeIndex_(endNodeIndex), childNodeIndex_(childNodeIndex) {}
30 
31     void Measure(LayoutWrapper* layoutWrapper) override;
32 
33     void Layout(LayoutWrapper* layoutWrapper) override;
34 
35     void PerformMeasureSelf(LayoutWrapper* layoutWrapper) const;
36 
SetAxis(Axis axis)37     void SetAxis(Axis axis)
38     {
39         axis_ = axis;
40     }
41 
SetCurOffset(float curOffset)42     void SetCurOffset(float curOffset)
43     {
44         curOffset_ = curOffset;
45     }
46 
SetStartNodeSize(float startNodeSize)47     void SetStartNodeSize(float startNodeSize)
48     {
49         startNodeSize_ = startNodeSize;
50     }
51 
GetStartNodeSize()52     float GetStartNodeSize() const
53     {
54         return startNodeSize_;
55     }
56 
SetEndNodeSize(float endNodeSize)57     void SetEndNodeSize(float endNodeSize)
58     {
59         endNodeSize_ = endNodeSize;
60     }
61 
GetEndNodeSize()62     float GetEndNodeSize() const
63     {
64         return endNodeSize_;
65     }
66 
SetIndexInList(int32_t index)67     void SetIndexInList(int32_t index)
68     {
69         indexInList_ = index;
70     }
71 
SetIndexInListItemGroup(int32_t indexInGroup)72     void SetIndexInListItemGroup(int32_t indexInGroup)
73     {
74         indexInListItemGroup_ = indexInGroup;
75     }
76 
GetIndexInList()77     int32_t GetIndexInList() const
78     {
79         return indexInList_;
80     }
81 
GetIndexInListItemGroup()82     int32_t GetIndexInListItemGroup() const
83     {
84         return indexInListItemGroup_;
85     }
86 
SetHasStartDeleteArea(bool hasStartDeleteArea)87     void SetHasStartDeleteArea(bool hasStartDeleteArea)
88     {
89         hasStartDeleteArea_ = hasStartDeleteArea;
90     }
91 
SetHasEndDeleteArea(bool hasEndDeleteArea)92     void SetHasEndDeleteArea(bool hasEndDeleteArea)
93     {
94         hasEndDeleteArea_ = hasEndDeleteArea;
95     }
96 
97     bool IsRTLAndVertical(LayoutWrapper* layoutWrapper) const;
98     float SetReverseValue(LayoutWrapper* layoutWrapper, float offset);
99 
100 private:
101     int32_t startNodeIndex_;
102     int32_t endNodeIndex_;
103     int32_t childNodeIndex_;
104 
105     int32_t indexInList_ = 0;
106     int32_t indexInListItemGroup_ = -1;
107 
108     float curOffset_ = 0.0f;
109     float startNodeSize_ = 0.0f;
110     float endNodeSize_ = 0.0f;
111     bool hasStartDeleteArea_ = false;
112     bool hasEndDeleteArea_ = false;
113 
114     Axis axis_ = Axis::VERTICAL;
115 };
116 } // namespace OHOS::Ace::NG
117 
118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_LAYOUT_ALGORITHM_H