MyGUI: MyGUI_WidgetStyle.h Source File

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
18 struct MYGUI_EXPORT WidgetStyle
19 {
20 enum Enum
21 {
22 Child,
23 Popup,
24 Overlapped,
25 MAX
26 };
27
28 WidgetStyle() :
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_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI::FontCodeType::Enum
Enum
Definition MyGUI_FontData.h:20
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::WidgetStyle::WidgetStyle
WidgetStyle()
Definition MyGUI_WidgetStyle.h:28
MyGUI::WidgetStyle::operator!=
friend bool operator!=(WidgetStyle const &a, WidgetStyle const &b)
Definition MyGUI_WidgetStyle.h:58
MyGUI::WidgetStyle::WidgetStyle
WidgetStyle(Enum _value)
Definition MyGUI_WidgetStyle.h:33
MyGUI::WidgetStyle::print
std::string_view print() const
Definition MyGUI_WidgetStyle.h:77
MyGUI::WidgetStyle::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const WidgetStyle &_value)
Definition MyGUI_WidgetStyle.h:63
MyGUI::WidgetStyle::operator==
friend bool operator==(WidgetStyle const &a, WidgetStyle const &b)
Definition MyGUI_WidgetStyle.h:53
MyGUI::WidgetStyle::operator>>
friend std::istream & operator>>(std::istream &_stream, WidgetStyle &_value)
Definition MyGUI_WidgetStyle.h:69
MyGUI::WidgetStyle::Enum
Enum
Definition MyGUI_WidgetStyle.h:21
MyGUI::WidgetStyle::Popup
@ Popup
Definition MyGUI_WidgetStyle.h:23
MyGUI::WidgetStyle::Child
@ Child
Definition MyGUI_WidgetStyle.h:22
MyGUI::WidgetStyle::MAX
@ MAX
Definition MyGUI_WidgetStyle.h:25
MyGUI::WidgetStyle::Overlapped
@ Overlapped
Definition MyGUI_WidgetStyle.h:24
MyGUI::WidgetStyle::parse
static WidgetStyle parse(std::string_view _value)
Definition MyGUI_WidgetStyle.h:38
MyGUI::WidgetStyle::getValue
int getValue() const
Definition MyGUI_WidgetStyle.h:82