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 #include "core/interfaces/native/node/divider_modifier.h"
16
17 #include "core/components/divider/divider_theme.h"
18 #include "core/components_ng/pattern/divider/divider_model_ng.h"
19
20 namespace OHOS::Ace::NG {
21 constexpr bool DEFAULT_DIVIDER_VERTICAL = false;
22 const Dimension DEFAULT_DIVIDER_STROKE_WIDTH(1, DimensionUnit::PX);
23 const LineCap DEFAULT_DIVIDER_LINE_CAP = LineCap::BUTT;
24
SetDividerStrokeWidth(ArkUINodeHandle node,ArkUI_Float32 value,int32_t unit)25 void SetDividerStrokeWidth(ArkUINodeHandle node, ArkUI_Float32 value, int32_t unit)
26 {
27 auto* frameNode = reinterpret_cast<FrameNode*>(node);
28 CHECK_NULL_VOID(frameNode);
29 CalcDimension strokeWidthDimension(value, static_cast<DimensionUnit>(unit));
30 DividerModelNG::StrokeWidth(frameNode, strokeWidthDimension);
31 }
32
ResetDividerStrokeWidth(ArkUINodeHandle node)33 void ResetDividerStrokeWidth(ArkUINodeHandle node)
34 {
35 auto* frameNode = reinterpret_cast<FrameNode*>(node);
36 CHECK_NULL_VOID(frameNode);
37 DividerModelNG::StrokeWidth(frameNode, DEFAULT_DIVIDER_STROKE_WIDTH);
38 }
39
SetDividerLineCap(ArkUINodeHandle node,int32_t lineCap)40 void SetDividerLineCap(ArkUINodeHandle node, int32_t lineCap)
41 {
42 auto* frameNode = reinterpret_cast<FrameNode*>(node);
43 CHECK_NULL_VOID(frameNode);
44 auto lineCapStyle = DEFAULT_DIVIDER_LINE_CAP;
45 if (static_cast<int>(LineCap::SQUARE) == lineCap) {
46 lineCapStyle = LineCap::SQUARE;
47 } else if (static_cast<int>(LineCap::ROUND) == lineCap) {
48 lineCapStyle = LineCap::ROUND;
49 } else {
50 lineCapStyle = DEFAULT_DIVIDER_LINE_CAP;
51 }
52 DividerModelNG::LineCap(frameNode, lineCapStyle);
53 }
54
ResetDividerLineCap(ArkUINodeHandle node)55 void ResetDividerLineCap(ArkUINodeHandle node)
56 {
57 auto* frameNode = reinterpret_cast<FrameNode*>(node);
58 CHECK_NULL_VOID(frameNode);
59 DividerModelNG::LineCap(frameNode, DEFAULT_DIVIDER_LINE_CAP);
60 }
61
SetDividerColor(ArkUINodeHandle node,uint32_t color,void * colorRawPtr)62 void SetDividerColor(ArkUINodeHandle node, uint32_t color, void* colorRawPtr)
63 {
64 auto* frameNode = reinterpret_cast<FrameNode*>(node);
65 CHECK_NULL_VOID(frameNode);
66 DividerModelNG::ResetResObj(frameNode, "divider.color");
67 if (SystemProperties::ConfigChangePerform() && colorRawPtr) {
68 auto* color = reinterpret_cast<ResourceObject*>(colorRawPtr);
69 auto colorResObj = AceType::Claim(color);
70 DividerModelNG::SetDividerColor(frameNode, colorResObj, true);
71 } else {
72 DividerModelNG::SetDividerColor(frameNode, Color(color), true);
73 }
74 }
75
ResetDividerColor(ArkUINodeHandle node)76 void ResetDividerColor(ArkUINodeHandle node)
77 {
78 auto* frameNode = reinterpret_cast<FrameNode*>(node);
79 CHECK_NULL_VOID(frameNode);
80 DividerModelNG::ResetResObj(frameNode, "divider.color");
81 DividerModelNG::ResetDividerColor(frameNode);
82 }
83
SetDividerVertical(ArkUINodeHandle node,ArkUI_Bool value)84 void SetDividerVertical(ArkUINodeHandle node, ArkUI_Bool value)
85 {
86 auto* frameNode = reinterpret_cast<FrameNode*>(node);
87 CHECK_NULL_VOID(frameNode);
88 DividerModelNG::SetVertical(frameNode, value);
89 }
90
ResetDividerVertical(ArkUINodeHandle node)91 void ResetDividerVertical(ArkUINodeHandle node)
92 {
93 auto* frameNode = reinterpret_cast<FrameNode*>(node);
94 CHECK_NULL_VOID(frameNode);
95 DividerModelNG::SetVertical(frameNode, DEFAULT_DIVIDER_VERTICAL);
96 }
97
98 namespace NodeModifier {
GetDividerModifier()99 const ArkUIDividerModifier* GetDividerModifier()
100 {
101 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
102 static const ArkUIDividerModifier modifier = {
103 .setDividerStrokeWidth = SetDividerStrokeWidth,
104 .resetDividerStrokeWidth = ResetDividerStrokeWidth,
105 .setDividerLineCap = SetDividerLineCap,
106 .resetDividerLineCap = ResetDividerLineCap,
107 .setDividerColor = SetDividerColor,
108 .resetDividerColor = ResetDividerColor,
109 .setDividerVertical = SetDividerVertical,
110 .resetDividerVertical = ResetDividerVertical,
111 };
112 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
113 return &modifier;
114 }
115
GetCJUIDividerModifier()116 const CJUIDividerModifier* GetCJUIDividerModifier()
117 {
118 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
119 static const CJUIDividerModifier modifier = {
120 .setDividerStrokeWidth = SetDividerStrokeWidth,
121 .resetDividerStrokeWidth = ResetDividerStrokeWidth,
122 .setDividerLineCap = SetDividerLineCap,
123 .resetDividerLineCap = ResetDividerLineCap,
124 .setDividerColor = SetDividerColor,
125 .resetDividerColor = ResetDividerColor,
126 .setDividerVertical = SetDividerVertical,
127 .resetDividerVertical = ResetDividerVertical,
128 };
129 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
130 return &modifier;
131 }
132 }
133 } // namespace OHOS::Ace::NG
134