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 "cj_badge_ffi.h"
17
18 #include "utils.h"
19 #include "core/components_ng/pattern/badge/badge_model.h"
20 #include "core/components_ng/pattern/badge/badge_model_ng.h"
21
22 using namespace OHOS::Ace;
23
24 namespace {
CreateBase(CJBadgeStyle style,int32_t position)25 BadgeParameters CreateBase(CJBadgeStyle style, int32_t position)
26 {
27 BadgeParameters badgeParameters;
28 badgeParameters.badgePosition = position;
29 badgeParameters.badgeTextColor = Color(style.color);
30 badgeParameters.badgeFontSize = Dimension(style.fontSize, DimensionUnit::VP);
31 badgeParameters.badgeCircleSize = Dimension(style.badgeSize, DimensionUnit::VP);
32 badgeParameters.badgeColor = Color(style.badgeColor);
33 return badgeParameters;
34 }
35 } // namespace
36
37 extern "C" {
FfiOHOSAceFrameworkBadgeCreate(int32_t count,CJBadgeStyle style,int32_t position,int32_t maxCount)38 void FfiOHOSAceFrameworkBadgeCreate(int32_t count, CJBadgeStyle style, int32_t position, int32_t maxCount)
39 {
40 BadgeParameters badgeParameters = CreateBase(style, position);
41 badgeParameters.badgeCount = count;
42 badgeParameters.badgeMaxCount = maxCount;
43 BadgeModel::GetInstance()->Create(badgeParameters);
44 }
45
FfiOHOSAceFrameworkBadgeCreateText(const char * value,CJBadgeStyle style,int32_t position)46 void FfiOHOSAceFrameworkBadgeCreateText(const char* value, CJBadgeStyle style, int32_t position)
47 {
48 BadgeParameters badgeParameters = CreateBase(style, position);
49 badgeParameters.badgeValue = value;
50 BadgeModel::GetInstance()->Create(badgeParameters);
51 }
52 }
53