• 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_ITEM_GROUP_PAINT_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_ITEM_GROUP_PAINT_METHOD_H
18 
19 #include "base/geometry/ng/size_t.h"
20 #include "base/memory/ace_type.h"
21 #include "base/memory/referenced.h"
22 #include "base/utils/macros.h"
23 #include "base/utils/utils.h"
24 #include "core/components_ng/render/divider_painter.h"
25 #include "core/components_ng/render/node_paint_method.h"
26 #include "core/components_ng/pattern/list/list_item_group_layout_algorithm.h"
27 #include "core/components_ng/pattern/list/list_item_group_pattern.h"
28 
29 namespace OHOS::Ace::NG {
30 struct DividerGroupInfo {
31     int32_t lanes = 1;
32     float crossSize = 0.0f;
33     float mainPadding = 0.0f;
34     float crossPadding = 0.0f;
35     float constrainStrokeWidth = 0.0f;
36     float halfSpaceWidth = 0.0f;
37     float startMargin = 0.0f;
38     float endMargin = 0.0f;
39 };
40 
41 class ACE_EXPORT ListItemGroupPaintMethod : public NodePaintMethod {
DECLARE_ACE_TYPE(ListItemGroupPaintMethod,NodePaintMethod)42     DECLARE_ACE_TYPE(ListItemGroupPaintMethod, NodePaintMethod)
43 public:
44     ListItemGroupPaintMethod(const V2::ItemDivider& divider, ListItemGroupPaintInfo listItemGroupPaintInfo,
45         ListItemGroupLayoutAlgorithm::PositionMap& itemPosition, const std::set<int32_t>& pressedItem)
46         : divider_(divider), itemPosition_(itemPosition)
47     {
48         vertical_ = listItemGroupPaintInfo.vertical;
49         lanes_ = listItemGroupPaintInfo.lanes;
50         spaceWidth_ = listItemGroupPaintInfo.spaceWidth;
51         laneGutter_ = listItemGroupPaintInfo.laneGutter;
52         totalItemCount_ = listItemGroupPaintInfo.totalItemCount;
53         layoutDirection_ = listItemGroupPaintInfo.layoutDirection;
54         mainSize_ = listItemGroupPaintInfo.mainSize;
55         if (!pressedItem.empty()) {
56             for (auto& child : itemPosition_) {
57                 if (pressedItem.find(child.second.id) != pressedItem.end()) {
58                     child.second.isPressed = true;
59                 }
60             }
61         }
62     }
63     ~ListItemGroupPaintMethod() override = default;
64 
65     CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override;
66 
67     void PaintDivider(PaintWrapper* paintWrapper, RSCanvas& canvas);
68 
69     void DrawDivider(int32_t index, int32_t laneIdx, const DividerGroupInfo& info,
70         const DividerPainter& dividerPainter, RSCanvas& canvas);
71 
72     void DrawLastLineDivider(int32_t index, int32_t laneIdx, const DividerGroupInfo& info,
73         const DividerPainter& dividerPainter, RSCanvas& canvas);
74 
75     void UpdateDividerList(const DividerGroupInfo& info, const DividerPainter& dividerPainter, RSCanvas& canvas);
76 
77 private:
78     V2::ItemDivider divider_;
79     bool vertical_ = false;
80     int32_t lanes_ = 1;
81     float spaceWidth_ = 0.0f;
82     float laneGutter_ = 0.0f;
83     float fSpacingTotal_ = 0.0f;
84     ListItemGroupLayoutAlgorithm::PositionMap itemPosition_;
85     int32_t totalItemCount_ = 0;
86     TextDirection layoutDirection_ = TextDirection::LTR;
87     float mainSize_ = 0.0f;
88 };
89 } // namespace OHOS::Ace::NG
90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_PAINT_METHOD_H