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/node_slider_modifier.h"
16
17 #include "core/components_ng/pattern/slider/slider_model_ng.h"
18 #include "core/components/slider/slider_theme.h"
19 #include "core/pipeline_ng/pipeline_context.h"
20
21 namespace OHOS::Ace::NG {
22 const bool DEFAULT_SHOW_STEPS = false;
23 const bool DEFAULT_SHOW_TIPS = false;
24 const std::vector<SliderModel::SliderMode> SLIDER_MODE = { SliderModel::SliderMode::OUTSET,
25 SliderModel::SliderMode::INSET, SliderModel::SliderMode::NONE, SliderModel::SliderMode::CAPSULE, };
26 const std::vector<SliderModel::BlockStyleType> SLIDER_STYLE_TYPE = { SliderModel::BlockStyleType::DEFAULT,
27 SliderModel::BlockStyleType::IMAGE, SliderModel::BlockStyleType::SHAPE };
28 std::map<SliderModel::SliderMode, int> SLIDER_MODE_MAP = {
29 { SliderModel::SliderMode::OUTSET, 0 },
30 { SliderModel::SliderMode::INSET, 1 },
31 { SliderModel::SliderMode::NONE, 2 },
32 { SliderModel::SliderMode::CAPSULE, 3 } };
33 std::map<SliderModel::BlockStyleType, int> SLIDER_STYLE_TYPE_MAP = {
34 { SliderModel::BlockStyleType::DEFAULT, 0 },
35 { SliderModel::BlockStyleType::IMAGE, 1 },
36 { SliderModel::BlockStyleType::SHAPE, 2 } };
37
38 std::map<BasicShapeType, int> SHAPE_TYPE_MAP = {
39 { BasicShapeType::RECT, 0 },
40 { BasicShapeType::CIRCLE, 1 },
41 { BasicShapeType::ELLIPSE, 2 },
42 { BasicShapeType::PATH, 3 } };
43
44 const float DEFAULT_VALUE = 0.0;
45 const float DEFAULT_MAX_VALUE = 100.0;
46 const float DEFAULT_MIN_VALUE = 0.0;
47 const float DEFAULT_STEP_VALUE = 1.0;
48
49 const uint32_t ERROR_UINT_CODE = -1;
50 const float ERROR_FLOAT_CODE = -1.0f;
51 const int32_t ERROR_INT_CODE = -1;
52 namespace SliderModifier {
53
54 std::string g_strValue;
55
SetShowTips(ArkUINodeHandle node,ArkUI_Bool isShow,const char * value)56 void SetShowTips(ArkUINodeHandle node, ArkUI_Bool isShow, const char *value)
57 {
58 auto *frameNode = reinterpret_cast<FrameNode *>(node);
59 CHECK_NULL_VOID(frameNode);
60 std::optional<std::string> content;
61
62 if (value == nullptr) {
63 content = std::nullopt;
64 } else {
65 content = std::string(value);
66 }
67 SliderModelNG::SetShowTips(frameNode, static_cast<bool>(isShow), content);
68 }
69
ResetShowTips(ArkUINodeHandle node)70 void ResetShowTips(ArkUINodeHandle node)
71 {
72 auto *frameNode = reinterpret_cast<FrameNode *>(node);
73 CHECK_NULL_VOID(frameNode);
74 std::optional<std::string> content;
75 SliderModelNG::SetShowTips(frameNode, DEFAULT_SHOW_TIPS, content);
76 }
77
SetSliderStepSize(ArkUINodeHandle node,ArkUI_Float32 value,int unit)78 void SetSliderStepSize(ArkUINodeHandle node, ArkUI_Float32 value, int unit)
79 {
80 auto *frameNode = reinterpret_cast<FrameNode *>(node);
81 CHECK_NULL_VOID(frameNode);
82 Dimension size = Dimension(static_cast<double>(value),
83 static_cast<OHOS::Ace::DimensionUnit>(unit));
84 SliderModelNG::SetStepSize(frameNode, size);
85 }
86
ResetSliderStepSize(ArkUINodeHandle node)87 void ResetSliderStepSize(ArkUINodeHandle node)
88 {
89 auto *frameNode = reinterpret_cast<FrameNode *>(node);
90 CHECK_NULL_VOID(frameNode);
91
92 auto pipelineContext = frameNode->GetContext();
93 CHECK_NULL_VOID(pipelineContext);
94 auto theme = pipelineContext->GetTheme<SliderTheme>();
95
96 Dimension stepSize = theme->GetMarkerSize();
97 SliderModelNG::SetStepSize(frameNode, stepSize);
98 }
99
SetBlockSize(ArkUINodeHandle node,ArkUI_Float32 widthVal,int widthUnit,ArkUI_Float32 heightVal,int heightUnit)100 void SetBlockSize(ArkUINodeHandle node, ArkUI_Float32 widthVal,
101 int widthUnit, ArkUI_Float32 heightVal, int heightUnit)
102 {
103 auto *frameNode = reinterpret_cast<FrameNode *>(node);
104 CHECK_NULL_VOID(frameNode);
105 Dimension blockWidth = Dimension(static_cast<double>(widthVal),
106 static_cast<OHOS::Ace::DimensionUnit>(widthUnit));
107 Dimension blockHeight = Dimension(static_cast<double>(heightVal),
108 static_cast<OHOS::Ace::DimensionUnit>(heightUnit));
109
110 if (LessNotEqual(blockWidth.Value(), 0.0)) {
111 blockWidth.SetValue(0.0);
112 }
113 if (LessNotEqual(blockHeight.Value(), 0.0)) {
114 blockHeight.SetValue(0.0);
115 }
116 SliderModelNG::SetBlockSize(frameNode, blockWidth, blockHeight);
117 }
118
ResetBlockSize(ArkUINodeHandle node)119 void ResetBlockSize(ArkUINodeHandle node)
120 {
121 auto *frameNode = reinterpret_cast<FrameNode *>(node);
122 CHECK_NULL_VOID(frameNode);
123 SliderModelNG::ResetBlockSize(frameNode);
124 }
125
SetTrackBorderRadius(ArkUINodeHandle node,float value,int unit)126 void SetTrackBorderRadius(ArkUINodeHandle node, float value, int unit)
127 {
128 auto *frameNode = reinterpret_cast<FrameNode *>(node);
129 CHECK_NULL_VOID(frameNode);
130 Dimension radius =
131 Dimension(static_cast<double>(value), static_cast<OHOS::Ace::DimensionUnit>(unit));
132 SliderModelNG::SetTrackBorderRadius(frameNode, radius);
133 }
134
ResetTrackBorderRadius(ArkUINodeHandle node)135 void ResetTrackBorderRadius(ArkUINodeHandle node)
136 {
137 auto *frameNode = reinterpret_cast<FrameNode *>(node);
138 CHECK_NULL_VOID(frameNode);
139 SliderModelNG::ResetTrackBorderRadius(frameNode);
140 }
141
SetStepColor(ArkUINodeHandle node,uint32_t color)142 void SetStepColor(ArkUINodeHandle node, uint32_t color)
143 {
144 auto *frameNode = reinterpret_cast<FrameNode *>(node);
145 CHECK_NULL_VOID(frameNode);
146 SliderModelNG::SetStepColor(frameNode, Color(color));
147 }
148
ResetStepColor(ArkUINodeHandle node)149 void ResetStepColor(ArkUINodeHandle node)
150 {
151 auto *frameNode = reinterpret_cast<FrameNode *>(node);
152 CHECK_NULL_VOID(frameNode);
153 SliderModelNG::ResetStepColor(frameNode);
154 }
155
SetBlockBorderColor(ArkUINodeHandle node,uint32_t color)156 void SetBlockBorderColor(ArkUINodeHandle node, uint32_t color)
157 {
158 auto *frameNode = reinterpret_cast<FrameNode *>(node);
159 CHECK_NULL_VOID(frameNode);
160 SliderModelNG::SetBlockBorderColor(frameNode, Color(color));
161 }
162
ResetBlockBorderColor(ArkUINodeHandle node)163 void ResetBlockBorderColor(ArkUINodeHandle node)
164 {
165 auto *frameNode = reinterpret_cast<FrameNode *>(node);
166 CHECK_NULL_VOID(frameNode);
167 SliderModelNG::ResetBlockBorderColor(frameNode);
168 }
169
SetBlockBorderWidth(ArkUINodeHandle node,ArkUI_Float32 value,int unit)170 void SetBlockBorderWidth(ArkUINodeHandle node, ArkUI_Float32 value, int unit)
171 {
172 auto *frameNode = reinterpret_cast<FrameNode *>(node);
173 CHECK_NULL_VOID(frameNode);
174 Dimension width =
175 Dimension(static_cast<double>(value), static_cast<OHOS::Ace::DimensionUnit>(unit));
176 SliderModelNG::SetBlockBorderWidth(frameNode, width);
177 }
178
ResetBlockBorderWidth(ArkUINodeHandle node)179 void ResetBlockBorderWidth(ArkUINodeHandle node)
180 {
181 auto *frameNode = reinterpret_cast<FrameNode *>(node);
182 CHECK_NULL_VOID(frameNode);
183 SliderModelNG::ResetBlockBorderWidth(frameNode);
184 }
185
SetBlockColor(ArkUINodeHandle node,uint32_t color)186 void SetBlockColor(ArkUINodeHandle node, uint32_t color)
187 {
188 auto *frameNode = reinterpret_cast<FrameNode *>(node);
189 CHECK_NULL_VOID(frameNode);
190 SliderModelNG::SetBlockColor(frameNode, Color(color));
191 }
192
ResetBlockColor(ArkUINodeHandle node)193 void ResetBlockColor(ArkUINodeHandle node)
194 {
195 auto *frameNode = reinterpret_cast<FrameNode *>(node);
196 CHECK_NULL_VOID(frameNode);
197 SliderModelNG::ResetBlockColor(frameNode);
198 }
199
SetTrackBackgroundColor(ArkUINodeHandle node,uint32_t color)200 void SetTrackBackgroundColor(ArkUINodeHandle node, uint32_t color)
201 {
202 auto *frameNode = reinterpret_cast<FrameNode *>(node);
203 CHECK_NULL_VOID(frameNode);
204 SliderModelNG::SetTrackBackgroundColor(frameNode, SliderModelNG::CreateSolidGradient(Color(color)), true);
205 }
206
ResetTrackBackgroundColor(ArkUINodeHandle node)207 void ResetTrackBackgroundColor(ArkUINodeHandle node)
208 {
209 auto *frameNode = reinterpret_cast<FrameNode *>(node);
210 CHECK_NULL_VOID(frameNode);
211 auto pipelineContext = frameNode->GetContext();
212 CHECK_NULL_VOID(pipelineContext);
213 auto theme = pipelineContext->GetTheme<SliderTheme>();
214 CHECK_NULL_VOID(theme);
215
216 SliderModelNG::SetTrackBackgroundColor(
217 frameNode, SliderModelNG::CreateSolidGradient(theme->GetTrackBgColor()), true);
218 }
219
SetSelectColor(ArkUINodeHandle node,uint32_t color)220 void SetSelectColor(ArkUINodeHandle node, uint32_t color)
221 {
222 auto *frameNode = reinterpret_cast<FrameNode *>(node);
223 CHECK_NULL_VOID(frameNode);
224 SliderModelNG::SetSelectColor(frameNode, SliderModelNG::CreateSolidGradient(Color(color)), true);
225 }
226
ResetSelectColor(ArkUINodeHandle node)227 void ResetSelectColor(ArkUINodeHandle node)
228 {
229 auto *frameNode = reinterpret_cast<FrameNode *>(node);
230 CHECK_NULL_VOID(frameNode);
231 auto pipelineContext = frameNode->GetContext();
232 CHECK_NULL_VOID(pipelineContext);
233 auto theme = pipelineContext->GetTheme<SliderTheme>();
234 CHECK_NULL_VOID(theme);
235 SliderModelNG::SetSelectColor(
236 frameNode, SliderModelNG::CreateSolidGradient(theme->GetTrackSelectedColor()), true);
237 }
238
SetShowSteps(ArkUINodeHandle node,int showSteps)239 void SetShowSteps(ArkUINodeHandle node, int showSteps)
240 {
241 auto *frameNode = reinterpret_cast<FrameNode *>(node);
242 CHECK_NULL_VOID(frameNode);
243 SliderModelNG::SetShowSteps(frameNode, static_cast<bool>(showSteps));
244 }
245
ResetShowSteps(ArkUINodeHandle node)246 void ResetShowSteps(ArkUINodeHandle node)
247 {
248 auto *frameNode = reinterpret_cast<FrameNode *>(node);
249 CHECK_NULL_VOID(frameNode);
250 SliderModelNG::SetShowSteps(frameNode, DEFAULT_SHOW_STEPS);
251 }
252
SetThickness(ArkUINodeHandle node,ArkUI_Float32 value,int unit)253 void SetThickness(ArkUINodeHandle node, ArkUI_Float32 value, int unit)
254 {
255 auto *frameNode = reinterpret_cast<FrameNode *>(node);
256 CHECK_NULL_VOID(frameNode);
257 Dimension thickness =
258 Dimension(static_cast<double>(value), static_cast<OHOS::Ace::DimensionUnit>(unit));
259 SliderModelNG::SetThickness(frameNode, thickness);
260 }
261
ResetThickness(ArkUINodeHandle node)262 void ResetThickness(ArkUINodeHandle node)
263 {
264 auto *frameNode = reinterpret_cast<FrameNode *>(node);
265 CHECK_NULL_VOID(frameNode);
266 SliderModelNG::SetThickness(frameNode, CalcDimension(0.0));
267 }
268
SetSliderValue(ArkUINodeHandle node,float value)269 void SetSliderValue(ArkUINodeHandle node, float value)
270 {
271 auto *frameNode = reinterpret_cast<FrameNode *>(node);
272 CHECK_NULL_VOID(frameNode);
273 SliderModelNG::SetSliderValue(frameNode, value);
274 }
275
SetMinLabel(ArkUINodeHandle node,float value)276 void SetMinLabel(ArkUINodeHandle node, float value)
277 {
278 auto *frameNode = reinterpret_cast<FrameNode *>(node);
279 CHECK_NULL_VOID(frameNode);
280 SliderModelNG::SetMinLabel(frameNode, value);
281 }
282
SetMaxLabel(ArkUINodeHandle node,float value)283 void SetMaxLabel(ArkUINodeHandle node, float value)
284 {
285 auto *frameNode = reinterpret_cast<FrameNode *>(node);
286 CHECK_NULL_VOID(frameNode);
287 SliderModelNG::SetMaxLabel(frameNode, value);
288 }
289
SetDirection(ArkUINodeHandle node,int value)290 void SetDirection(ArkUINodeHandle node, int value)
291 {
292 auto *frameNode = reinterpret_cast<FrameNode *>(node);
293 CHECK_NULL_VOID(frameNode);
294 SliderModelNG::SetDirection(frameNode, static_cast<Axis>(value));
295 }
296
SetStep(ArkUINodeHandle node,float value)297 void SetStep(ArkUINodeHandle node, float value)
298 {
299 auto *frameNode = reinterpret_cast<FrameNode *>(node);
300 CHECK_NULL_VOID(frameNode);
301 SliderModelNG::SetStep(frameNode, value);
302 }
303
SetReverse(ArkUINodeHandle node,int value)304 void SetReverse(ArkUINodeHandle node, int value)
305 {
306 auto *frameNode = reinterpret_cast<FrameNode *>(node);
307 CHECK_NULL_VOID(frameNode);
308 SliderModelNG::SetReverse(frameNode, static_cast<bool>(value));
309 }
310
SetSliderStyle(ArkUINodeHandle node,int value)311 void SetSliderStyle(ArkUINodeHandle node, int value)
312 {
313 auto *frameNode = reinterpret_cast<FrameNode *>(node);
314 CHECK_NULL_VOID(frameNode);
315 if (value < 0 || value >= static_cast<int32_t>(SLIDER_MODE.size())) {
316 return;
317 }
318 SliderModelNG::SetSliderMode(frameNode, SLIDER_MODE[value]);
319 }
320
ResetSliderValue(ArkUINodeHandle node)321 void ResetSliderValue(ArkUINodeHandle node)
322 {
323 auto *frameNode = reinterpret_cast<FrameNode *>(node);
324 CHECK_NULL_VOID(frameNode);
325 SliderModelNG::SetSliderValue(frameNode, DEFAULT_VALUE);
326 }
327
ResetMinLabel(ArkUINodeHandle node)328 void ResetMinLabel(ArkUINodeHandle node)
329 {
330 auto *frameNode = reinterpret_cast<FrameNode *>(node);
331 CHECK_NULL_VOID(frameNode);
332 SliderModelNG::SetMinLabel(frameNode, DEFAULT_MIN_VALUE);
333 }
334
ResetMaxLabel(ArkUINodeHandle node)335 void ResetMaxLabel(ArkUINodeHandle node)
336 {
337 auto *frameNode = reinterpret_cast<FrameNode *>(node);
338 CHECK_NULL_VOID(frameNode);
339 SliderModelNG::SetMaxLabel(frameNode, DEFAULT_MAX_VALUE);
340 }
341
ResetDirection(ArkUINodeHandle node)342 void ResetDirection(ArkUINodeHandle node)
343 {
344 auto *frameNode = reinterpret_cast<FrameNode *>(node);
345 CHECK_NULL_VOID(frameNode);
346 SliderModelNG::SetDirection(frameNode, Axis::HORIZONTAL);
347 }
348
ResetStep(ArkUINodeHandle node)349 void ResetStep(ArkUINodeHandle node)
350 {
351 auto *frameNode = reinterpret_cast<FrameNode *>(node);
352 CHECK_NULL_VOID(frameNode);
353 SliderModelNG::SetStep(frameNode, DEFAULT_STEP_VALUE);
354 }
355
ResetReverse(ArkUINodeHandle node)356 void ResetReverse(ArkUINodeHandle node)
357 {
358 auto *frameNode = reinterpret_cast<FrameNode *>(node);
359 CHECK_NULL_VOID(frameNode);
360 SliderModelNG::SetReverse(frameNode, false);
361 }
362
ResetSliderStyle(ArkUINodeHandle node)363 void ResetSliderStyle(ArkUINodeHandle node)
364 {
365 auto *frameNode = reinterpret_cast<FrameNode *>(node);
366 CHECK_NULL_VOID(frameNode);
367 SliderModelNG::SetSliderMode(frameNode, SliderModel::SliderMode::OUTSET);
368 }
369
SetSliderBlockImage(ArkUINodeHandle node,const char * src,const char * bundle,const char * module)370 void SetSliderBlockImage(
371 ArkUINodeHandle node, const char* src, const char* bundle, const char* module)
372 {
373 auto* frameNode = reinterpret_cast<FrameNode*>(node);
374 CHECK_NULL_VOID(frameNode);
375 std::string srcStr(src);
376 std::string bundleStr(bundle);
377 std::string moduleStr(module);
378 SliderModelNG::SetBlockImage(frameNode, srcStr, bundleStr, moduleStr);
379 }
380
ResetSliderBlockImage(ArkUINodeHandle node)381 void ResetSliderBlockImage(ArkUINodeHandle node)
382 {
383 auto *frameNode = reinterpret_cast<FrameNode *>(node);
384 CHECK_NULL_VOID(frameNode);
385 SliderModelNG::ResetBlockImage(frameNode);
386 }
387
SetSliderBlockPath(ArkUINodeHandle node,const char * type,const ArkUI_Float32 (* attribute)[2],const char * commands)388 void SetSliderBlockPath(
389 ArkUINodeHandle node, const char* type, const ArkUI_Float32 (*attribute)[2], const char* commands)
390 {
391 auto* frameNode = reinterpret_cast<FrameNode*>(node);
392 CHECK_NULL_VOID(frameNode);
393 auto path = AceType::MakeRefPtr<Path>();
394 auto width = Dimension((*attribute)[0], static_cast<OHOS::Ace::DimensionUnit>(1));
395 auto height = Dimension((*attribute)[1], static_cast<OHOS::Ace::DimensionUnit>(1));
396 std::string pathCommands(commands);
397 path->SetWidth(width);
398 path->SetHeight(height);
399 path->SetValue(StringUtils::TrimStr(pathCommands));
400 SliderModelNG::SetBlockShape(frameNode, path);
401 }
402
SetSliderBlockShape(ArkUINodeHandle node,const char * type,const ArkUI_Float32 * attribute,int length)403 void SetSliderBlockShape(ArkUINodeHandle node, const char* type, const ArkUI_Float32* attribute, int length)
404 {
405 auto* frameNode = reinterpret_cast<FrameNode*>(node);
406 CHECK_NULL_VOID(frameNode);
407 if (std::strcmp(type, "rect") == 0) {
408 auto shape = AceType::MakeRefPtr<ShapeRect>();
409 // 0 width 1 height 2 radiusWith 3 radius Height
410 auto width = Dimension(attribute[0], static_cast<OHOS::Ace::DimensionUnit>(1));
411 auto height = Dimension(attribute[1], static_cast<OHOS::Ace::DimensionUnit>(1));
412 auto radiusWidth = Dimension(attribute[2], static_cast<OHOS::Ace::DimensionUnit>(1));
413 auto radiusHeight = Dimension(attribute[3], static_cast<OHOS::Ace::DimensionUnit>(1));
414 shape->SetWidth(width);
415 shape->SetHeight(height);
416 shape->SetRadiusWidth(radiusWidth);
417 shape->SetRadiusHeight(radiusHeight);
418 SliderModelNG::SetBlockShape(frameNode, shape);
419 }
420 if (std::strcmp(type, "circle") == 0) {
421 auto shape = AceType::MakeRefPtr<Circle>();
422 // 0 width 1 height
423 auto width = Dimension(attribute[0], static_cast<OHOS::Ace::DimensionUnit>(1));
424 auto height = Dimension(attribute[1], static_cast<OHOS::Ace::DimensionUnit>(1));
425 shape->SetWidth(width);
426 shape->SetHeight(height);
427 SliderModelNG::SetBlockShape(frameNode, shape);
428 }
429 if (std::strcmp(type, "ellipse") == 0) {
430 auto shape = AceType::MakeRefPtr<Ellipse>();
431 // 0 width 1 height
432 auto width = Dimension(attribute[0], static_cast<OHOS::Ace::DimensionUnit>(1));
433 auto height = Dimension(attribute[1], static_cast<OHOS::Ace::DimensionUnit>(1));
434 shape->SetWidth(width);
435 shape->SetHeight(height);
436 SliderModelNG::SetBlockShape(frameNode, shape);
437 }
438 }
439
ResetSliderBlockShape(ArkUINodeHandle node)440 void ResetSliderBlockShape(ArkUINodeHandle node)
441 {
442 auto *frameNode = reinterpret_cast<FrameNode *>(node);
443 CHECK_NULL_VOID(frameNode);
444 SliderModelNG::ResetBlockImage(frameNode);
445 }
446
SetSliderBlockType(ArkUINodeHandle node,int value)447 void SetSliderBlockType(ArkUINodeHandle node, int value)
448 {
449 auto *frameNode = reinterpret_cast<FrameNode *>(node);
450 CHECK_NULL_VOID(frameNode);
451 if (value < 0 || value >= static_cast<int32_t>(SLIDER_STYLE_TYPE.size())) {
452 return;
453 }
454 SliderModelNG::SetBlockType(frameNode, SLIDER_STYLE_TYPE[value]);
455 }
456
ResetSliderBlockType(ArkUINodeHandle node)457 void ResetSliderBlockType(ArkUINodeHandle node)
458 {
459 auto *frameNode = reinterpret_cast<FrameNode *>(node);
460 CHECK_NULL_VOID(frameNode);
461 SliderModelNG::ResetBlockType(frameNode);
462 }
463
SetSliderValidSlideRange(ArkUINodeHandle node,float from,float to)464 void SetSliderValidSlideRange(ArkUINodeHandle node, float from, float to)
465 {
466 auto *frameNode = reinterpret_cast<FrameNode *>(node);
467 CHECK_NULL_VOID(frameNode);
468 SliderModelNG::SetValidSlideRange(frameNode, from, to);
469 }
470
ResetSliderValidSlideRange(ArkUINodeHandle node)471 void ResetSliderValidSlideRange(ArkUINodeHandle node)
472 {
473 auto *frameNode = reinterpret_cast<FrameNode *>(node);
474 CHECK_NULL_VOID(frameNode);
475 SliderModelNG::ResetValidSlideRange(frameNode);
476 }
477
SetSelectedBorderRadius(ArkUINodeHandle node,float value,int unit)478 void SetSelectedBorderRadius(ArkUINodeHandle node, float value, int unit)
479 {
480 auto* frameNode = reinterpret_cast<FrameNode*>(node);
481 CHECK_NULL_VOID(frameNode);
482 Dimension radius = Dimension(static_cast<double>(value), static_cast<OHOS::Ace::DimensionUnit>(unit));
483 SliderModelNG::SetSelectedBorderRadius(frameNode, radius);
484 }
485
ResetSelectedBorderRadius(ArkUINodeHandle node)486 void ResetSelectedBorderRadius(ArkUINodeHandle node)
487 {
488 auto* frameNode = reinterpret_cast<FrameNode*>(node);
489 CHECK_NULL_VOID(frameNode);
490 SliderModelNG::ResetSelectedBorderRadius(frameNode);
491 }
492
SetInteractionMode(ArkUINodeHandle node,int value)493 void SetInteractionMode(ArkUINodeHandle node, int value)
494 {
495 auto* frameNode = reinterpret_cast<FrameNode*>(node);
496 CHECK_NULL_VOID(frameNode);
497 SliderModelNG::SetSliderInteractionMode(frameNode, static_cast<SliderModel::SliderInteraction>(value));
498 }
499
ResetInteractionMode(ArkUINodeHandle node)500 void ResetInteractionMode(ArkUINodeHandle node)
501 {
502 auto* frameNode = reinterpret_cast<FrameNode*>(node);
503 CHECK_NULL_VOID(frameNode);
504 SliderModelNG::ResetSliderInteractionMode(frameNode);
505 }
506
SetMinResponsiveDistance(ArkUINodeHandle node,float value)507 void SetMinResponsiveDistance(ArkUINodeHandle node, float value)
508 {
509 auto* frameNode = reinterpret_cast<FrameNode*>(node);
510 CHECK_NULL_VOID(frameNode);
511 SliderModelNG::SetMinResponsiveDistance(frameNode, value);
512 }
513
ResetMinResponsiveDistance(ArkUINodeHandle node)514 void ResetMinResponsiveDistance(ArkUINodeHandle node)
515 {
516 auto* frameNode = reinterpret_cast<FrameNode*>(node);
517 CHECK_NULL_VOID(frameNode);
518 SliderModelNG::ResetMinResponsiveDistance(frameNode);
519 }
520
SetOnChange(ArkUINodeHandle node,void * callback)521 void SetOnChange(ArkUINodeHandle node, void* callback)
522 {
523 auto* frameNode = reinterpret_cast<FrameNode*>(node);
524 CHECK_NULL_VOID(frameNode);
525 if (callback) {
526 auto onChange = reinterpret_cast<std::function<void(float, int32_t)>*>(callback);
527 SliderModelNG::SetOnChange(frameNode, std::move(*onChange));
528 } else {
529 SliderModelNG::SetOnChange(frameNode, nullptr);
530 }
531 }
532
ResetOnChange(ArkUINodeHandle node)533 void ResetOnChange(ArkUINodeHandle node)
534 {
535 auto* frameNode = reinterpret_cast<FrameNode*>(node);
536 CHECK_NULL_VOID(frameNode);
537 SliderModelNG::SetOnChange(frameNode, nullptr);
538 }
539
GetBlockColor(ArkUINodeHandle node)540 ArkUI_Uint32 GetBlockColor(ArkUINodeHandle node)
541 {
542 auto *frameNode = reinterpret_cast<FrameNode *>(node);
543 CHECK_NULL_RETURN(frameNode, ERROR_UINT_CODE);
544 return SliderModelNG::GetBlockColor(frameNode).GetValue();
545 }
546
GetTrackBackgroundColor(ArkUINodeHandle node)547 ArkUI_Uint32 GetTrackBackgroundColor(ArkUINodeHandle node)
548 {
549 auto *frameNode = reinterpret_cast<FrameNode *>(node);
550 CHECK_NULL_RETURN(frameNode, ERROR_UINT_CODE);
551 NG::Gradient gradient = SliderModelNG::GetTrackBackgroundColor(frameNode);
552 return gradient.GetColors().at(0).GetLinearColor().ToColor().GetValue();
553 }
554
GetSelectColor(ArkUINodeHandle node)555 ArkUI_Uint32 GetSelectColor(ArkUINodeHandle node)
556 {
557 auto *frameNode = reinterpret_cast<FrameNode *>(node);
558 CHECK_NULL_RETURN(frameNode, ERROR_UINT_CODE);
559 NG::Gradient gradient = SliderModelNG::GetSelectColor(frameNode);
560 return gradient.GetColors().at(0).GetLinearColor().ToColor().GetValue();
561 }
562
GetShowSteps(ArkUINodeHandle node)563 ArkUI_Bool GetShowSteps(ArkUINodeHandle node)
564 {
565 auto *frameNode = reinterpret_cast<FrameNode *>(node);
566 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
567 return static_cast<ArkUI_Bool>(SliderModelNG::GetShowSteps(frameNode));
568 }
569
GetBlockType(ArkUINodeHandle node)570 ArkUI_Int32 GetBlockType(ArkUINodeHandle node)
571 {
572 auto *frameNode = reinterpret_cast<FrameNode *>(node);
573 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
574 return SLIDER_STYLE_TYPE_MAP[SliderModelNG::GetBlockType(frameNode)];
575 }
576
GetSliderValue(ArkUINodeHandle node)577 ArkUI_Float32 GetSliderValue(ArkUINodeHandle node)
578 {
579 auto *frameNode = reinterpret_cast<FrameNode *>(node);
580 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
581 return SliderModelNG::GetSliderValue(frameNode);
582 }
583
GetMinLabel(ArkUINodeHandle node)584 ArkUI_Float32 GetMinLabel(ArkUINodeHandle node)
585 {
586 auto *frameNode = reinterpret_cast<FrameNode *>(node);
587 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
588 return SliderModelNG::GetMinLabel(frameNode);
589 }
590
GetMaxLabel(ArkUINodeHandle node)591 ArkUI_Float32 GetMaxLabel(ArkUINodeHandle node)
592 {
593 auto *frameNode = reinterpret_cast<FrameNode *>(node);
594 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
595 return SliderModelNG::GetMaxLabel(frameNode);
596 }
597
GetDirection(ArkUINodeHandle node)598 ArkUI_Int32 GetDirection(ArkUINodeHandle node)
599 {
600 auto *frameNode = reinterpret_cast<FrameNode *>(node);
601 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
602 return static_cast<ArkUI_Int32>(SliderModelNG::GetDirection(frameNode));
603 }
604
GetStep(ArkUINodeHandle node)605 ArkUI_Float32 GetStep(ArkUINodeHandle node)
606 {
607 auto *frameNode = reinterpret_cast<FrameNode *>(node);
608 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
609 return SliderModelNG::GetStep(frameNode);
610 }
611
GetReverse(ArkUINodeHandle node)612 ArkUI_Bool GetReverse(ArkUINodeHandle node)
613 {
614 auto *frameNode = reinterpret_cast<FrameNode *>(node);
615 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
616 return static_cast<ArkUI_Bool>(SliderModelNG::GetReverse(frameNode));
617 }
618
GetSliderStyle(ArkUINodeHandle node)619 ArkUI_Int32 GetSliderStyle(ArkUINodeHandle node)
620 {
621 auto *frameNode = reinterpret_cast<FrameNode *>(node);
622 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
623 return SLIDER_MODE_MAP[SliderModelNG::GetSliderMode(frameNode)];
624 }
GetBlockImageValue(ArkUINodeHandle node)625 ArkUI_CharPtr GetBlockImageValue(ArkUINodeHandle node)
626 {
627 auto* frameNode = reinterpret_cast<FrameNode*>(node);
628 CHECK_NULL_RETURN(frameNode, nullptr);
629 g_strValue = SliderModelNG::GetBlockImageValue(frameNode);
630 return g_strValue.c_str();
631 }
632
GetSliderBlockShape(ArkUINodeHandle node,ArkUI_Float32 (* value)[5])633 ArkUI_CharPtr GetSliderBlockShape(ArkUINodeHandle node, ArkUI_Float32 (*value)[5])
634 {
635 auto* frameNode = reinterpret_cast<FrameNode*>(node);
636 CHECK_NULL_RETURN(frameNode, nullptr);
637 RefPtr<BasicShape> basicShape = SliderModelNG::GetBlockShape(frameNode);
638 auto shapeType = basicShape->GetBasicShapeType();
639 //index 0 shapeType
640 (*value)[0] = SHAPE_TYPE_MAP[shapeType];
641 //index 1 width
642 (*value)[1] = basicShape->GetWidth().Value();
643 //index 2 height
644 (*value)[2] = basicShape->GetHeight().Value();
645 switch (shapeType) {
646 case BasicShapeType::PATH: {
647 auto path = AceType::DynamicCast<Path>(basicShape);
648 g_strValue = path->GetValue();
649 return g_strValue.c_str();
650 }
651 case BasicShapeType::RECT: {
652 auto shapeRect = AceType::DynamicCast<ShapeRect>(basicShape);
653 //index 3 radius x
654 (*value)[3] = shapeRect->GetTopLeftRadius().GetX().Value();
655 //index 4 radius y
656 (*value)[4] = shapeRect->GetTopLeftRadius().GetY().Value();
657 break;
658 }
659 default:
660 break;
661 }
662 return nullptr;
663 }
664
GetThickness(ArkUINodeHandle node,int unit)665 ArkUI_Float32 GetThickness(ArkUINodeHandle node, int unit)
666 {
667 auto* frameNode = reinterpret_cast<FrameNode*>(node);
668 CHECK_NULL_RETURN(frameNode, ERROR_FLOAT_CODE);
669 return SliderModelNG::GetThickness(frameNode).GetNativeValue(static_cast<DimensionUnit>(unit));
670 }
671
GetSliderValidSlideRange(ArkUINodeHandle node)672 ArkUISliderValidSlideRange GetSliderValidSlideRange(ArkUINodeHandle node)
673 {
674 ArkUISliderValidSlideRange errorReturn = {
675 std::numeric_limits<float>::quiet_NaN(),
676 std::numeric_limits<float>::quiet_NaN()
677 };
678 auto* frameNode = reinterpret_cast<FrameNode*>(node);
679 CHECK_NULL_RETURN(frameNode, errorReturn);
680 auto rangeValue = SliderModelNG::GetValidSlideRange(frameNode);
681 CHECK_NULL_RETURN(rangeValue && rangeValue->HasValidValues(), errorReturn);
682 return { rangeValue->GetFromValue(), rangeValue->GetToValue() };
683 }
684
GetEnableHapticFeedback(ArkUINodeHandle node)685 ArkUI_Bool GetEnableHapticFeedback(ArkUINodeHandle node)
686 {
687 auto* frameNode = reinterpret_cast<FrameNode*>(node);
688 CHECK_NULL_RETURN(frameNode, true);
689 return SliderModelNG::GetEnableHapticFeedback(frameNode);
690 }
691
SetEnableHapticFeedback(ArkUINodeHandle node,int enableHapticFeedback)692 void SetEnableHapticFeedback(ArkUINodeHandle node, int enableHapticFeedback)
693 {
694 auto* frameNode = reinterpret_cast<FrameNode*>(node);
695 CHECK_NULL_VOID(frameNode);
696 SliderModelNG::SetEnableHapticFeedback(frameNode, enableHapticFeedback);
697 }
698
ResetEnableHapticFeedback(ArkUINodeHandle node)699 void ResetEnableHapticFeedback(ArkUINodeHandle node)
700 {
701 auto* frameNode = reinterpret_cast<FrameNode*>(node);
702 CHECK_NULL_VOID(frameNode);
703 SliderModelNG::SetEnableHapticFeedback(frameNode, true);
704 }
705 } // namespace SliderModifier
706
707 namespace NodeModifier {
GetSliderModifier()708 const ArkUISliderModifier* GetSliderModifier()
709 {
710 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
711 static const ArkUISliderModifier modifier = {
712 .setShowTips = SliderModifier::SetShowTips,
713 .resetShowTips = SliderModifier::ResetShowTips,
714 .setSliderStepSize = SliderModifier::SetSliderStepSize,
715 .resetSliderStepSize = SliderModifier::ResetSliderStepSize,
716 .setBlockSize = SliderModifier::SetBlockSize,
717 .resetBlockSize = SliderModifier::ResetBlockSize,
718 .setTrackBorderRadius = SliderModifier::SetTrackBorderRadius,
719 .resetTrackBorderRadius = SliderModifier::ResetTrackBorderRadius,
720 .setStepColor = SliderModifier::SetStepColor,
721 .resetStepColor = SliderModifier::ResetStepColor,
722 .setBlockBorderColor = SliderModifier::SetBlockBorderColor,
723 .resetBlockBorderColor = SliderModifier::ResetBlockBorderColor,
724 .setBlockBorderWidth = SliderModifier::SetBlockBorderWidth,
725 .resetBlockBorderWidth = SliderModifier::ResetBlockBorderWidth,
726 .setBlockColor = SliderModifier::SetBlockColor,
727 .resetBlockColor = SliderModifier::ResetBlockColor,
728 .setTrackBackgroundColor = SliderModifier::SetTrackBackgroundColor,
729 .resetTrackBackgroundColor = SliderModifier::ResetTrackBackgroundColor,
730 .setSelectColor = SliderModifier::SetSelectColor,
731 .resetSelectColor = SliderModifier::ResetSelectColor,
732 .setShowSteps = SliderModifier::SetShowSteps,
733 .resetShowSteps = SliderModifier::ResetShowSteps,
734 .setThickness = SliderModifier::SetThickness,
735 .resetThickness = SliderModifier::ResetThickness,
736 .setSliderValue = SliderModifier::SetSliderValue,
737 .setMinLabel = SliderModifier::SetMinLabel,
738 .setMaxLabel = SliderModifier::SetMaxLabel,
739 .setDirection = SliderModifier::SetDirection,
740 .setStep = SliderModifier::SetStep,
741 .setReverse = SliderModifier::SetReverse,
742 .setSliderStyle = SliderModifier::SetSliderStyle,
743 .resetSliderValue = SliderModifier::ResetSliderValue,
744 .resetMinLabel = SliderModifier::ResetMinLabel,
745 .resetMaxLabel = SliderModifier::ResetMaxLabel,
746 .resetDirection = SliderModifier::ResetDirection,
747 .resetStep = SliderModifier::ResetStep,
748 .resetReverse = SliderModifier::ResetReverse,
749 .resetSliderStyle = SliderModifier::ResetSliderStyle,
750 .setSliderBlockImage = SliderModifier::SetSliderBlockImage,
751 .resetSliderBlockImage = SliderModifier::ResetSliderBlockImage,
752 .setSliderBlockPath = SliderModifier::SetSliderBlockPath,
753 .setSliderBlockShape = SliderModifier::SetSliderBlockShape,
754 .resetSliderBlockShape = SliderModifier::ResetSliderBlockShape,
755 .setSliderBlockType = SliderModifier::SetSliderBlockType,
756 .resetSliderBlockType = SliderModifier::ResetSliderBlockType,
757 .setSliderValidSlideRange = SliderModifier::SetSliderValidSlideRange,
758 .resetSliderValidSlideRange = SliderModifier::ResetSliderValidSlideRange,
759 .setSelectedBorderRadius = SliderModifier::SetSelectedBorderRadius,
760 .resetSelectedBorderRadius = SliderModifier::ResetSelectedBorderRadius,
761 .setInteractionMode = SliderModifier::SetInteractionMode,
762 .resetInteractionMode = SliderModifier::ResetInteractionMode,
763 .setMinResponsiveDistance = SliderModifier::SetMinResponsiveDistance,
764 .resetMinResponsiveDistance = SliderModifier::ResetMinResponsiveDistance,
765 .setOnChange = SliderModifier::SetOnChange,
766 .resetOnChange = SliderModifier::ResetOnChange,
767 .getBlockColor = SliderModifier::GetBlockColor,
768 .getTrackBackgroundColor = SliderModifier::GetTrackBackgroundColor,
769 .getSelectColor = SliderModifier::GetSelectColor,
770 .getShowSteps = SliderModifier::GetShowSteps,
771 .getBlockType = SliderModifier::GetBlockType,
772 .getSliderValue = SliderModifier::GetSliderValue,
773 .getMinLabel = SliderModifier::GetMinLabel,
774 .getMaxLabel = SliderModifier::GetMaxLabel,
775 .getDirection = SliderModifier::GetDirection,
776 .getStep = SliderModifier::GetStep,
777 .getReverse = SliderModifier::GetReverse,
778 .getSliderStyle = SliderModifier::GetSliderStyle,
779 .getBlockImageValue = SliderModifier::GetBlockImageValue,
780 .getSliderBlockShape = SliderModifier::GetSliderBlockShape,
781 .getThickness = SliderModifier::GetThickness,
782 .getSliderValidSlideRange = SliderModifier::GetSliderValidSlideRange,
783 .getEnableHapticFeedback = SliderModifier::GetEnableHapticFeedback,
784 .setEnableHapticFeedback = SliderModifier::SetEnableHapticFeedback,
785 .resetEnableHapticFeedback = SliderModifier::ResetEnableHapticFeedback,
786 };
787 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
788
789 return &modifier;
790 }
791
GetCJUISliderModifier()792 const CJUISliderModifier* GetCJUISliderModifier()
793 {
794 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
795 static const CJUISliderModifier modifier = {
796 .setShowTips = SliderModifier::SetShowTips,
797 .resetShowTips = SliderModifier::ResetShowTips,
798 .setSliderStepSize = SliderModifier::SetSliderStepSize,
799 .resetSliderStepSize = SliderModifier::ResetSliderStepSize,
800 .setBlockSize = SliderModifier::SetBlockSize,
801 .resetBlockSize = SliderModifier::ResetBlockSize,
802 .setTrackBorderRadius = SliderModifier::SetTrackBorderRadius,
803 .resetTrackBorderRadius = SliderModifier::ResetTrackBorderRadius,
804 .setStepColor = SliderModifier::SetStepColor,
805 .resetStepColor = SliderModifier::ResetStepColor,
806 .setBlockBorderColor = SliderModifier::SetBlockBorderColor,
807 .resetBlockBorderColor = SliderModifier::ResetBlockBorderColor,
808 .setBlockBorderWidth = SliderModifier::SetBlockBorderWidth,
809 .resetBlockBorderWidth = SliderModifier::ResetBlockBorderWidth,
810 .setBlockColor = SliderModifier::SetBlockColor,
811 .resetBlockColor = SliderModifier::ResetBlockColor,
812 .setTrackBackgroundColor = SliderModifier::SetTrackBackgroundColor,
813 .resetTrackBackgroundColor = SliderModifier::ResetTrackBackgroundColor,
814 .setSelectColor = SliderModifier::SetSelectColor,
815 .resetSelectColor = SliderModifier::ResetSelectColor,
816 .setShowSteps = SliderModifier::SetShowSteps,
817 .resetShowSteps = SliderModifier::ResetShowSteps,
818 .setThickness = SliderModifier::SetThickness,
819 .resetThickness = SliderModifier::ResetThickness,
820 .setSliderValue = SliderModifier::SetSliderValue,
821 .setMinLabel = SliderModifier::SetMinLabel,
822 .setMaxLabel = SliderModifier::SetMaxLabel,
823 .setDirection = SliderModifier::SetDirection,
824 .setStep = SliderModifier::SetStep,
825 .setReverse = SliderModifier::SetReverse,
826 .setSliderStyle = SliderModifier::SetSliderStyle,
827 .resetSliderValue = SliderModifier::ResetSliderValue,
828 .resetMinLabel = SliderModifier::ResetMinLabel,
829 .resetMaxLabel = SliderModifier::ResetMaxLabel,
830 .resetDirection = SliderModifier::ResetDirection,
831 .resetStep = SliderModifier::ResetStep,
832 .resetReverse = SliderModifier::ResetReverse,
833 .resetSliderStyle = SliderModifier::ResetSliderStyle,
834 .setSliderBlockImage = SliderModifier::SetSliderBlockImage,
835 .resetSliderBlockImage = SliderModifier::ResetSliderBlockImage,
836 .setSliderBlockPath = SliderModifier::SetSliderBlockPath,
837 .setSliderBlockShape = SliderModifier::SetSliderBlockShape,
838 .resetSliderBlockShape = SliderModifier::ResetSliderBlockShape,
839 .setSliderBlockType = SliderModifier::SetSliderBlockType,
840 .resetSliderBlockType = SliderModifier::ResetSliderBlockType,
841 .setSliderValidSlideRange = SliderModifier::SetSliderValidSlideRange,
842 .resetSliderValidSlideRange = SliderModifier::ResetSliderValidSlideRange,
843 .setSelectedBorderRadius = SliderModifier::SetSelectedBorderRadius,
844 .resetSelectedBorderRadius = SliderModifier::ResetSelectedBorderRadius,
845 .setInteractionMode = SliderModifier::SetInteractionMode,
846 .resetInteractionMode = SliderModifier::ResetInteractionMode,
847 .setMinResponsiveDistance = SliderModifier::SetMinResponsiveDistance,
848 .resetMinResponsiveDistance = SliderModifier::ResetMinResponsiveDistance,
849 .getBlockColor = SliderModifier::GetBlockColor,
850 .getTrackBackgroundColor = SliderModifier::GetTrackBackgroundColor,
851 .getSelectColor = SliderModifier::GetSelectColor,
852 .getShowSteps = SliderModifier::GetShowSteps,
853 .getBlockType = SliderModifier::GetBlockType,
854 .getSliderValue = SliderModifier::GetSliderValue,
855 .getMinLabel = SliderModifier::GetMinLabel,
856 .getMaxLabel = SliderModifier::GetMaxLabel,
857 .getDirection = SliderModifier::GetDirection,
858 .getStep = SliderModifier::GetStep,
859 .getReverse = SliderModifier::GetReverse,
860 .getSliderStyle = SliderModifier::GetSliderStyle,
861 .getBlockImageValue = SliderModifier::GetBlockImageValue,
862 .getSliderBlockShape = SliderModifier::GetSliderBlockShape,
863 .getThickness = SliderModifier::GetThickness,
864 .getSliderValidSlideRange = SliderModifier::GetSliderValidSlideRange,
865 .getEnableHapticFeedback = SliderModifier::GetEnableHapticFeedback,
866 .setEnableHapticFeedback = SliderModifier::SetEnableHapticFeedback,
867 .resetEnableHapticFeedback = SliderModifier::ResetEnableHapticFeedback,
868 };
869 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
870
871 return &modifier;
872 }
873
SetSliderChange(ArkUINodeHandle node,void * extraParam)874 void SetSliderChange(ArkUINodeHandle node, void* extraParam)
875 {
876 auto* frameNode = reinterpret_cast<FrameNode*>(node);
877 CHECK_NULL_VOID(frameNode);
878 auto onEvent = [node, extraParam](float value, int32_t mode) {
879 ArkUINodeEvent event;
880 event.kind = COMPONENT_ASYNC_EVENT;
881 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
882 event.componentAsyncEvent.subKind = ON_SLIDER_CHANGE;
883 event.componentAsyncEvent.data[0].f32 = value;
884 event.componentAsyncEvent.data[1].i32 = mode;
885 SendArkUISyncEvent(&event);
886 };
887 SliderModelNG::SetOnChange(frameNode, std::move(onEvent));
888 }
889
890 }
891 }
892