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_row_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/row_model_ng.h"
22 
23 using namespace OHOS::Ace;
24 using namespace OHOS::Ace::Framework;
25 
26 namespace {
27 const std::vector<FlexAlign> FLEX_ALIGNS = {
28     FlexAlign::AUTO,
29     FlexAlign::FLEX_START,
30     FlexAlign::CENTER,
31     FlexAlign::FLEX_END,
32     FlexAlign::SPACE_BETWEEN,
33     FlexAlign::SPACE_AROUND,
34     FlexAlign::SPACE_EVENLY
35 };
36 } // namespace
37 
38 extern "C" {
FfiOHOSAceFrameworkRowCreate()39 void FfiOHOSAceFrameworkRowCreate()
40 {
41     RowModel::GetInstance()->CreateWithWrap();
42     return;
43 }
44 
FfiOHOSAceFrameworkRowCreateWithSpace(double space,int32_t unit)45 void FfiOHOSAceFrameworkRowCreateWithSpace(double space, int32_t unit)
46 {
47     Dimension spaceDime(space, static_cast<DimensionUnit>(unit));
48     Dimension value(space, static_cast<DimensionUnit>(unit));
49     RowModel::GetInstance()->Create(value, nullptr, "");
50     return;
51 }
52 
FfiOHOSAceFrameworkRowSetAlignItems(int32_t alignItems)53 void FfiOHOSAceFrameworkRowSetAlignItems(int32_t alignItems)
54 {
55     if (!Utils::CheckParamsValid(alignItems, FLEX_ALIGNS.size())) {
56         LOGE("invalid value for align item");
57         return;
58     }
59     RowModel::GetInstance()->SetAlignItems(FLEX_ALIGNS[alignItems]);
60 }
61 
FfiOHOSAceFrameworkRowSetJustifyContent(int32_t justifyContent)62 void FfiOHOSAceFrameworkRowSetJustifyContent(int32_t justifyContent)
63 {
64     if (!Utils::CheckParamsValid(justifyContent, FLEX_ALIGNS.size())) {
65         LOGE("invalid value for justifyContent");
66         return;
67     }
68     RowModel::GetInstance()->SetJustifyContent(FLEX_ALIGNS[justifyContent]);
69     return;
70 }
71 
FfiOHOSAceFrameworkRowSetHeight(double height,int32_t unit)72 void FfiOHOSAceFrameworkRowSetHeight(double height, int32_t unit)
73 {
74     FfiOHOSAceFrameworkViewAbstractSetHeight(height, unit);
75     FlexModel::GetInstance()->SetHasHeight();
76     return;
77 }
78 
FfiOHOSAceFrameworkRowSetWidth(double width,int32_t unit)79 void FfiOHOSAceFrameworkRowSetWidth(double width, int32_t unit)
80 {
81     FfiOHOSAceFrameworkViewAbstractSetWidth(width, unit);
82     FlexModel::GetInstance()->SetHasWidth();
83     return;
84 }
85 }
86