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_column_ffi.h"
17 
18 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_view_abstract_ffi.h"
19 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
20 #include "core/components_ng/pattern/flex/flex_model.h"
21 #include "core/components_ng/pattern/linear_layout/column_model_ng.h"
22 #include "core/common/container.h"
23 
24 using namespace OHOS::Ace;
25 using namespace OHOS::Ace::Framework;
26 
27 namespace {
28 const std::vector<FlexAlign> FLEX_ALIGNS = {
29     FlexAlign::AUTO,
30     FlexAlign::FLEX_START,
31     FlexAlign::CENTER,
32     FlexAlign::FLEX_END,
33     FlexAlign::SPACE_BETWEEN,
34     FlexAlign::SPACE_AROUND,
35     FlexAlign::SPACE_EVENLY
36 };
37 } // namespace
38 
39 extern "C" {
FfiOHOSAceFrameworkColumnCreate()40 void FfiOHOSAceFrameworkColumnCreate()
41 {
42     ColumnModel::GetInstance()->CreateWithWrap();
43 }
44 
FfiOHOSAceFrameworkColumnCreateWithSpace(double space,int32_t unit)45 void FfiOHOSAceFrameworkColumnCreateWithSpace(double space, int32_t unit)
46 {
47     Dimension value(space, static_cast<DimensionUnit>(unit));
48     ColumnModel::GetInstance()->Create(value, nullptr, "");
49 }
50 
FfiOHOSAceFrameworkColumnSetAlignItems(int32_t alignItems)51 void FfiOHOSAceFrameworkColumnSetAlignItems(int32_t alignItems)
52 {
53     if (!Utils::CheckParamsValid(alignItems, FLEX_ALIGNS.size())) {
54         LOGE("invalid value for align item");
55         return;
56     }
57     ColumnModel::GetInstance()->SetAlignItems(FLEX_ALIGNS[alignItems]);
58 }
59 
FfiOHOSAceFrameworkColumnSetJustifyContent(int32_t justifyContent)60 void FfiOHOSAceFrameworkColumnSetJustifyContent(int32_t justifyContent)
61 {
62     if (!Utils::CheckParamsValid(justifyContent, FLEX_ALIGNS.size())) {
63         LOGE("invalid value for justifyContent");
64         return;
65     }
66     ColumnModel::GetInstance()->SetJustifyContent(FLEX_ALIGNS[justifyContent]);
67 }
68 
FfiOHOSAceFrameworkColumnSetHeight(double height,int32_t unit)69 void FfiOHOSAceFrameworkColumnSetHeight(double height, int32_t unit)
70 {
71     FfiOHOSAceFrameworkViewAbstractSetHeight(height, unit);
72     FlexModel::GetInstance()->SetHasHeight();
73 }
74 
FfiOHOSAceFrameworkColumnSetWidth(double width,int32_t unit)75 void FfiOHOSAceFrameworkColumnSetWidth(double width, int32_t unit)
76 {
77     FfiOHOSAceFrameworkViewAbstractSetWidth(width, unit);
78     FlexModel::GetInstance()->SetHasWidth();
79 }
80 }
81