• 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_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H
18 
19 #include <string>
20 
21 namespace OHOS::Ace {
22 
23 class ViewportConfig {
24 public:
25     ViewportConfig() = default;
ViewportConfig(int32_t width,int32_t height,float density)26     ViewportConfig(int32_t width, int32_t height, float density)
27         : width_(width), height_(height), density_(density)
28     {}
29     ~ViewportConfig() = default;
30 
SetSize(int32_t width,int32_t height)31     void SetSize(int32_t width, int32_t height)
32     {
33         width_ = width;
34         height_ = height;
35     }
36 
SetPosition(int32_t x,int32_t y)37     void SetPosition(int32_t x, int32_t y)
38     {
39         posX_ = x;
40         posY_ = y;
41     }
42 
Width()43     int32_t Width() const
44     {
45         return width_;
46     }
47 
Height()48     int32_t Height() const
49     {
50         return height_;
51     }
52 
Left()53     int32_t Left() const
54     {
55         return posX_;
56     }
57 
Top()58     int32_t Top() const
59     {
60         return posY_;
61     }
62 
SetDensity(float density)63     void SetDensity(float density)
64     {
65         density_ = density;
66     }
67 
Density()68     float Density() const
69     {
70         return density_;
71     }
72 
SetOrientation(int32_t orientation)73     void SetOrientation(int32_t orientation)
74     {
75         orientation_ = orientation;
76     }
77 
Orientation()78     int32_t Orientation() const
79     {
80         return orientation_;
81     }
82 
ToString()83     std::string ToString() const
84     {
85         std::string config = "Viewport config:";
86         config.append(" size: (" + std::to_string(width_) + ", " + std::to_string(height_) + ")");
87         config.append(" orientation: " + std::to_string(orientation_));
88         config.append(" density: " + std::to_string(density_));
89         config.append(" position: (" + std::to_string(posX_) + ", " + std::to_string(posY_) + ")");
90         return config;
91     }
92 
93 private:
94     int32_t width_ = 0;
95     int32_t height_ = 0;
96     int32_t posX_ = 0;
97     int32_t posY_ = 0;
98     int32_t orientation_ = 0;
99     float density_ = 1.0f;
100 };
101 
102 } // namespace OHOS::Ace
103 
104 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_ACE_VIEWPORT_CONFIG_H
105