1 /* 2 * Copyright (c) 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_CONTENT_MODIFIER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_CONTENT_MODIFIER_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components_ng/base/modifier.h" 22 #include "core/components_ng/pattern/list/list_layout_algorithm.h" 23 #include "core/components_ng/property/property.h" 24 #include "core/components_ng/render/animation_utils.h" 25 #include "core/components_ng/render/drawing.h" 26 27 namespace OHOS::Ace::NG { 28 struct DividerInfo { 29 float constrainStrokeWidth; 30 float crossSize; 31 float startMargin; 32 float endMargin; 33 float space; 34 float mainPadding; 35 float crossPadding; 36 bool isVertical; 37 int32_t lanes; 38 int32_t totalItemCount; 39 Color color; 40 float laneGutter = 0.0f; 41 }; 42 43 class ListContentModifier : public ContentModifier { 44 DECLARE_ACE_TYPE(ListContentModifier, ContentModifier); 45 public: 46 using PositionMap = ListLayoutAlgorithm::PositionMap; 47 ListContentModifier(const OffsetF& clipOffset, const SizeF& clipSize); 48 ~ListContentModifier() override = default; 49 void onDraw(DrawingContext& context) override; 50 SetClipOffset(OffsetF offset)51 void SetClipOffset(OffsetF offset) 52 { 53 clipOffset_->Set(offset); 54 } 55 SetClipSize(SizeF size)56 void SetClipSize(SizeF size) 57 { 58 clipSize_->Set(size); 59 } 60 SetClip(bool clip)61 void SetClip(bool clip) 62 { 63 clip_->Set(clip); 64 } 65 SetDividerInfo(DividerInfo && dividerInfo)66 void SetDividerInfo(DividerInfo&& dividerInfo) 67 { 68 dividerInfo_ = dividerInfo; 69 } 70 ResetDividerInfo()71 void ResetDividerInfo() 72 { 73 if (dividerInfo_.has_value()) { 74 dividerInfo_.reset(); 75 FlushDivider(); 76 } 77 } 78 SetItemsPosition(const PositionMap & positionMap)79 void SetItemsPosition(const PositionMap& positionMap) 80 { 81 itemPosition_ = positionMap; 82 } 83 84 static void PaintDivider(const DividerInfo& dividerInfo, const PositionMap& itemPosition, RSCanvas& canvas); 85 FlushDivider()86 void FlushDivider() 87 { 88 flushDivider_->Set(!flushDivider_->Get()); 89 } 90 91 private: 92 RefPtr<AnimatablePropertyOffsetF> clipOffset_; 93 RefPtr<AnimatablePropertySizeF> clipSize_; 94 RefPtr<PropertyBool> clip_; 95 96 std::optional<DividerInfo> dividerInfo_; 97 PositionMap itemPosition_; 98 RefPtr<PropertyBool> flushDivider_; 99 100 ACE_DISALLOW_COPY_AND_MOVE(ListContentModifier); 101 }; 102 } // namespace OHOS::Ace::NG 103 104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_CONTENT_MODIFIER_H 105