MyGUI 3.4.3
MyGUI_WidgetStyle.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_WIDGET_STYLE_H_
8#define MYGUI_WIDGET_STYLE_H_
9
10#include "MyGUI_Prerequest.h"
11#include <string>
12#include <cstring>
13#include <iostream>
14
15namespace MyGUI
16{
17
19 {
20 enum Enum
21 {
25 MAX
26 };
27
29 mValue(MAX)
30 {
31 }
32
33 WidgetStyle(Enum _value) :
34 mValue(_value)
35 {
36 }
37
38 static WidgetStyle parse(std::string_view _value)
39 {
40 WidgetStyle type;
41 int value = 0;
42 while (true)
43 {
44 std::string_view name = type.getValueName(value);
45 if (name.empty() || name == _value)
46 break;
47 value++;
48 }
49 type.mValue = static_cast<Enum>(value);
50 return type;
51 }
52
53 friend bool operator==(WidgetStyle const& a, WidgetStyle const& b)
54 {
55 return a.mValue == b.mValue;
56 }
57
58 friend bool operator!=(WidgetStyle const& a, WidgetStyle const& b)
59 {
60 return a.mValue != b.mValue;
61 }
62
63 friend std::ostream& operator<<(std::ostream& _stream, const WidgetStyle& _value)
64 {
65 _stream << _value.getValueName(_value.mValue);
66 return _stream;
67 }
68
69 friend std::istream& operator>>(std::istream& _stream, WidgetStyle& _value)
70 {
71 std::string value;
72 _stream >> value;
73 _value = parse(value);
74 return _stream;
75 }
76
77 std::string_view print() const
78 {
79 return getValueName(mValue);
80 }
81
82 int getValue() const
83 {
84 return mValue;
85 }
86
87 private:
88 std::string_view getValueName(int _index) const
89 {
90 if (_index < 0 || _index >= MAX)
91 return {};
92 static const std::string_view values[MAX] = {"Child", "Popup", "Overlapped"};
93 return values[_index];
94 }
95
96 private:
97 Enum mValue;
98 };
99
100} // namespace MyGUI
101
102#endif // MYGUI_WIDGET_STYLE_H_
#define MYGUI_EXPORT
friend bool operator!=(WidgetStyle const &a, WidgetStyle const &b)
std::string_view print() const
friend std::ostream & operator<<(std::ostream &_stream, const WidgetStyle &_value)
friend bool operator==(WidgetStyle const &a, WidgetStyle const &b)
friend std::istream & operator>>(std::istream &_stream, WidgetStyle &_value)
static WidgetStyle parse(std::string_view _value)