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/button_modifier.h"
16
17 #include "bridge/common/utils/utils.h"
18 #include "core/common/container.h"
19 #include "core/components_ng/base/view_abstract_model.h"
20 #include "core/components_ng/pattern/button/button_model_ng.h"
21 #include "frameworks/core/components/button/button_theme.h"
22
23 namespace OHOS::Ace::NG {
24 namespace {
25 constexpr int32_t DEFAULT_BUTTON_TYPE = (int32_t)ButtonType::CAPSULE;
26 constexpr int32_t DEFAULT_BUTTON_TYPE_VERSION_EIGHTEEN = (int32_t)ButtonType::ROUNDED_RECTANGLE;
27 constexpr bool DEFAULT_STATE_EFFECT = true;
28 constexpr Ace::FontWeight DEFAULT_FONT_WEIGHT = Ace::FontWeight::NORMAL;
29 constexpr Ace::FontStyle DEFAULT_FONT_STYLE = Ace::FontStyle::NORMAL;
30 constexpr float DEFAULT_MIN_FONT_SCALE = 0.0f;
31 constexpr float DEFAULT_MAX_FONT_SCALE = static_cast<float>(INT32_MAX);
32 constexpr uint32_t INDEX_STRING_FONT_WEIGHT_0 = 0;
33 constexpr uint32_t INDEX_STRING_FONT_FAMILY_1 = 1;
34 constexpr uint32_t INDEX_VALUE_TEXT_OVERFLOW_0 = 0;
35 constexpr uint32_t INDEX_VALUE_MAX_LINES_1 = 1;
36 constexpr uint32_t INDEX_VALUE_ADAPT_HEIGHT_2 = 2;
37 constexpr uint32_t INDEX_VALUE_FONT_STYLE_3 = 3;
38 constexpr uint32_t INDEX_DIMENSION_MIN_FONT_SIZE_0 = 0;
39 constexpr uint32_t INDEX_DIMENSION_MAX_FONT_SIZE_1 = 1;
40 constexpr uint32_t INDEX_DIMENSION_FONT_SIZE_2 = 2;
41 constexpr uint32_t INDEX_STRING_ARRAY_COUNT = 0;
42 constexpr uint32_t INDEX_VALUE_ARRAY_COUNT = 1;
43 constexpr uint32_t INDEX_DIMENSION_ARRAY_COUNT = 2;
44 constexpr uint32_t INDEX_INVALID_FONT_FAMILY_0 = 0;
45 const std::string DEFAULT_FONT_FAMILY = "HarmonyOS Sans";
46 constexpr int32_t OFFSET_1 = 1;
47 constexpr int32_t OFFSET_2 = 2;
48 constexpr int32_t OFFSET_3 = 3;
49 constexpr int32_t BORDER_RADIUS_SIZE = 12; // BorderRadius array size
50 const std::vector<TextOverflow> TEXT_OVERFLOWS = { TextOverflow::NONE, TextOverflow::CLIP, TextOverflow::ELLIPSIS,
51 TextOverflow::MARQUEE };
52 const std::vector<Ace::FontStyle> FONT_STYLES = { Ace::FontStyle::NORMAL, Ace::FontStyle::ITALIC };
53 const std::vector<TextHeightAdaptivePolicy> HEIGHT_ADAPTIVE_POLICY = { TextHeightAdaptivePolicy::MAX_LINES_FIRST,
54 TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST, TextHeightAdaptivePolicy::LAYOUT_CONSTRAINT_FIRST };
55 const std::string NONE_FONT_FAMILY = "NoneFontFamily";
56 const uint32_t ERROR_UINT_CODE = -1;
57 const float ERROR_FLOAT_CODE = -1.0f;
58 const int32_t ERROR_INT_CODE = -1;
59 thread_local std::string g_strValue;
60
61 const std::unordered_map<int, DimensionUnit> DIMENSION_UNIT_MAP = {
62 { -2, DimensionUnit::INVALID },
63 { -1, DimensionUnit::NONE },
64 { 0, DimensionUnit::PX },
65 { 1, DimensionUnit::VP },
66 { 2, DimensionUnit::FP },
67 { 3, DimensionUnit::PERCENT },
68 { 4, DimensionUnit::LPX },
69 { 5, DimensionUnit::AUTO },
70 { 6, DimensionUnit::CALC },
71 };
72
73 const std::vector<FontWeight> BUTTON_FONT_WEIGHTS = {
74 FontWeight::W100,
75 FontWeight::W200,
76 FontWeight::W300,
77 FontWeight::W400,
78 FontWeight::W500,
79 FontWeight::W600,
80 FontWeight::W700,
81 FontWeight::W800,
82 FontWeight::W900,
83 FontWeight::BOLD,
84 FontWeight::BOLDER,
85 FontWeight::LIGHTER,
86 FontWeight::MEDIUM,
87 FontWeight::NORMAL,
88 FontWeight::REGULAR,
89 };
90 } // namespace
91
SetOptionalBorderRadius(std::optional<Dimension> & optionalDimension,const ArkUI_Float32 * values,int32_t valuesSize,int32_t & offset)92 void SetOptionalBorderRadius(
93 std::optional<Dimension>& optionalDimension, const ArkUI_Float32* values, int32_t valuesSize, int32_t& offset)
94 {
95 bool hasValue = static_cast<bool>(values[offset]);
96 if (hasValue) {
97 optionalDimension =
98 Dimension(values[offset + OFFSET_1], static_cast<OHOS::Ace::DimensionUnit>(values[offset + OFFSET_2]));
99 }
100 offset = offset + OFFSET_3;
101 }
102
SetButtonLabel(ArkUINodeHandle node,ArkUI_CharPtr label)103 void SetButtonLabel(ArkUINodeHandle node, ArkUI_CharPtr label)
104 {
105 auto* frameNode = reinterpret_cast<FrameNode*>(node);
106 CHECK_NULL_VOID(frameNode);
107 ButtonModelNG::SetLabel(frameNode, label);
108 }
109
ResetButtonLabel(ArkUINodeHandle node)110 void ResetButtonLabel(ArkUINodeHandle node)
111 {
112 auto* frameNode = reinterpret_cast<FrameNode*>(node);
113 CHECK_NULL_VOID(frameNode);
114 ButtonModelNG::SetLabel(frameNode, "");
115 }
116
SetButtonType(ArkUINodeHandle node,int type)117 void SetButtonType(ArkUINodeHandle node, int type)
118 {
119 auto* frameNode = reinterpret_cast<FrameNode*>(node);
120 CHECK_NULL_VOID(frameNode);
121 if ((ButtonType)type == ButtonType::CAPSULE || (ButtonType)type == ButtonType::CIRCLE ||
122 (ButtonType)type == ButtonType::ARC || (ButtonType)type == ButtonType::NORMAL ||
123 (ButtonType)type == ButtonType::ROUNDED_RECTANGLE) {
124 ButtonModelNG::SetType(frameNode, type);
125 }
126 }
127
ResetButtonType(ArkUINodeHandle node)128 void ResetButtonType(ArkUINodeHandle node)
129 {
130 auto* frameNode = reinterpret_cast<FrameNode*>(node);
131 CHECK_NULL_VOID(frameNode);
132 if (frameNode->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) {
133 ButtonModelNG::SetType(frameNode, DEFAULT_BUTTON_TYPE_VERSION_EIGHTEEN);
134 } else {
135 ButtonModelNG::SetType(frameNode, DEFAULT_BUTTON_TYPE);
136 }
137
138 return;
139 }
140
SetButtonStateEffect(ArkUINodeHandle node,ArkUI_Bool stateEffect)141 void SetButtonStateEffect(ArkUINodeHandle node, ArkUI_Bool stateEffect)
142 {
143 auto* frameNode = reinterpret_cast<FrameNode*>(node);
144 CHECK_NULL_VOID(frameNode);
145 ButtonModelNG::SetStateEffect(frameNode, stateEffect);
146 }
147
ResetButtonStateEffect(ArkUINodeHandle node)148 void ResetButtonStateEffect(ArkUINodeHandle node)
149 {
150 auto* frameNode = reinterpret_cast<FrameNode*>(node);
151 CHECK_NULL_VOID(frameNode);
152 ButtonModelNG::SetStateEffect(frameNode, DEFAULT_STATE_EFFECT);
153 }
154
SetButtonFontColor(ArkUINodeHandle node,uint32_t fontColor)155 void SetButtonFontColor(ArkUINodeHandle node, uint32_t fontColor)
156 {
157 auto* frameNode = reinterpret_cast<FrameNode*>(node);
158 CHECK_NULL_VOID(frameNode);
159 ButtonModelNG::SetFontColor(frameNode, Color(fontColor));
160 }
161
SetButtonFontColorPtr(ArkUINodeHandle node,uint32_t fontColor,void * colorRawPtr)162 void SetButtonFontColorPtr(ArkUINodeHandle node, uint32_t fontColor, void* colorRawPtr)
163 {
164 CHECK_NULL_VOID(node);
165 SetButtonFontColor(node, fontColor);
166 if (SystemProperties::ConfigChangePerform()) {
167 auto* frameNode = reinterpret_cast<FrameNode*>(node);
168 CHECK_NULL_VOID(frameNode);
169 auto* color = reinterpret_cast<ResourceObject*>(colorRawPtr);
170 auto colorResObj = AceType::Claim(color);
171 ButtonModelNG::CreateWithColorResourceObj(frameNode, colorResObj, ButtonColorType::FONT_COLOR);
172 }
173 }
174
ResetButtonFontColor(ArkUINodeHandle node)175 void ResetButtonFontColor(ArkUINodeHandle node)
176 {
177 auto* frameNode = reinterpret_cast<FrameNode*>(node);
178 CHECK_NULL_VOID(frameNode);
179 auto pipeline = PipelineBase::GetCurrentContext();
180 CHECK_NULL_VOID(pipeline);
181 auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
182 CHECK_NULL_VOID(buttonTheme);
183 Color textColor = buttonTheme->GetTextStyle().GetTextColor();
184 ButtonModelNG::SetFontColor(frameNode, textColor);
185 if (SystemProperties::ConfigChangePerform()) {
186 ButtonModelNG::CreateWithColorResourceObj(frameNode, nullptr, ButtonColorType::FONT_COLOR);
187 }
188 }
189
ResetButtonFontSizeInternal(ArkUINodeHandle node)190 void ResetButtonFontSizeInternal(ArkUINodeHandle node)
191 {
192 auto* frameNode = reinterpret_cast<FrameNode*>(node);
193 CHECK_NULL_VOID(frameNode);
194 auto pipeline = PipelineBase::GetCurrentContext();
195 CHECK_NULL_VOID(pipeline);
196 auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
197 CHECK_NULL_VOID(buttonTheme);
198 CalcDimension fontSize = buttonTheme->GetTextStyle().GetFontSize();
199 ButtonModelNG::SetFontSize(frameNode, fontSize);
200 }
201
SetButtonFontSize(ArkUINodeHandle node,ArkUI_Float32 fontSizeValue,int fontSizeUnit)202 void SetButtonFontSize(ArkUINodeHandle node, ArkUI_Float32 fontSizeValue, int fontSizeUnit)
203 {
204 auto* frameNode = reinterpret_cast<FrameNode*>(node);
205 CHECK_NULL_VOID(frameNode);
206 if (LessNotEqual(fontSizeValue, 0.0)) {
207 ResetButtonFontSizeInternal(node);
208 } else {
209 ButtonModelNG::SetFontSize(frameNode, CalcDimension(fontSizeValue, (DimensionUnit)fontSizeUnit));
210 }
211 }
212
ResetButtonFontSize(ArkUINodeHandle node)213 void ResetButtonFontSize(ArkUINodeHandle node)
214 {
215 ResetButtonFontSizeInternal(node);
216 }
217
SetButtonFontWeight(ArkUINodeHandle node,ArkUI_CharPtr fontWeight)218 void SetButtonFontWeight(ArkUINodeHandle node, ArkUI_CharPtr fontWeight)
219 {
220 auto* frameNode = reinterpret_cast<FrameNode*>(node);
221 CHECK_NULL_VOID(frameNode);
222 std::string fontWeightStr = fontWeight;
223 ButtonModelNG::SetFontWeight(frameNode, Framework::ConvertStrToFontWeight(fontWeightStr));
224 }
225
SetButtonFontWeightEnum(ArkUINodeHandle node,int fontWeight)226 void SetButtonFontWeightEnum(ArkUINodeHandle node, int fontWeight)
227 {
228 auto* frameNode = reinterpret_cast<FrameNode*>(node);
229 CHECK_NULL_VOID(frameNode);
230 ButtonModelNG::SetFontWeight(frameNode, static_cast<FontWeight>(fontWeight));
231 }
232
ResetButtonFontWeight(ArkUINodeHandle node)233 void ResetButtonFontWeight(ArkUINodeHandle node)
234 {
235 auto* frameNode = reinterpret_cast<FrameNode*>(node);
236 CHECK_NULL_VOID(frameNode);
237 ButtonModelNG::SetFontWeight(frameNode, DEFAULT_FONT_WEIGHT);
238 }
239
SetButtonFontStyle(ArkUINodeHandle node,int32_t fontStyle)240 void SetButtonFontStyle(ArkUINodeHandle node, int32_t fontStyle)
241 {
242 auto* frameNode = reinterpret_cast<FrameNode*>(node);
243 CHECK_NULL_VOID(frameNode);
244 if (fontStyle < 0 || fontStyle >= static_cast<int32_t>(FONT_STYLES.size())) {
245 ButtonModelNG::SetFontStyle(frameNode, DEFAULT_FONT_STYLE);
246 } else {
247 ButtonModelNG::SetFontStyle(frameNode, FONT_STYLES[fontStyle]);
248 }
249 }
250
ResetButtonFontStyle(ArkUINodeHandle node)251 void ResetButtonFontStyle(ArkUINodeHandle node)
252 {
253 auto* frameNode = reinterpret_cast<FrameNode*>(node);
254 CHECK_NULL_VOID(frameNode);
255 ButtonModelNG::SetFontStyle(frameNode, DEFAULT_FONT_STYLE);
256 }
257
SetButtonFontFamily(ArkUINodeHandle node,ArkUI_CharPtr fontFamily)258 void SetButtonFontFamily(ArkUINodeHandle node, ArkUI_CharPtr fontFamily)
259 {
260 auto* frameNode = reinterpret_cast<FrameNode*>(node);
261 CHECK_NULL_VOID(frameNode);
262 std::string familiesStr = fontFamily;
263 std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
264 ButtonModelNG::SetFontFamily(frameNode, fontFamilyResult);
265 }
266
SetButtonFontFamilyPtr(ArkUINodeHandle node,ArkUI_CharPtr fontFamily,void * familiesRawPtr)267 void SetButtonFontFamilyPtr(ArkUINodeHandle node, ArkUI_CharPtr fontFamily, void* familiesRawPtr)
268 {
269 CHECK_NULL_VOID(node);
270 SetButtonFontFamily(node, fontFamily);
271 if (SystemProperties::ConfigChangePerform()) {
272 auto* frameNode = reinterpret_cast<FrameNode*>(node);
273 CHECK_NULL_VOID(frameNode);
274 auto* families = reinterpret_cast<ResourceObject*>(familiesRawPtr);
275 auto familiesResObj = AceType::Claim(families);
276 ButtonModelNG::CreateWithFamiliesResourceObj(frameNode, familiesResObj, ButtonStringType::FONT_FAMILY);
277 }
278 }
279
ResetButtonFontFamily(ArkUINodeHandle node)280 void ResetButtonFontFamily(ArkUINodeHandle node)
281 {
282 auto* frameNode = reinterpret_cast<FrameNode*>(node);
283 CHECK_NULL_VOID(frameNode);
284 std::string familiesStr = DEFAULT_FONT_FAMILY;
285 std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
286 ButtonModelNG::SetFontFamily(frameNode, fontFamilyResult);
287 if (SystemProperties::ConfigChangePerform()) {
288 ButtonModelNG::CreateWithFamiliesResourceObj(frameNode, nullptr, ButtonStringType::FONT_FAMILY);
289 }
290 }
291
ButtonCompleteParameters(ButtonParameters & buttonParameters)292 void ButtonCompleteParameters(ButtonParameters& buttonParameters)
293 {
294 auto pipeline = PipelineBase::GetCurrentContext();
295 CHECK_NULL_VOID(pipeline);
296 auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
297 if (!buttonTheme) {
298 return;
299 }
300 auto textStyle = buttonTheme->GetTextStyle();
301 if (!buttonParameters.textOverflow.has_value()) {
302 buttonParameters.textOverflow = TextOverflow::CLIP;
303 }
304 if (!buttonParameters.maxLines.has_value()) {
305 buttonParameters.maxLines = buttonTheme->GetTextMaxLines();
306 }
307 if (!buttonParameters.fontSize.has_value()) {
308 buttonParameters.fontSize = textStyle.GetFontSize();
309 }
310 if (!buttonParameters.fontWeight.has_value()) {
311 buttonParameters.fontWeight = textStyle.GetFontWeight();
312 }
313 if (!buttonParameters.fontStyle.has_value()) {
314 buttonParameters.fontStyle = textStyle.GetFontStyle();
315 }
316 if (!buttonParameters.heightAdaptivePolicy.has_value()) {
317 buttonParameters.heightAdaptivePolicy = TextHeightAdaptivePolicy::MAX_LINES_FIRST;
318 }
319 }
320
SetButtonDimension(const ArkUI_Float32 * dimensionArray,uint32_t offset,const size_t dataCount,std::optional<CalcDimension> & optDimension)321 bool SetButtonDimension(
322 const ArkUI_Float32* dimensionArray, uint32_t offset, const size_t dataCount,
323 std::optional<CalcDimension>& optDimension)
324 {
325 CHECK_NULL_RETURN(dimensionArray, false);
326 auto hasValue = dimensionArray[offset];
327 if (!static_cast<bool>(hasValue)) {
328 return false;
329 }
330 uint32_t valueIndex = offset + 1;
331 uint32_t unitIndex = offset + 2;
332 if (unitIndex >= dataCount) {
333 return false;
334 }
335 auto value = dimensionArray[valueIndex];
336 auto unit = dimensionArray[unitIndex];
337 DimensionUnit unitValue = static_cast<DimensionUnit>(unit);
338 CalcDimension dimensionValue = CalcDimension(value, unitValue);
339 optDimension = dimensionValue;
340 return true;
341 }
342
SetButtonDimensionParameters(const ArkUI_Float32 * dimensionArray,const size_t dataCount,ButtonParameters & buttonParameters)343 void SetButtonDimensionParameters(
344 const ArkUI_Float32* dimensionArray, const size_t dataCount, ButtonParameters& buttonParameters)
345 {
346 CHECK_NULL_VOID(dimensionArray);
347 uint32_t step = 3;
348 uint32_t minFontSizeIndex = INDEX_DIMENSION_MIN_FONT_SIZE_0;
349 std::optional<CalcDimension> minFontSizeOptional = std::nullopt;
350 if (SetButtonDimension(dimensionArray, minFontSizeIndex, dataCount, minFontSizeOptional)) {
351 buttonParameters.minFontSize = minFontSizeOptional;
352 }
353 uint32_t maxFontSizeIndex = INDEX_DIMENSION_MAX_FONT_SIZE_1 * step;
354 std::optional<CalcDimension> maxFontSizeOptional = std::nullopt;
355 if (SetButtonDimension(dimensionArray, maxFontSizeIndex, dataCount, maxFontSizeOptional)) {
356 buttonParameters.maxFontSize = maxFontSizeOptional;
357 }
358 uint32_t fontSizeIndex = INDEX_DIMENSION_FONT_SIZE_2 * step;
359 std::optional<CalcDimension> fontSizeOptional = std::nullopt;
360 if (SetButtonDimension(dimensionArray, fontSizeIndex, dataCount, fontSizeOptional)) {
361 buttonParameters.fontSize = fontSizeOptional;
362 }
363 }
364
SetButtonValue(const int32_t * valueArray,uint32_t index,const size_t dataCount,int32_t & result)365 bool SetButtonValue(const int32_t* valueArray, uint32_t index, const size_t dataCount, int32_t& result)
366 {
367 CHECK_NULL_RETURN(valueArray, false);
368 uint32_t step = 2;
369 auto hasValueIndex = index * step;
370 auto valueIndex = hasValueIndex + 1;
371 if (valueIndex >= dataCount) {
372 return false;
373 }
374 if (static_cast<bool>(valueArray[hasValueIndex])) {
375 result = valueArray[valueIndex];
376 return true;
377 }
378 return false;
379 }
380
SetButtonValueParameters(const int32_t * valueArray,const size_t dataCount,ButtonParameters & buttonParameters)381 void SetButtonValueParameters(const int32_t* valueArray, const size_t dataCount, ButtonParameters& buttonParameters)
382 {
383 CHECK_NULL_VOID(valueArray);
384 int32_t result = 0;
385 buttonParameters.textOverflow = TextOverflow::ELLIPSIS;
386 if (SetButtonValue(valueArray, INDEX_VALUE_TEXT_OVERFLOW_0, dataCount, result) && result >= 0 &&
387 result < static_cast<int32_t>(TEXT_OVERFLOWS.size())) {
388 buttonParameters.textOverflow = TEXT_OVERFLOWS[result];
389 }
390 buttonParameters.maxLines = std::nullopt;
391 if (SetButtonValue(valueArray, INDEX_VALUE_MAX_LINES_1, dataCount, result) && result >= 0) {
392 buttonParameters.maxLines = Positive(result) ? result : 1;
393 }
394 buttonParameters.heightAdaptivePolicy = std::nullopt;
395 if (SetButtonValue(valueArray, INDEX_VALUE_ADAPT_HEIGHT_2, dataCount, result) && result >= 0 &&
396 result < static_cast<int32_t>(HEIGHT_ADAPTIVE_POLICY.size())) {
397 buttonParameters.heightAdaptivePolicy = HEIGHT_ADAPTIVE_POLICY[result];
398 }
399 buttonParameters.fontStyle = std::nullopt;
400 if (SetButtonValue(valueArray, INDEX_VALUE_FONT_STYLE_3, dataCount, result) && result >= 0 &&
401 result < static_cast<int32_t>(FONT_STYLES.size())) {
402 buttonParameters.fontStyle = FONT_STYLES[result];
403 }
404 }
405
SetButtonStringParameters(ArkUI_CharPtr * stringParameters,const size_t dataCount,ButtonParameters & buttonParameters)406 void SetButtonStringParameters(
407 ArkUI_CharPtr* stringParameters, const size_t dataCount, ButtonParameters& buttonParameters)
408 {
409 CHECK_NULL_VOID(stringParameters);
410 buttonParameters.fontWeight = std::nullopt;
411 if (INDEX_STRING_FONT_WEIGHT_0 < dataCount && stringParameters[INDEX_STRING_FONT_WEIGHT_0] != nullptr) {
412 std::string fontWeightStr = stringParameters[INDEX_STRING_FONT_WEIGHT_0];
413 buttonParameters.fontWeight = Framework::ConvertStrToFontWeight(fontWeightStr);
414 }
415 buttonParameters.fontFamily = std::nullopt;
416 if (INDEX_STRING_FONT_FAMILY_1 < dataCount && stringParameters[INDEX_STRING_FONT_FAMILY_1] != nullptr) {
417 std::string familiesStr = stringParameters[INDEX_STRING_FONT_FAMILY_1];
418 std::vector<std::string> fontFamilyResult = Framework::ConvertStrToFontFamilies(familiesStr);
419 if (fontFamilyResult.size() == 1 &&
420 fontFamilyResult[INDEX_INVALID_FONT_FAMILY_0].compare(NONE_FONT_FAMILY) == 0) {
421 return;
422 }
423 buttonParameters.fontFamily = fontFamilyResult;
424 }
425 }
426
SetButtonLabelStyle(ArkUINodeHandle node,ArkUI_CharPtr * stringParameters,const ArkUI_Int32 * valueArray,const ArkUI_Float32 * dimensionArray,const ArkUI_Uint32 * dataCountArray)427 void SetButtonLabelStyle(ArkUINodeHandle node, ArkUI_CharPtr* stringParameters, const ArkUI_Int32* valueArray,
428 const ArkUI_Float32* dimensionArray, const ArkUI_Uint32* dataCountArray)
429 {
430 auto* frameNode = reinterpret_cast<FrameNode*>(node);
431 CHECK_NULL_VOID(frameNode);
432 ButtonParameters buttonParameters;
433 SetButtonStringParameters(stringParameters, dataCountArray[INDEX_STRING_ARRAY_COUNT], buttonParameters);
434 SetButtonValueParameters(valueArray, dataCountArray[INDEX_VALUE_ARRAY_COUNT], buttonParameters);
435 SetButtonDimensionParameters(dimensionArray, dataCountArray[INDEX_DIMENSION_ARRAY_COUNT], buttonParameters);
436 ButtonCompleteParameters(buttonParameters);
437 ButtonModelNG::SetLabelStyle(frameNode, buttonParameters);
438 }
439
SetButtonLabelStylePtr(ArkUINodeHandle node,ArkUI_CharPtr * stringParameters,const ArkUI_Int32 * valueArray,const ArkUI_Float32 * dimensionArray,const ArkUI_Uint32 * dataCountArray,const ArkUIButtonSizeStruct & sizeResObj)440 void SetButtonLabelStylePtr(ArkUINodeHandle node, ArkUI_CharPtr* stringParameters, const ArkUI_Int32* valueArray,
441 const ArkUI_Float32* dimensionArray, const ArkUI_Uint32* dataCountArray, const ArkUIButtonSizeStruct& sizeResObj)
442 {
443 CHECK_NULL_VOID(node);
444 SetButtonLabelStyle(node, stringParameters, valueArray, dimensionArray, dataCountArray);
445 if (SystemProperties::ConfigChangePerform()) {
446 auto* frameNode = reinterpret_cast<FrameNode*>(node);
447 CHECK_NULL_VOID(frameNode);
448 auto* minFontSize = reinterpret_cast<ResourceObject*>(sizeResObj.minFontSize);
449 auto minSizeResObj = AceType::Claim(minFontSize);
450 ButtonModelNG::CreateWithDimensionFpResourceObj(frameNode, minSizeResObj,
451 ButtonDimensionType::MIN_FONT_SIZE);
452 auto* maxFontSize = reinterpret_cast<ResourceObject*>(sizeResObj.maxFontSize);
453 auto maxSizeResObj = AceType::Claim(maxFontSize);
454 ButtonModelNG::CreateWithDimensionFpResourceObj(frameNode, maxSizeResObj,
455 ButtonDimensionType::MAX_FONT_SIZE);
456 }
457 }
458
ResetButtonLabelStyle(ArkUINodeHandle node)459 void ResetButtonLabelStyle(ArkUINodeHandle node)
460 {
461 if (SystemProperties::ConfigChangePerform()) {
462 auto* frameNode = reinterpret_cast<FrameNode*>(node);
463 CHECK_NULL_VOID(frameNode);
464 ButtonModelNG::CreateWithDimensionFpResourceObj(frameNode, nullptr, ButtonDimensionType::MIN_FONT_SIZE);
465 ButtonModelNG::CreateWithDimensionFpResourceObj(frameNode, nullptr, ButtonDimensionType::MAX_FONT_SIZE);
466 }
467 return;
468 }
469
SetButtonBackgroundColor(ArkUINodeHandle node,uint32_t color)470 void SetButtonBackgroundColor(ArkUINodeHandle node, uint32_t color)
471 {
472 auto* frameNode = reinterpret_cast<FrameNode*>(node);
473 CHECK_NULL_VOID(frameNode);
474 ButtonModelNG::BackgroundColor(frameNode, Color(color), true);
475 }
476
SetButtonBackgroundColorWithColorSpace(ArkUINodeHandle node,ArkUI_Uint32 color,ArkUI_Int32 colorSpace)477 void SetButtonBackgroundColorWithColorSpace(ArkUINodeHandle node, ArkUI_Uint32 color, ArkUI_Int32 colorSpace)
478 {
479 auto* frameNode = reinterpret_cast<FrameNode*>(node);
480 CHECK_NULL_VOID(frameNode);
481 Color backgroundColor { color };
482 if (ColorSpace::DISPLAY_P3 == colorSpace) {
483 backgroundColor.SetColorSpace(ColorSpace::DISPLAY_P3);
484 } else {
485 backgroundColor.SetColorSpace(ColorSpace::SRGB);
486 }
487 ButtonModelNG::BackgroundColor(frameNode, backgroundColor, true);
488 }
489
SetButtonBackgroundColorWithColorSpacePtr(ArkUINodeHandle node,ArkUI_Uint32 color,ArkUI_Int32 colorSpace,void * colorRawPtr)490 void SetButtonBackgroundColorWithColorSpacePtr(ArkUINodeHandle node, ArkUI_Uint32 color,
491 ArkUI_Int32 colorSpace, void* colorRawPtr)
492 {
493 CHECK_NULL_VOID(node);
494 SetButtonBackgroundColorWithColorSpace(node, color, colorSpace);
495 if (SystemProperties::ConfigChangePerform()) {
496 auto* frameNode = reinterpret_cast<FrameNode*>(node);
497 CHECK_NULL_VOID(frameNode);
498 auto* color = reinterpret_cast<ResourceObject*>(colorRawPtr);
499 auto colorResObj = AceType::Claim(color);
500 ButtonModelNG::CreateWithColorResourceObj(frameNode, colorResObj, ButtonColorType::BACKGROUND_COLOR);
501 }
502 }
503
ResetButtonBackgroundColor(ArkUINodeHandle node)504 void ResetButtonBackgroundColor(ArkUINodeHandle node)
505 {
506 auto* frameNode = reinterpret_cast<FrameNode*>(node);
507 CHECK_NULL_VOID(frameNode);
508 Color backgroundColor;
509 auto pipeline = PipelineBase::GetCurrentContext();
510 CHECK_NULL_VOID(pipeline);
511 auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
512 CHECK_NULL_VOID(buttonTheme);
513 backgroundColor = buttonTheme->GetBgColor();
514 ButtonModelNG::BackgroundColor(frameNode, backgroundColor, false);
515 if (SystemProperties::ConfigChangePerform()) {
516 ButtonModelNG::CreateWithColorResourceObj(frameNode, nullptr, ButtonColorType::BACKGROUND_COLOR);
517 }
518 }
519
520 /**
521 * @param src source borderRadius
522 * @param options option value
523 * values[offset + 0], option[offset + 1], option[offset + 2]: borderRadius topLeft(hasValue, value, unit)
524 * values[offset + 3], option[offset + 4], option[offset + 5]: borderRadius topRight(hasValue, value, unit)
525 * values[offset + 6], option[offset + 7], option[offset + 8]: borderRadius bottomLeft(hasValue, value, unit)
526 * values[offset + 9], option[offset + 10], option[offset + 11]: borderRadius bottomRight(hasValue, value, unit)
527 * @param optionsLength options valuesSize
528 */
SetButtonBorderRadius(ArkUINodeHandle node,const ArkUI_Float32 * values,int32_t valuesSize)529 void SetButtonBorderRadius(ArkUINodeHandle node, const ArkUI_Float32* values, int32_t valuesSize)
530 {
531 if ((values == nullptr) || (valuesSize != BORDER_RADIUS_SIZE)) {
532 return;
533 }
534 auto* frameNode = reinterpret_cast<FrameNode*>(node);
535 CHECK_NULL_VOID(frameNode);
536 int32_t offset = 0;
537 std::optional<Dimension> radiusTopLeft;
538 std::optional<Dimension> radiusTopRight;
539 std::optional<Dimension> radiusBottomLeft;
540 std::optional<Dimension> radiusBottomRight;
541
542 SetOptionalBorderRadius(radiusTopLeft, values, valuesSize, offset);
543 SetOptionalBorderRadius(radiusTopRight, values, valuesSize, offset);
544 SetOptionalBorderRadius(radiusBottomLeft, values, valuesSize, offset);
545 SetOptionalBorderRadius(radiusBottomRight, values, valuesSize, offset);
546 ButtonModelNG::SetBorderRadius(frameNode, radiusTopLeft, radiusTopRight, radiusBottomLeft, radiusBottomRight);
547 }
548
ResetButtonBorderRadius(ArkUINodeHandle node)549 void ResetButtonBorderRadius(ArkUINodeHandle node)
550 {
551 auto* frameNode = reinterpret_cast<FrameNode*>(node);
552 CHECK_NULL_VOID(frameNode);
553 OHOS::Ace::Dimension reset;
554 ButtonModelNG::SetBorderRadius(frameNode, reset);
555 }
556
SetButtonSize(ArkUINodeHandle node,ArkUI_CharPtr widthValue,int32_t widthUnit,ArkUI_CharPtr heightValue,int32_t heightUnit)557 void SetButtonSize(
558 ArkUINodeHandle node, ArkUI_CharPtr widthValue, int32_t widthUnit, ArkUI_CharPtr heightValue, int32_t heightUnit)
559 {
560 auto* frameNode = reinterpret_cast<FrameNode*>(node);
561 CHECK_NULL_VOID(frameNode);
562 std::string widthValueStr = std::string(widthValue);
563 std::string heightValueStr = std::string(heightValue);
564 std::optional<CalcDimension> widthInfo;
565 std::optional<CalcDimension> heightInfo;
566 if (widthValueStr != "undefined") {
567 widthInfo = CalcDimension(StringUtils::StringToDouble(widthValueStr), (DimensionUnit)widthUnit);
568 } else {
569 ViewAbstract::ClearWidthOrHeight(frameNode, true);
570 }
571 if (heightValueStr != "undefined") {
572 heightInfo = CalcDimension(StringUtils::StringToDouble(heightValueStr), (DimensionUnit)heightUnit);
573 } else {
574 ViewAbstract::ClearWidthOrHeight(frameNode, false);
575 }
576 ButtonModelNG::SetSize(frameNode, widthInfo, heightInfo);
577 }
578
ResetButtonSize(ArkUINodeHandle node)579 void ResetButtonSize(ArkUINodeHandle node)
580 {
581 auto* frameNode = reinterpret_cast<FrameNode*>(node);
582 CHECK_NULL_VOID(frameNode);
583 ViewAbstract::ClearWidthOrHeight(frameNode, true);
584 ViewAbstract::ClearWidthOrHeight(frameNode, false);
585 }
586
GetButtonLabel(ArkUINodeHandle node)587 ArkUI_CharPtr GetButtonLabel(ArkUINodeHandle node)
588 {
589 auto *frameNode = reinterpret_cast<FrameNode *>(node);
590 CHECK_NULL_RETURN(frameNode, "");
591 g_strValue = ButtonModelNG::GetLabel(frameNode);
592 return g_strValue.c_str();
593 }
594
GetButtonFontSize(ArkUINodeHandle node,ArkUI_Int32 unit)595 ArkUI_Float32 GetButtonFontSize(ArkUINodeHandle node, ArkUI_Int32 unit)
596 {
597 auto *frameNode = reinterpret_cast<FrameNode *>(node);
598 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
599 return ButtonModelNG::GetFontSize(frameNode).GetNativeValue(static_cast<DimensionUnit>(unit));
600 }
601
GetButtonFontWeight(ArkUINodeHandle node)602 ArkUI_Int32 GetButtonFontWeight(ArkUINodeHandle node)
603 {
604 auto *frameNode = reinterpret_cast<FrameNode *>(node);
605 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
606 return static_cast<ArkUI_Int32>(ButtonModelNG::GetFontWeight(frameNode));
607 }
608
GetButtonFontColor(ArkUINodeHandle node)609 ArkUI_Uint32 GetButtonFontColor(ArkUINodeHandle node)
610 {
611 auto *frameNode = reinterpret_cast<FrameNode *>(node);
612 CHECK_NULL_RETURN(frameNode, ERROR_UINT_CODE);
613 return ButtonModelNG::GetFontColor(frameNode).GetValue();
614 }
615
SetButtonRole(ArkUINodeHandle node,ArkUI_Uint32 buttonRole)616 void SetButtonRole(ArkUINodeHandle node, ArkUI_Uint32 buttonRole)
617 {
618 auto* frameNode = reinterpret_cast<FrameNode*>(node);
619 CHECK_NULL_VOID(frameNode);
620 ButtonRole role = ButtonRole::NORMAL;
621 if (buttonRole >= static_cast<uint32_t>(ButtonRole::NORMAL) && buttonRole <=
622 static_cast<uint32_t>(ButtonRole::ERROR)) {
623 role = static_cast<ButtonRole>(buttonRole);
624 }
625 ButtonModelNG::SetRole(frameNode, role);
626 }
627
ResetButtonRole(ArkUINodeHandle node)628 void ResetButtonRole(ArkUINodeHandle node)
629 {
630 auto* frameNode = reinterpret_cast<FrameNode*>(node);
631 CHECK_NULL_VOID(frameNode);
632 ButtonModelNG::SetRole(frameNode, ButtonRole::NORMAL);
633 }
634
SetButtonStyle(ArkUINodeHandle node,ArkUI_Uint32 buttonStyle)635 void SetButtonStyle(ArkUINodeHandle node, ArkUI_Uint32 buttonStyle)
636 {
637 auto* frameNode = reinterpret_cast<FrameNode*>(node);
638 CHECK_NULL_VOID(frameNode);
639 ButtonStyleMode style = ButtonStyleMode::EMPHASIZE;
640 if (buttonStyle >= static_cast<uint32_t>(ButtonStyleMode::NORMAL) && buttonStyle <=
641 static_cast<uint32_t>(ButtonStyleMode::TEXT)) {
642 style = static_cast<ButtonStyleMode>(buttonStyle);
643 }
644 ButtonModelNG::SetButtonStyle(frameNode, style);
645 }
646
ResetButtonStyle(ArkUINodeHandle node)647 void ResetButtonStyle(ArkUINodeHandle node)
648 {
649 auto* frameNode = reinterpret_cast<FrameNode*>(node);
650 CHECK_NULL_VOID(frameNode);
651 ButtonModelNG::SetButtonStyle(frameNode, ButtonStyleMode::EMPHASIZE);
652 }
653
SetButtonControlSize(ArkUINodeHandle node,ArkUI_Uint32 controlSize)654 void SetButtonControlSize(ArkUINodeHandle node, ArkUI_Uint32 controlSize)
655 {
656 auto* frameNode = reinterpret_cast<FrameNode*>(node);
657 CHECK_NULL_VOID(frameNode);
658 ControlSize size = ControlSize::NORMAL;
659 if (controlSize >= static_cast<uint32_t>(ControlSize::SMALL) && controlSize <=
660 static_cast<uint32_t>(ControlSize::NORMAL)) {
661 size = static_cast<ControlSize>(controlSize);
662 }
663 ButtonModelNG::SetControlSize(frameNode, size);
664 }
665
ResetButtonControlSize(ArkUINodeHandle node)666 void ResetButtonControlSize(ArkUINodeHandle node)
667 {
668 auto* frameNode = reinterpret_cast<FrameNode*>(node);
669 CHECK_NULL_VOID(frameNode);
670 ButtonModelNG::SetControlSize(frameNode, ControlSize::NORMAL);
671 }
672
GetButtonType(ArkUINodeHandle node)673 ArkUI_Int32 GetButtonType(ArkUINodeHandle node)
674 {
675 auto* frameNode = reinterpret_cast<FrameNode*>(node);
676 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
677 return static_cast<ArkUI_Int32>(ButtonModelNG::GetType(frameNode));
678 }
679
SetButtonLabelWithCheck(ArkUINodeHandle node,ArkUI_CharPtr value)680 void SetButtonLabelWithCheck(ArkUINodeHandle node, ArkUI_CharPtr value)
681 {
682 auto* frameNode = reinterpret_cast<FrameNode*>(node);
683 CHECK_NULL_VOID(frameNode);
684 ButtonModelNG::SetLabelWithCheck(frameNode, value);
685 }
686
ResetButtonLabelWithCheck(ArkUINodeHandle node)687 void ResetButtonLabelWithCheck(ArkUINodeHandle node)
688 {
689 auto* frameNode = reinterpret_cast<FrameNode*>(node);
690 CHECK_NULL_VOID(frameNode);
691 ButtonModelNG::SetLabelWithCheck(frameNode, "");
692 }
693
SetButtonOptions(ArkUINodeHandle node,ArkUI_Uint32 buttonStyle,ArkUI_Uint32 buttonRole)694 void SetButtonOptions(ArkUINodeHandle node, ArkUI_Uint32 buttonStyle, ArkUI_Uint32 buttonRole)
695 {
696 auto* frameNode = reinterpret_cast<FrameNode*>(node);
697 CHECK_NULL_VOID(frameNode);
698 ButtonStyleMode style = ButtonStyleMode::EMPHASIZE;
699 if (buttonStyle >= static_cast<uint32_t>(ButtonStyleMode::NORMAL) && buttonStyle <=
700 static_cast<uint32_t>(ButtonStyleMode::TEXT)) {
701 style = static_cast<ButtonStyleMode>(buttonStyle);
702 }
703 ButtonRole role = ButtonRole::NORMAL;
704 if (buttonRole >= static_cast<uint32_t>(ButtonRole::NORMAL) && buttonRole <=
705 static_cast<uint32_t>(ButtonRole::ERROR)) {
706 role = static_cast<ButtonRole>(buttonRole);
707 }
708 ButtonModelNG::ApplyTheme(frameNode, style, role);
709 }
710
ResetButtonOptions(ArkUINodeHandle node)711 void ResetButtonOptions(ArkUINodeHandle node)
712 {
713 auto* frameNode = reinterpret_cast<FrameNode*>(node);
714 CHECK_NULL_VOID(frameNode);
715 if (frameNode->GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) {
716 ButtonModelNG::SetType(frameNode, DEFAULT_BUTTON_TYPE_VERSION_EIGHTEEN);
717 } else {
718 ButtonModelNG::SetType(frameNode, DEFAULT_BUTTON_TYPE);
719 }
720 ButtonModelNG::SetStateEffect(frameNode, DEFAULT_STATE_EFFECT);
721 ButtonModelNG::SetButtonStyle(frameNode, ButtonStyleMode::EMPHASIZE);
722 ButtonModelNG::SetControlSize(frameNode, ControlSize::NORMAL);
723 ButtonModelNG::SetRole(frameNode, ButtonRole::NORMAL);
724 }
725
SetCreateWithLabel(ArkUINodeHandle node,bool createWithLabel)726 void SetCreateWithLabel(ArkUINodeHandle node, bool createWithLabel)
727 {
728 auto* frameNode = reinterpret_cast<FrameNode*>(node);
729 CHECK_NULL_VOID(frameNode);
730 ButtonModelNG::SetCreateWithLabel(frameNode, createWithLabel);
731 }
732
SetButtonMinFontScale(ArkUINodeHandle node,ArkUI_Float32 minFontScale)733 void SetButtonMinFontScale(ArkUINodeHandle node, ArkUI_Float32 minFontScale)
734 {
735 auto* frameNode = reinterpret_cast<FrameNode*>(node);
736 CHECK_NULL_VOID(frameNode);
737 ButtonModelNG::SetMinFontScale(frameNode, minFontScale);
738 }
739
SetButtonMinFontScalePtr(ArkUINodeHandle node,ArkUI_Float32 minFontScale,void * scaleRawPtr)740 void SetButtonMinFontScalePtr(ArkUINodeHandle node, ArkUI_Float32 minFontScale, void* scaleRawPtr)
741 {
742 CHECK_NULL_VOID(node);
743 SetButtonMinFontScale(node, minFontScale);
744 if (SystemProperties::ConfigChangePerform()) {
745 auto* frameNode = reinterpret_cast<FrameNode*>(node);
746 CHECK_NULL_VOID(frameNode);
747 auto* scaleValue = reinterpret_cast<ResourceObject*>(scaleRawPtr);
748 auto scaleResObj = AceType::Claim(scaleValue);
749 ButtonModelNG::CreateWithDoubleResourceObj(frameNode, scaleResObj, ButtonDoubleType::MIN_FONT_SCALE);
750 }
751 }
752
ResetButtonMinFontScale(ArkUINodeHandle node)753 void ResetButtonMinFontScale(ArkUINodeHandle node)
754 {
755 auto* frameNode = reinterpret_cast<FrameNode*>(node);
756 CHECK_NULL_VOID(frameNode);
757 ButtonModelNG::SetMinFontScale(frameNode, DEFAULT_MIN_FONT_SCALE);
758 if (SystemProperties::ConfigChangePerform()) {
759 ButtonModelNG::CreateWithDoubleResourceObj(frameNode, nullptr, ButtonDoubleType::MIN_FONT_SCALE);
760 }
761 }
762
SetButtonMaxFontScale(ArkUINodeHandle node,ArkUI_Float32 maxFontScale)763 void SetButtonMaxFontScale(ArkUINodeHandle node, ArkUI_Float32 maxFontScale)
764 {
765 auto* frameNode = reinterpret_cast<FrameNode*>(node);
766 CHECK_NULL_VOID(frameNode);
767 ButtonModelNG::SetMaxFontScale(frameNode, maxFontScale);
768 }
769
SetButtonMaxFontScalePtr(ArkUINodeHandle node,ArkUI_Float32 maxFontScale,void * scaleRawPtr)770 void SetButtonMaxFontScalePtr(ArkUINodeHandle node, ArkUI_Float32 maxFontScale, void* scaleRawPtr)
771 {
772 CHECK_NULL_VOID(node);
773 SetButtonMaxFontScale(node, maxFontScale);
774 if (SystemProperties::ConfigChangePerform()) {
775 auto* frameNode = reinterpret_cast<FrameNode*>(node);
776 CHECK_NULL_VOID(frameNode);
777 auto* scaleValue = reinterpret_cast<ResourceObject*>(scaleRawPtr);
778 auto scaleResObj = AceType::Claim(scaleValue);
779 ButtonModelNG::CreateWithDoubleResourceObj(frameNode, scaleResObj, ButtonDoubleType::MAX_FONT_SCALE);
780 }
781 }
782
ResetButtonMaxFontScale(ArkUINodeHandle node)783 void ResetButtonMaxFontScale(ArkUINodeHandle node)
784 {
785 auto* frameNode = reinterpret_cast<FrameNode*>(node);
786 CHECK_NULL_VOID(frameNode);
787 ButtonModelNG::SetMaxFontScale(frameNode, DEFAULT_MAX_FONT_SCALE);
788 if (SystemProperties::ConfigChangePerform()) {
789 ButtonModelNG::CreateWithDoubleResourceObj(frameNode, nullptr, ButtonDoubleType::MAX_FONT_SCALE);
790 }
791 }
792
GetButtonMinFontScale(ArkUINodeHandle node)793 ArkUI_Float32 GetButtonMinFontScale(ArkUINodeHandle node)
794 {
795 auto *frameNode = reinterpret_cast<FrameNode *>(node);
796 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
797 return static_cast<ArkUI_Float32>(ButtonModelNG::GetMinFontScale(frameNode));
798 }
799
GetButtonMaxFontScale(ArkUINodeHandle node)800 ArkUI_Float32 GetButtonMaxFontScale(ArkUINodeHandle node)
801 {
802 auto *frameNode = reinterpret_cast<FrameNode *>(node);
803 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
804 return static_cast<ArkUI_Float32>(ButtonModelNG::GetMaxFontScale(frameNode));
805 }
806
807 namespace NodeModifier {
GetButtonModifier()808 const ArkUIButtonModifier* GetButtonModifier()
809 {
810 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
811 static const ArkUIButtonModifier modifier = {
812 .setButtonLabel = SetButtonLabel,
813 .resetButtonLabel = ResetButtonLabel,
814 .setButtonType = SetButtonType,
815 .resetButtonType = ResetButtonType,
816 .setButtonStateEffect = SetButtonStateEffect,
817 .resetButtonStateEffect = ResetButtonStateEffect,
818 .setButtonFontColor = SetButtonFontColor,
819 .resetButtonFontColor = ResetButtonFontColor,
820 .setButtonFontSize = SetButtonFontSize,
821 .resetButtonFontSize = ResetButtonFontSize,
822 .setButtonFontWeight = SetButtonFontWeight,
823 .resetButtonFontWeight = ResetButtonFontWeight,
824 .setButtonFontStyle = SetButtonFontStyle,
825 .resetButtonFontStyle = ResetButtonFontStyle,
826 .setButtonFontFamily = SetButtonFontFamily,
827 .resetButtonFontFamily = ResetButtonFontFamily,
828 .setButtonLabelStyle = SetButtonLabelStyle,
829 .resetButtonLabelStyle = ResetButtonLabelStyle,
830 .setButtonBackgroundColor = SetButtonBackgroundColor,
831 .setButtonBackgroundColorWithColorSpace = SetButtonBackgroundColorWithColorSpace,
832 .resetButtonBackgroundColor = ResetButtonBackgroundColor,
833 .setButtonBorderRadius = SetButtonBorderRadius,
834 .resetButtonBorderRadius = ResetButtonBorderRadius,
835 .setButtonFontWeightEnum = SetButtonFontWeightEnum,
836 .setButtonSize = SetButtonSize,
837 .resetButtonSize = ResetButtonSize,
838 .getButtonLabel = GetButtonLabel,
839 .getButtonFontSize = GetButtonFontSize,
840 .getButtonFontWeight = GetButtonFontWeight,
841 .getButtonFontColor = GetButtonFontColor,
842 .setButtonRole = SetButtonRole,
843 .resetButtonRole = ResetButtonRole,
844 .setButtonStyle = SetButtonStyle,
845 .resetButtonStyle = ResetButtonStyle,
846 .setButtonControlSize = SetButtonControlSize,
847 .resetButtonControlSize = ResetButtonControlSize,
848 .getButtonType = GetButtonType,
849 .setButtonLabelWithCheck = SetButtonLabelWithCheck,
850 .resetButtonLabelWithCheck = ResetButtonLabelWithCheck,
851 .setButtonOptions = SetButtonOptions,
852 .resetButtonOptions = ResetButtonOptions,
853 .setCreateWithLabel = SetCreateWithLabel,
854 .setButtonMinFontScale = SetButtonMinFontScale,
855 .resetButtonMinFontScale = ResetButtonMinFontScale,
856 .setButtonMaxFontScale = SetButtonMaxFontScale,
857 .resetButtonMaxFontScale = ResetButtonMaxFontScale,
858 .getButtonMinFontScale = GetButtonMinFontScale,
859 .getButtonMaxFontScale = GetButtonMaxFontScale,
860 .setButtonFontColorPtr = SetButtonFontColorPtr,
861 .setButtonFontFamilyPtr = SetButtonFontFamilyPtr,
862 .setButtonLabelStylePtr = SetButtonLabelStylePtr,
863 .setButtonBackgroundColorWithColorSpacePtr = SetButtonBackgroundColorWithColorSpacePtr,
864 .setButtonMinFontScalePtr = SetButtonMinFontScalePtr,
865 .setButtonMaxFontScalePtr = SetButtonMaxFontScalePtr,
866 };
867 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
868 return &modifier;
869 }
870
GetCJUIButtonModifier()871 const CJUIButtonModifier* GetCJUIButtonModifier()
872 {
873 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
874 static const CJUIButtonModifier modifier = {
875 .setButtonLabel = SetButtonLabel,
876 .resetButtonLabel = ResetButtonLabel,
877 .setButtonType = SetButtonType,
878 .resetButtonType = ResetButtonType,
879 .setButtonStateEffect = SetButtonStateEffect,
880 .resetButtonStateEffect = ResetButtonStateEffect,
881 .setButtonFontColor = SetButtonFontColor,
882 .resetButtonFontColor = ResetButtonFontColor,
883 .setButtonFontSize = SetButtonFontSize,
884 .resetButtonFontSize = ResetButtonFontSize,
885 .setButtonFontWeight = SetButtonFontWeight,
886 .resetButtonFontWeight = ResetButtonFontWeight,
887 .setButtonFontStyle = SetButtonFontStyle,
888 .resetButtonFontStyle = ResetButtonFontStyle,
889 .setButtonFontFamily = SetButtonFontFamily,
890 .resetButtonFontFamily = ResetButtonFontFamily,
891 .setButtonLabelStyle = SetButtonLabelStyle,
892 .resetButtonLabelStyle = ResetButtonLabelStyle,
893 .setButtonBackgroundColor = SetButtonBackgroundColor,
894 .setButtonBackgroundColorWithColorSpace = SetButtonBackgroundColorWithColorSpace,
895 .resetButtonBackgroundColor = ResetButtonBackgroundColor,
896 .setButtonBorderRadius = SetButtonBorderRadius,
897 .resetButtonBorderRadius = ResetButtonBorderRadius,
898 .setButtonFontWeightEnum = SetButtonFontWeightEnum,
899 .setButtonSize = SetButtonSize,
900 .resetButtonSize = ResetButtonSize,
901 .getButtonLabel = GetButtonLabel,
902 .getButtonFontSize = GetButtonFontSize,
903 .getButtonFontWeight = GetButtonFontWeight,
904 .getButtonFontColor = GetButtonFontColor,
905 .setButtonRole = SetButtonRole,
906 .resetButtonRole = ResetButtonRole,
907 .setButtonStyle = SetButtonStyle,
908 .resetButtonStyle = ResetButtonStyle,
909 .setButtonControlSize = SetButtonControlSize,
910 .resetButtonControlSize = ResetButtonControlSize,
911 .getButtonType = GetButtonType,
912 .setButtonLabelWithCheck = SetButtonLabelWithCheck,
913 .resetButtonLabelWithCheck = ResetButtonLabelWithCheck,
914 .setButtonOptions = SetButtonOptions,
915 .resetButtonOptions = ResetButtonOptions,
916 .setCreateWithLabel = SetCreateWithLabel,
917 .setButtonMinFontScale = SetButtonMinFontScale,
918 .resetButtonMinFontScale = ResetButtonMinFontScale,
919 .setButtonMaxFontScale = SetButtonMaxFontScale,
920 .resetButtonMaxFontScale = ResetButtonMaxFontScale,
921 .getButtonMinFontScale = GetButtonMinFontScale,
922 .getButtonMaxFontScale = GetButtonMaxFontScale,
923 };
924 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
925 return &modifier;
926 }
927 } // namespace NodeModifier
928 } // namespace OHOS::Ace::NG
929