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, const ListItemGroupPaintInfo& listItemGroupPaintInfo, 45 ListItemGroupLayoutAlgorithm::PositionMap& itemPosition, 46 ListItemGroupLayoutAlgorithm::PositionMap& cachedItemPosition, 47 const std::set<int32_t>& pressedItem) 48 : divider_(divider), itemPosition_(itemPosition) 49 { 50 vertical_ = listItemGroupPaintInfo.vertical; 51 lanes_ = listItemGroupPaintInfo.lanes; 52 spaceWidth_ = listItemGroupPaintInfo.spaceWidth; 53 laneGutter_ = listItemGroupPaintInfo.laneGutter; 54 totalItemCount_ = listItemGroupPaintInfo.totalItemCount; 55 layoutDirection_ = listItemGroupPaintInfo.layoutDirection; 56 mainSize_ = listItemGroupPaintInfo.mainSize; 57 for (auto& [index, pos] : cachedItemPosition) { 58 itemPosition_[index] = pos; 59 } 60 if (!pressedItem.empty()) { 61 for (auto& child : itemPosition_) { 62 if (pressedItem.find(child.second.id) != pressedItem.end()) { 63 child.second.isPressed = true; 64 } 65 } 66 } 67 } 68 ~ListItemGroupPaintMethod() override = default; 69 70 CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override; 71 72 void PaintDivider(PaintWrapper* paintWrapper, RSCanvas& canvas); 73 74 void DrawDivider(int32_t index, int32_t laneIdx, const DividerGroupInfo& info, 75 const DividerPainter& dividerPainter, RSCanvas& canvas); 76 77 void DrawLastLineDivider(int32_t index, int32_t laneIdx, const DividerGroupInfo& info, 78 const DividerPainter& dividerPainter, RSCanvas& canvas); 79 80 void UpdateDividerList(const DividerGroupInfo& info, const DividerPainter& dividerPainter, RSCanvas& canvas); 81 82 private: 83 V2::ItemDivider divider_; 84 bool vertical_ = false; 85 int32_t lanes_ = 1; 86 float spaceWidth_ = 0.0f; 87 float laneGutter_ = 0.0f; 88 float fSpacingTotal_ = 0.0f; 89 ListItemGroupLayoutAlgorithm::PositionMap itemPosition_; 90 int32_t totalItemCount_ = 0; 91 TextDirection layoutDirection_ = TextDirection::LTR; 92 float mainSize_ = 0.0f; 93 }; 94 } // namespace OHOS::Ace::NG 95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_PAINT_METHOD_H