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_divider_arithmetic.h"
23 #include "core/components_ng/pattern/list/list_layout_algorithm.h"
24 #include "core/components_ng/property/property.h"
25 #include "core/components_ng/render/animation_utils.h"
26 #include "core/components_ng/render/drawing.h"
27 
28 namespace OHOS::Ace::NG {
29 class ListContentModifier : public ContentModifier {
30     DECLARE_ACE_TYPE(ListContentModifier, ContentModifier);
31 public:
32     ListContentModifier(const OffsetF& clipOffset, const SizeF& clipSize);
33     ~ListContentModifier() override = default;
34     void onDraw(DrawingContext& context) override;
35 
SetClipOffset(OffsetF offset)36     void SetClipOffset(OffsetF offset)
37     {
38         clipOffset_->Set(offset);
39     }
40 
SetClipSize(SizeF size)41     void SetClipSize(SizeF size)
42     {
43         clipSize_->Set(size);
44     }
45 
SetClip(bool clip)46     void SetClip(bool clip)
47     {
48         clip_->Set(clip);
49     }
50 
SetDividerPainter(float width,bool isVertical,Color color)51     void SetDividerPainter(float width, bool isVertical, Color color)
52     {
53         width_ = width;
54         isVertical_ = isVertical;
55         color_->Set(LinearColor(color));
56     }
57 
SetDividerMap(const ListDividerMap & dividerMap)58     void SetDividerMap(const ListDividerMap& dividerMap)
59     {
60         CHECK_NULL_VOID(refDivider_);
61         refDivider_->SetMap(dividerMap);
62         RefPtr<ListDividerArithmetic> lda = AceType::MakeRefPtr<ListDividerArithmetic>(dividerMap, refDivider_);
63         CHECK_NULL_VOID(dividerList_);
64         dividerList_->Set(AceType::DynamicCast<CustomAnimatableArithmetic>(lda));
65     }
66 
67 private:
68     RefPtr<AnimatableArithmeticProperty> dividerList_;
69     RefPtr<AnimatablePropertyOffsetF> clipOffset_;
70     RefPtr<AnimatablePropertySizeF> clipSize_;
71     RefPtr<AnimatablePropertyColor> color_;
72     RefPtr<PropertyBool> clip_;
73     RefPtr<RefDividerMap> refDivider_;
74 
75     float width_ = 0.0f;
76     bool isVertical_ = true;
77 
78     ACE_DISALLOW_COPY_AND_MOVE(ListContentModifier);
79 };
80 } // namespace OHOS::Ace::NG
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_LIST_LIST_CONTENT_MODIFIER_H
83