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 #include "core/components_ng/pattern/list/list_content_modifier.h"
17
18 #include "core/components_ng/render/divider_painter.h"
19
20 namespace OHOS::Ace::NG {
ListContentModifier(const OffsetF & clipOffset,const SizeF & clipSize)21 ListContentModifier::ListContentModifier(const OffsetF& clipOffset, const SizeF& clipSize)
22 {
23 color_ = AceType::MakeRefPtr<AnimatablePropertyColor>(LinearColor::TRANSPARENT);
24 refDivider_ = AceType::MakeRefPtr<RefDividerMap>();
25 ListDividerMap dividerMap;
26 RefPtr<ListDividerArithmetic> lda = AceType::MakeRefPtr<ListDividerArithmetic>(dividerMap, refDivider_);
27 dividerList_ = AceType::MakeRefPtr<AnimatableArithmeticProperty>(
28 AceType::DynamicCast<CustomAnimatableArithmetic>(lda));
29
30 AttachProperty(color_);
31 AttachProperty(dividerList_);
32 }
33
onDraw(DrawingContext & context)34 void ListContentModifier::onDraw(DrawingContext& context)
35 {
36 CHECK_NULL_VOID(dividerList_);
37 auto dividerlist = dividerList_->Get();
38 CHECK_NULL_VOID(dividerlist);
39 auto lda = AceType::DynamicCast<ListDividerArithmetic>(dividerlist);
40 CHECK_NULL_VOID(lda);
41 const auto& dividerMap = isNeedDividerAnimation_ ? lda->GetDividerMap() : refDivider_->GetMap();
42 if (!dividerMap.empty()) {
43 DividerPainter dividerPainter(
44 width_, 0, isVertical_, color_->Get().ToColor(), LineCap::SQUARE);
45 for (const auto& child : dividerMap) {
46 if (child.second.length > 0) {
47 dividerPainter.SetDividerLength(child.second.length);
48 dividerPainter.DrawLine(context.canvas, child.second.offset);
49 }
50 }
51 }
52 }
53 } // namespace OHOS::Ace::NG
54