1 /*
2  * Copyright (c) 2024 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 "bridge/cj_frontend/interfaces/cj_ffi/cj_counter_ffi.h"
17 
18 #include "cj_lambda.h"
19 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_view_abstract_ffi.h"
20 #include "core/components_ng/pattern/counter/counter_model.h"
21 #include "core/components_ng/pattern/counter/counter_model_ng.h"
22 
23 using namespace OHOS::Ace;
24 using namespace OHOS::Ace::Framework;
25 
26 extern "C" {
FfiOHOSAceFrameworkCounterCreate()27 void FfiOHOSAceFrameworkCounterCreate()
28 {
29     CounterModel::GetInstance()->Create();
30 }
31 
FfiOHOSAceFrameworkCounterSetWidth(double value,int32_t unit)32 void FfiOHOSAceFrameworkCounterSetWidth(double value, int32_t unit)
33 {
34     Dimension dValue(value, static_cast<DimensionUnit>(unit));
35     if (LessNotEqual(dValue.Value(), 0.0)) {
36         dValue.SetValue(0.0);
37     }
38     CounterModel::GetInstance()->SetWidth(dValue);
39 }
40 
FfiOHOSAceFrameworkCounterSetHeight(double value,int32_t unit)41 void FfiOHOSAceFrameworkCounterSetHeight(double value, int32_t unit)
42 {
43     Dimension dValue(value, static_cast<DimensionUnit>(unit));
44     if (LessNotEqual(dValue.Value(), 0.0)) {
45         dValue.SetValue(0.0);
46     }
47     CounterModel::GetInstance()->SetHeight(dValue);
48 }
49 
FfiOHOSAceFrameworkCounterSetSize(double width,int32_t widthUnit,double height,int32_t heightUnit)50 void FfiOHOSAceFrameworkCounterSetSize(double width, int32_t widthUnit, double height, int32_t heightUnit)
51 {
52     FfiOHOSAceFrameworkCounterSetWidth(width, widthUnit);
53     FfiOHOSAceFrameworkCounterSetHeight(height, heightUnit);
54 }
55 
FfiOHOSAceFrameworkCounterSetControlWidth(double value,int32_t unit)56 void FfiOHOSAceFrameworkCounterSetControlWidth(double value, int32_t unit)
57 {
58     Dimension dValue(value, static_cast<DimensionUnit>(unit));
59     if (LessNotEqual(dValue.Value(), 0.0)) {
60         dValue.SetValue(0.0);
61     }
62     CounterModel::GetInstance()->SetControlWidth(dValue);
63 }
64 
FfiOHOSAceFrameworkCounterSetStateChange(bool state)65 void FfiOHOSAceFrameworkCounterSetStateChange(bool state)
66 {
67     CounterModel::GetInstance()->SetStateChange(state);
68 }
69 
FfiOHOSAceFrameworkCounterSetBackgroundColor(uint32_t color)70 void FfiOHOSAceFrameworkCounterSetBackgroundColor(uint32_t color)
71 {
72     CounterModel::GetInstance()->SetBackgroundColor(Color(color));
73 }
74 
FfiOHOSAceFrameworkCounterSetOnInc(void (* callback)())75 void FfiOHOSAceFrameworkCounterSetOnInc(void (*callback)())
76 {
77     CounterModel::GetInstance()->SetOnInc(CJLambda::Create(callback));
78 }
79 
FfiOHOSAceFrameworkCounterSetOnDec(void (* callback)())80 void FfiOHOSAceFrameworkCounterSetOnDec(void (*callback)())
81 {
82     CounterModel::GetInstance()->SetOnDec(CJLambda::Create(callback));
83 }
84 }
85