• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
18 
19 #include <mutex>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/memory/ace_type.h"
23 #include "core/components/common/layout/grid_column_info.h"
24 
25 namespace OHOS::Ace {
26 
27 struct SystemGridInfo {
28     SystemGridInfo() = default;
SystemGridInfoSystemGridInfo29     SystemGridInfo(
30         GridSizeType sizeType, const Dimension& gutter, const Dimension& margin, int32_t columns, int32_t maxColumns)
31         : sizeType(sizeType), gutter(gutter), margin(margin), columns(columns), maxColumns(maxColumns)
32     {}
SystemGridInfoSystemGridInfo33     SystemGridInfo(GridSizeType sizeType, const Dimension& gutter, const Dimension& margin, int32_t columns)
34         : sizeType(sizeType), gutter(gutter), margin(margin), columns(columns), maxColumns(columns)
35     {}
36     ACE_FORCE_EXPORT_WITH_PREVIEW std::string ToString() const;
37 
38     GridSizeType sizeType = GridSizeType::UNDEFINED;
39     Dimension gutter;
40     Dimension margin;
41     int32_t columns = 0;
42     int32_t maxColumns = 0;
43 };
44 
45 class ACE_FORCE_EXPORT_WITH_PREVIEW GridSystemManager final {
46 public:
47     ~GridSystemManager() = default;
48     ACE_EXPORT static GridSystemManager& GetInstance();
49 
GetCurrentGridInfo()50     const SystemGridInfo& GetCurrentGridInfo()
51     {
52         return systemGridInfo_;
53     }
54 
55     static SystemGridInfo GetSystemGridInfo(const GridSizeType& sizeType);
56     static RefPtr<GridColumnInfo> GetInfoByType(const GridColumnType& type);
57     // width is use px unit.
58     SystemGridInfo GetSystemGridInfo(const GridTemplateType& templateType, double width);
59     void OnSurfaceChanged(double width);
SetWindowInfo(double screenWidth,double density,double dipScale)60     void SetWindowInfo(double screenWidth, double density, double dipScale)
61     {
62         screenWidth_ = screenWidth;
63         density_ = density;
64         dipScale_ = dipScale;
65         viewScale_ = density / dipScale;
66     }
67 
GetScreenWidth()68     double GetScreenWidth() const
69     {
70         return screenWidth_;
71     }
72 
GetDipScale()73     double GetDipScale() const
74     {
75         return dipScale_;
76     }
77 
GetCurrentSize()78     GridSizeType GetCurrentSize() const
79     {
80         return currentSize_;
81     }
82 
83 private:
84     GridSystemManager() = default;
85 
86     static GridSystemManager* instance_;
87     static std::mutex mutex_;
88 
89     double screenWidth_ = 0.0;
90     double density_ = 1.0;
91     double dipScale_ = 1.0;
92     double viewScale_ = 1.0;
93     GridSizeType currentSize_ = GridSizeType::UNDEFINED;
94     SystemGridInfo systemGridInfo_;
95 
96     ACE_DISALLOW_COPY_AND_MOVE(GridSystemManager);
97 };
98 
99 } // namespace OHOS::Ace
100 
101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
102