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_PAINT_METHOD_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_PAINT_METHOD_H 18 19 #include "core/components_ng/pattern/list/list_content_modifier.h" 20 #include "core/components_ng/pattern/scroll/inner/scroll_bar.h" 21 #include "core/components_ng/pattern/scroll/scroll_edge_effect.h" 22 #include "core/components_ng/pattern/scrollable/scrollable_paint_method.h" 23 #include "core/components_v2/list/list_properties.h" 24 25 namespace OHOS::Ace::NG { 26 struct DividerInfo { 27 float constrainStrokeWidth = 0.0f; 28 float mainSize = 0.0f; 29 float crossSize = 0.0f; 30 float mainPadding = 0.0f; 31 float crossPadding = 0.0f; 32 float startMargin = 0.0f; 33 float endMargin = 0.0f; 34 float space = 0.0f; 35 float laneGutter = 0.0f; 36 int32_t lanes = 1; 37 int32_t totalItemCount = 0; 38 Color color = Color::TRANSPARENT; 39 bool isVertical = true; 40 }; 41 42 class ACE_EXPORT ListPaintMethod : public ScrollablePaintMethod { 43 DECLARE_ACE_TYPE(ListPaintMethod, ScrollablePaintMethod); 44 public: 45 using PositionMap = ListLayoutAlgorithm::PositionMap; ListPaintMethod(const V2::ItemDivider & divider,bool vertical,bool isReverse,int32_t lanes,float space)46 ListPaintMethod(const V2::ItemDivider& divider, bool vertical, bool isReverse, int32_t lanes, float space) 47 : ScrollablePaintMethod(vertical, isReverse), divider_(divider), lanes_(lanes), space_(space) 48 {} 49 ~ListPaintMethod() override = default; 50 51 CanvasDrawFunction GetForegroundDrawFunction(PaintWrapper* paintWrapper) override; 52 GetContentModifier(PaintWrapper * paintWrapper)53 RefPtr<Modifier> GetContentModifier(PaintWrapper* paintWrapper) override 54 { 55 return listContentModifier_; 56 } 57 58 void UpdateContentModifier(PaintWrapper* paintWrapper) override; 59 60 void UpdateBoundsRect(const RectF& frameRect, bool clip); 61 62 void UpdateDividerList(const DividerInfo& dividerInfo, bool clip); 63 64 ListDivider HandleDividerList(int32_t index, bool lastIsGroup, int32_t laneIdx, const DividerInfo& dividerInfo); 65 ListDivider HandleLastLineIndex(int32_t index, int32_t laneIdx, const DividerInfo& dividerInfo); 66 67 void PaintEdgeEffect(PaintWrapper* paintWrapper, RSCanvas& canvas); 68 SetScrollBar(WeakPtr<ScrollBar> && scrollBar)69 void SetScrollBar(WeakPtr<ScrollBar>&& scrollBar) 70 { 71 scrollBar_ = scrollBar; 72 } 73 SetEdgeEffect(WeakPtr<ScrollEdgeEffect> && edgeEffect)74 void SetEdgeEffect(WeakPtr<ScrollEdgeEffect>&& edgeEffect) 75 { 76 edgeEffect_ = edgeEffect; 77 } 78 SetTotalItemCount(int32_t totalItemCount)79 void SetTotalItemCount(int32_t totalItemCount) 80 { 81 totalItemCount_ = totalItemCount; 82 } 83 SetDirection(bool isRTL)84 void SetDirection(bool isRTL) 85 { 86 isRTL_ = isRTL; 87 } 88 SetContentModifier(const RefPtr<ListContentModifier> & modify)89 void SetContentModifier(const RefPtr<ListContentModifier>& modify) 90 { 91 listContentModifier_ = modify; 92 } 93 SetLaneIdx(int32_t idx)94 void SetLaneIdx(int32_t idx) 95 { 96 initLaneIdx_ = idx; 97 } 98 SetItemsPosition(const PositionMap & positionMap,const PositionMap & cachedPositionMap,const std::set<int32_t> & pressedItem,bool showCached,bool clip)99 void SetItemsPosition(const PositionMap& positionMap, const PositionMap& cachedPositionMap, 100 const std::set<int32_t>& pressedItem, bool showCached, bool clip) 101 { 102 itemPosition_ = positionMap; 103 if (showCached || clip) { 104 for (auto& [index, pos] : cachedPositionMap) { 105 itemPosition_[index] = pos; 106 } 107 } 108 if (!pressedItem.empty()) { 109 for (auto& child : itemPosition_) { 110 if (pressedItem.find(child.second.id) != pressedItem.end()) { 111 child.second.isPressed = true; 112 } 113 } 114 } 115 } 116 SetLaneGutter(float laneGutter)117 void SetLaneGutter(float laneGutter) 118 { 119 laneGutter_ = laneGutter; 120 } 121 GetLaneGutter()122 float GetLaneGutter() 123 { 124 return laneGutter_; 125 } 126 SetScrollBarOverlayModifier(WeakPtr<ScrollBarOverlayModifier> && scrollBarOverlayModifier)127 void SetScrollBarOverlayModifier(WeakPtr<ScrollBarOverlayModifier>&& scrollBarOverlayModifier) 128 { 129 scrollBarOverlayModifier_ = scrollBarOverlayModifier; 130 } 131 GetOverlayModifier(PaintWrapper * paintWrapper)132 RefPtr<Modifier> GetOverlayModifier(PaintWrapper* paintWrapper) override 133 { 134 return scrollBarOverlayModifier_.Upgrade(); 135 } 136 137 void UpdateOverlayModifier(PaintWrapper* paintWrapper) override; 138 SetAdjustOffset(float adjustOffset)139 void SetAdjustOffset(float adjustOffset) 140 { 141 adjustOffset_ = adjustOffset; 142 } 143 144 private: 145 V2::ItemDivider divider_; 146 int32_t lanes_ = 1; 147 int32_t initLaneIdx_ = 0; 148 int32_t totalItemCount_ = 0; 149 float space_; 150 float laneGutter_ = 0.0f; 151 PositionMap itemPosition_; 152 float adjustOffset_ = 0.0f; 153 RefPtr<ListContentModifier> listContentModifier_; 154 155 WeakPtr<ScrollBar> scrollBar_; 156 WeakPtr<ScrollEdgeEffect> edgeEffect_; 157 WeakPtr<ScrollBarOverlayModifier> scrollBarOverlayModifier_; 158 bool isRTL_ = false; 159 }; 160 } // namespace OHOS::Ace::NG 161 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LIST_LIST_PAINT_METHOD_H