• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_PATTERNS_LIST_LIST_ITEM_GROUP_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_ITEM_GROUP_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "base/utils/noncopyable.h"
21 #include "base/utils/utils.h"
22 #include "core/components_ng/pattern/list/list_item_group_accessibility_property.h"
23 #include "core/components_ng/pattern/list/list_item_group_layout_algorithm.h"
24 #include "core/components_ng/pattern/list/list_item_group_layout_property.h"
25 #include "core/components_ng/pattern/list/list_layout_property.h"
26 #include "core/components_ng/pattern/pattern.h"
27 #include "core/components_ng/syntax/shallow_builder.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 struct ListItemGroupPaintInfo {
32     bool vertical = false;
33     int32_t lanes = 1;
34     float spaceWidth = 0.0f;
35     float laneGutter = 0.0f;
36 };
37 
38 class ACE_EXPORT ListItemGroupPattern : public Pattern {
39     DECLARE_ACE_TYPE(ListItemGroupPattern, Pattern);
40 
41 public:
ListItemGroupPattern(const RefPtr<ShallowBuilder> & shallowBuilder,V2::ListItemGroupStyle listItemGroupStyle)42     explicit ListItemGroupPattern(
43         const RefPtr<ShallowBuilder>& shallowBuilder, V2::ListItemGroupStyle listItemGroupStyle)
44         : shallowBuilder_(shallowBuilder), listItemGroupStyle_(listItemGroupStyle)
45     {}
46     ~ListItemGroupPattern() override = default;
47 
IsAtomicNode()48     bool IsAtomicNode() const override
49     {
50         return false;
51     }
52 
CreateLayoutProperty()53     RefPtr<LayoutProperty> CreateLayoutProperty() override
54     {
55         return MakeRefPtr<ListItemGroupLayoutProperty>();
56     }
57 
CreateAccessibilityProperty()58     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
59     {
60         return MakeRefPtr<ListItemGroupAccessibilityProperty>();
61     }
62 
63     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override;
64 
65     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
66 
AddHeader(const RefPtr<NG::UINode> & header)67     void AddHeader(const RefPtr<NG::UINode>& header)
68     {
69         auto host = GetHost();
70         CHECK_NULL_VOID(host);
71         if (headerIndex_ < 0) {
72             headerIndex_ = itemStartIndex_;
73             host->AddChild(header);
74             itemStartIndex_++;
75         } else {
76             host->ReplaceChild(host->GetChildAtIndex(headerIndex_), header);
77         }
78         auto frameNode = AceType::DynamicCast<FrameNode>(header->GetFrameChildByIndex(0, false));
79         CHECK_NULL_VOID(frameNode);
80         auto renderContext = frameNode->GetRenderContext();
81         CHECK_NULL_VOID(renderContext);
82         renderContext->UpdateZIndex(1);
83     }
84 
AddFooter(const RefPtr<NG::UINode> & footer)85     void AddFooter(const RefPtr<NG::UINode>& footer)
86     {
87         auto host = GetHost();
88         CHECK_NULL_VOID(host);
89         if (footerIndex_ < 0) {
90             footerIndex_ = itemStartIndex_;
91             host->AddChild(footer);
92             itemStartIndex_++;
93         } else {
94             host->ReplaceChild(host->GetChildAtIndex(footerIndex_), footer);
95         }
96         auto frameNode = AceType::DynamicCast<FrameNode>(footer->GetFrameChildByIndex(0, false));
97         CHECK_NULL_VOID(frameNode);
98         auto renderContext = frameNode->GetRenderContext();
99         CHECK_NULL_VOID(renderContext);
100         renderContext->UpdateZIndex(1);
101     }
102 
GetItemPosition()103     const ListItemGroupLayoutAlgorithm::PositionMap& GetItemPosition()
104     {
105         return itemPosition_;
106     }
107 
SetIndexInList(int32_t index)108     void SetIndexInList(int32_t index)
109     {
110         indexInList_ = index;
111     }
112 
GetIndexInList()113     int32_t GetIndexInList() const
114     {
115         return indexInList_;
116     }
117 
GetDisplayEndIndexInGroup()118     int32_t GetDisplayEndIndexInGroup() const
119     {
120         return itemDisplayEndIndex_;
121     }
122 
GetDiasplayStartIndexInGroup()123     int32_t GetDiasplayStartIndexInGroup() const
124     {
125         return itemDiasplayStartIndex_;
126     }
127 
GetEndIndexInGroup()128     int32_t GetEndIndexInGroup() const
129     {
130         return (itemTotalCount_ - 1);
131     }
132 
GetLanesInGroup()133     int32_t GetLanesInGroup() const
134     {
135         return lanes_;
136     }
137 
GetListItemGroupStyle()138     V2::ListItemGroupStyle GetListItemGroupStyle()
139     {
140         return listItemGroupStyle_;
141     }
142 
143 private:
144     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
145     void OnAttachToFrameNode() override;
146     void SetListItemGroupDefaultAttributes(const RefPtr<FrameNode>& itemGroupNode);
147     RefPtr<ShallowBuilder> shallowBuilder_;
148     V2::ListItemGroupStyle listItemGroupStyle_ = V2::ListItemGroupStyle::NONE;
149 
150     int32_t indexInList_ = 0;
151 
152     int32_t headerIndex_ = -1;
153     int32_t footerIndex_ = -1;
154     int32_t itemStartIndex_ = 0;
155     int32_t itemTotalCount_ = -1;
156     int32_t itemDisplayEndIndex_ = -1;
157     int32_t itemDiasplayStartIndex_ = -1;
158 
159     ListItemGroupLayoutAlgorithm::PositionMap itemPosition_;
160     float spaceWidth_ = 0.0f;
161     Axis axis_ = Axis::VERTICAL;
162     int32_t lanes_ = 1;
163     float laneGutter_ = 0.0f;
164     ACE_DISALLOW_COPY_AND_MOVE(ListItemGroupPattern);
165 };
166 } // namespace OHOS::Ace::NG
167 
168 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_ITEM_PATTERN_H
169