• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_PROPERTIES_ALIGNMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_ALIGNMENT_H
18 
19 #include <string>
20 
21 #include "base/geometry/offset.h"
22 #include "base/geometry/size.h"
23 #include "base/utils/macros.h"
24 #include "core/components/common/layout/constants.h"
25 
26 namespace OHOS::Ace {
27 
28 class ACE_EXPORT Alignment final {
29 public:
30     Alignment() = default;
31     ~Alignment() = default;
32 
GetHorizontal()33     double GetHorizontal() const
34     {
35         return horizontal_;
36     }
37 
GetVertical()38     double GetVertical() const
39     {
40         return vertical_;
41     }
42 
43     bool operator==(const Alignment& other) const
44     {
45         return NearEqual(horizontal_, other.horizontal_) && NearEqual(vertical_, other.vertical_);
46     }
47 
48     bool operator!=(const Alignment& other) const
49     {
50         return !operator==(other);
51     }
52 
53     static const Offset GetAlignPosition(const Size& parentSize, const Size& childSize, const Alignment& alignment);
54     static const Alignment TOP_LEFT;
55     static const Alignment TOP_CENTER;
56     static const Alignment TOP_RIGHT;
57     static const Alignment CENTER_LEFT;
58     static const Alignment CENTER;
59     static const Alignment CENTER_RIGHT;
60     static const Alignment BOTTOM_LEFT;
61     static const Alignment BOTTOM_CENTER;
62     static const Alignment BOTTOM_RIGHT;
63 
ToString()64     std::string ToString() const
65     {
66         std::stringstream ss;
67         ss << "Alignment (" << std::fixed << std::setprecision(1) << horizontal_ << ", " << vertical_ << ")";
68         std::string output = ss.str();
69         return output;
70     }
71 
72     std::string GetAlignmentStr(TextDirection direction) const;
73 
74 private:
75     friend class AlignCreator;
Alignment(double horizontal,double vertical)76     Alignment(double horizontal, double vertical) : horizontal_(horizontal), vertical_(vertical) {}
77     double horizontal_ = 0.0;
78     double vertical_ = 0.0;
79 };
80 
81 } // namespace OHOS::Ace
82 
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_PROPERTIES_ALIGNMENT_H
84