1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FLEX_FLEX_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FLEX_FLEX_MODEL_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <vector>
22 
23 #include "base/utils/macros.h"
24 #include "core/components/common/layout/constants.h"
25 #include "frameworks/base/geometry/dimension.h"
26 
27 namespace OHOS::Ace {
28 
29 const std::vector<WrapAlignment> WRAP_TABLE = {
30     WrapAlignment::START,
31     WrapAlignment::START,
32     WrapAlignment::CENTER,
33     WrapAlignment::END,
34     WrapAlignment::STRETCH,
35     WrapAlignment::BASELINE,
36     WrapAlignment::SPACE_BETWEEN,
37     WrapAlignment::SPACE_AROUND,
38     WrapAlignment::SPACE_EVENLY,
39 };
40 
41 constexpr int32_t MAIN_ALIGN_MAX_VALUE = 8;
42 constexpr int32_t CROSS_ALIGN_MAX_VALUE = 5;
43 constexpr int32_t DIRECTION_MAX_VALUE = 3;
44 
45 class ACE_FORCE_EXPORT FlexModel {
46 public:
47     static FlexModel* GetInstance();
48     virtual ~FlexModel() = default;
49 
50     virtual void CreateFlexRow() = 0;
51 
52     virtual void CreateWrap() = 0;
53 
54     virtual void SetDirection(FlexDirection direction) = 0;
55     virtual void SetWrapDirection(WrapDirection direction) = 0;
56 
57     virtual void SetMainAxisAlign(FlexAlign flexAlign) = 0;
58     virtual void SetWrapMainAlignment(WrapAlignment value) = 0;
59 
60     virtual void SetCrossAxisAlign(FlexAlign flexAlign) = 0;
61     virtual void SetWrapCrossAlignment(WrapAlignment value) = 0;
62 
63     virtual void SetAlignItems(int32_t value) = 0;
64     virtual void SetWrapAlignment(WrapAlignment value) = 0;
65 
66     virtual void SetHasHeight() = 0;
67     virtual void SetHasWidth() = 0;
68     virtual void SetFlexWidth() = 0;
69     virtual void SetFlexHeight() = 0;
70 
71     virtual void SetJustifyContent(int32_t value) = 0;
72 
73     virtual void SetAlignContent(int32_t value) = 0;
74     virtual void SetMainSpace(const std::optional<Dimension>& space) = 0;
75     virtual void SetCrossSpace(const std::optional<Dimension>& space) = 0;
76 
77 private:
78     static std::unique_ptr<FlexModel> instance_;
79     static std::mutex mutex_;
80 };
81 
82 } // namespace OHOS::Ace
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FLEX_FLEX_MODEL_H
84