MyGUI 3.5.3
MyGUI_Align.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_ALIGN_H_
8#define MYGUI_ALIGN_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Macros.h"
12#include "MyGUI_Diagnostic.h"
13#include <map>
14
15namespace MyGUI
16{
17
18 struct MYGUI_EXPORT Align
19 {
20 enum Enum
21 {
22 HCenter = MYGUI_FLAG_NONE,
23 VCenter = MYGUI_FLAG_NONE,
24 Center = HCenter | VCenter,
25
26 Left = MYGUI_FLAG(1),
27 Right = MYGUI_FLAG(2),
28 HStretch = Left | Right,
29
30 Top = MYGUI_FLAG(3),
31 Bottom = MYGUI_FLAG(4),
32 VStretch = Top | Bottom,
33
34 Stretch = HStretch | VStretch,
35 Default = Left | Top
36 };
37
38 Align(Enum _value = Default) :
39 mValue(_value)
40 {
41 }
42
43 bool isHCenter() const
44 {
45 return HCenter == (mValue & HStretch);
46 }
47
48 bool isVCenter() const
49 {
50 return VCenter == (mValue & VStretch);
51 }
52
53 bool isCenter() const
54 {
55 return Center == (mValue & Stretch);
56 }
57
58 bool isLeft() const
59 {
60 return Left == (mValue & HStretch);
61 }
62
63 bool isRight() const
64 {
65 return Right == (mValue & HStretch);
66 }
67
68 bool isHStretch() const
69 {
70 return HStretch == (mValue & HStretch);
71 }
72
73 bool isTop() const
74 {
75 return Top == (mValue & VStretch);
76 }
77
78 bool isBottom() const
79 {
80 return Bottom == (mValue & VStretch);
81 }
82
83 bool isVStretch() const
84 {
85 return VStretch == (mValue & VStretch);
86 }
87
88 bool isStretch() const
89 {
90 return Stretch == (mValue & Stretch);
91 }
92
93 bool isDefault() const
94 {
95 return Default == (mValue & Stretch);
96 }
97
98 Align& operator|=(Align const& _other)
99 {
100 mValue = (mValue | _other.mValue).mValue;
101 return *this;
102 }
103
104 friend Align operator|(Enum const& a, Enum const& b)
105 {
106 return {Enum((unsigned int)a | (unsigned int)b)};
107 }
108
109 friend Align operator|(Align const& a, Align const& b)
110 {
111 return a.mValue | b.mValue;
112 }
113
114 friend bool operator==(Align const& a, Align const& b)
115 {
116 return a.mValue == b.mValue;
117 }
118
119 friend bool operator!=(Align const& a, Align const& b)
120 {
121 return a.mValue != b.mValue;
122 }
123
124 using MapAlign = std::map<std::string, Align>;
125
126 static Align parse(std::string_view _value);
127
128 std::string print() const;
129
130 friend std::ostream& operator<<(std::ostream& _stream, const Align& _value)
131 {
132 _stream << _value.print();
133 return _stream;
134 }
135
136 friend std::istream& operator>>(std::istream& _stream, Align& _value)
137 {
138 _value.mValue = Enum(0);
139 std::string value;
140 _stream >> value;
141
142 const MapAlign& map_names = Align::getValueNames();
143 auto iter = map_names.find(value);
144 if (iter != map_names.end())
145 _value |= iter->second;
146
147 if (!_stream.eof())
148 {
149 std::string value2;
150 _stream >> value2;
151 iter = map_names.find(value2);
152 if (iter != map_names.end())
153 _value |= iter->second;
154 }
155
156 return _stream;
157 }
158
159 int getValue() const
160 {
161 return mValue;
162 }
163
164 private:
165 static const MapAlign& getValueNames();
166
167 private:
168 Enum mValue;
169 };
170
171} // namespace MyGUI
172
173#endif // MYGUI_ALIGN_H_
#define MYGUI_EXPORT
constexpr unsigned int MYGUI_FLAG(uint8_t num)
constexpr unsigned int MYGUI_FLAG_NONE