MyGUI_Align.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_ALIGN_H_
#define MYGUI_ALIGN_H_
#include "MyGUI_Prerequest.h"
#include "MyGUI_Macros.h"
#include "MyGUI_Diagnostic.h"
#include "MyGUI_StringUtility.h"
#include <map>
namespace MyGUI
{
struct MYGUI_EXPORT Align
{
enum Enum
{
HCenter = MYGUI_FLAG_NONE,
VCenter = MYGUI_FLAG_NONE,
Center = HCenter | VCenter,
Left = MYGUI_FLAG(1),
Right = MYGUI_FLAG(2),
HStretch = Left | Right,
Top = MYGUI_FLAG(3),
Bottom = MYGUI_FLAG(4),
VStretch = Top | Bottom,
Stretch = HStretch | VStretch,
Default = Left | Top
};
Align(Enum _value = Default) :
mValue(_value)
{
}
bool isHCenter() const
{
return HCenter == (mValue & HStretch);
}
bool isVCenter() const
{
return VCenter == (mValue & VStretch);
}
bool isCenter() const
{
return Center == (mValue & Stretch);
}
bool isLeft() const
{
return Left == (mValue & HStretch);
}
bool isRight() const
{
return Right == (mValue & HStretch);
}
bool isHStretch() const
{
return HStretch == (mValue & HStretch);
}
bool isTop() const
{
return Top == (mValue & VStretch);
}
bool isBottom() const
{
return Bottom == (mValue & VStretch);
}
bool isVStretch() const
{
return VStretch == (mValue & VStretch);
}
bool isStretch() const
{
return Stretch == (mValue & Stretch);
}
bool isDefault() const
{
return Default == (mValue & Stretch);
}
Align& operator|=(Align const& _other)
{
mValue = (mValue | _other.mValue).mValue;
return *this;
}
friend Align operator|(Enum const& a, Enum const& b)
{
return {Enum((unsigned int)a | (unsigned int)b)};
}
friend Align operator|(Align const& a, Align const& b)
{
return a.mValue | b.mValue;
}
friend bool operator==(Align const& a, Align const& b)
{
return a.mValue == b.mValue;
}
friend bool operator!=(Align const& a, Align const& b)
{
return a.mValue != b.mValue;
}
using MapAlign = std::map<std::string, Align>;
static Align parse(std::string_view _value)
{
Align result(Enum(0));
const MapAlign& map_names = Align::getValueNames();
std::vector<std::string> vec = utility::split(_value);
for (const auto& pos : vec)
{
auto iter = map_names.find(pos);
if (iter != map_names.end())
{
result |= iter->second;
}
}
return result;
}
std::string print() const
{
std::string result;
if (mValue & Left)
{
if (mValue & Right)
result = "HStretch";
else
result = "Left";
}
else if (mValue & Right)
result = "Right";
else
result = "HCenter";
if (mValue & Top)
{
if (mValue & Bottom)
result += " VStretch";
else
result += " Top";
}
else if (mValue & Bottom)
result += " Bottom";
else
result += " VCenter";
return result;
}
friend std::ostream& operator<<(std::ostream& _stream, const Align& _value)
{
_stream << _value.print();
return _stream;
}
friend std::istream& operator>>(std::istream& _stream, Align& _value)
{
_value.mValue = Enum(0);
std::string value;
_stream >> value;
const MapAlign& map_names = Align::getValueNames();
auto iter = map_names.find(value);
if (iter != map_names.end())
_value |= iter->second;
if (!_stream.eof())
{
std::string value2;
_stream >> value2;
iter = map_names.find(value2);
if (iter != map_names.end())
_value |= iter->second;
}
return _stream;
}
int getValue() const
{
return mValue;
}
private:
static const MapAlign& getValueNames()
{
static MapAlign map_names;
if (map_names.empty())
{
#ifndef MYGUI_DONT_USE_OBSOLETE
// OBSOLETE
map_names["ALIGN_HCENTER"] = HCenter;
map_names["ALIGN_VCENTER"] = VCenter;
map_names["ALIGN_CENTER"] = Center;
map_names["ALIGN_LEFT"] = Left;
map_names["ALIGN_RIGHT"] = Right;
map_names["ALIGN_HSTRETCH"] = HStretch;
map_names["ALIGN_TOP"] = Top;
map_names["ALIGN_BOTTOM"] = Bottom;
map_names["ALIGN_VSTRETCH"] = VStretch;
map_names["ALIGN_STRETCH"] = Stretch;
map_names["ALIGN_DEFAULT"] = Default;
#endif
MYGUI_REGISTER_VALUE(map_names, HCenter);
MYGUI_REGISTER_VALUE(map_names, VCenter);
MYGUI_REGISTER_VALUE(map_names, Center);
MYGUI_REGISTER_VALUE(map_names, Left);
MYGUI_REGISTER_VALUE(map_names, Right);
MYGUI_REGISTER_VALUE(map_names, HStretch);
MYGUI_REGISTER_VALUE(map_names, Top);
MYGUI_REGISTER_VALUE(map_names, Bottom);
MYGUI_REGISTER_VALUE(map_names, VStretch);
MYGUI_REGISTER_VALUE(map_names, Stretch);
MYGUI_REGISTER_VALUE(map_names, Default);
}
return map_names;
}
private:
Enum mValue;
};
} // namespace MyGUI
#endif // MYGUI_ALIGN_H_
MyGUI_Diagnostic.h
MYGUI_REGISTER_VALUE
#define MYGUI_REGISTER_VALUE(map, value)
Definition MyGUI_Diagnostic.h:56
MyGUI_Macros.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_StringUtility.h
MyGUI::FontCodeType::Enum
Enum
Definition MyGUI_FontData.h:20
MyGUI::utility::split
std::vector< std::string > split(std::string_view _source, std::string_view _delims="\t\n ")
Definition MyGUI_StringUtility.h:153
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::MYGUI_FLAG
constexpr unsigned int MYGUI_FLAG(uint8_t num)
Definition MyGUI_Macros.h:24
MyGUI::MYGUI_FLAG_NONE
constexpr unsigned int MYGUI_FLAG_NONE
Definition MyGUI_Macros.h:23
MyGUI::Align::parse
static Align parse(std::string_view _value)
Definition MyGUI_Align.h:127
MyGUI::Align::isHStretch
bool isHStretch() const
Definition MyGUI_Align.h:69
MyGUI::Align::Align
Align(Enum _value=Default)
Definition MyGUI_Align.h:39
MyGUI::Align::isVCenter
bool isVCenter() const
Definition MyGUI_Align.h:49
MyGUI::Align::getValue
int getValue() const
Definition MyGUI_Align.h:203
MyGUI::Align::operator<<
friend std::ostream & operator<<(std::ostream &_stream, const Align &_value)
Definition MyGUI_Align.h:174
MyGUI::Align::Enum
Enum
Definition MyGUI_Align.h:22
MyGUI::Align::HStretch
@ HStretch
Definition MyGUI_Align.h:29
MyGUI::Align::HCenter
@ HCenter
Definition MyGUI_Align.h:23
MyGUI::Align::Left
@ Left
Definition MyGUI_Align.h:27
MyGUI::Align::VStretch
@ VStretch
Definition MyGUI_Align.h:33
MyGUI::Align::Bottom
@ Bottom
Definition MyGUI_Align.h:32
MyGUI::Align::Default
@ Default
Definition MyGUI_Align.h:36
MyGUI::Align::VCenter
@ VCenter
Definition MyGUI_Align.h:24
MyGUI::Align::Center
@ Center
Definition MyGUI_Align.h:25
MyGUI::Align::Right
@ Right
Definition MyGUI_Align.h:28
MyGUI::Align::Stretch
@ Stretch
Definition MyGUI_Align.h:35
MyGUI::Align::Top
@ Top
Definition MyGUI_Align.h:31
MyGUI::Align::isTop
bool isTop() const
Definition MyGUI_Align.h:74
MyGUI::Align::print
std::string print() const
Definition MyGUI_Align.h:143
MyGUI::Align::operator>>
friend std::istream & operator>>(std::istream &_stream, Align &_value)
Definition MyGUI_Align.h:180
MyGUI::Align::MapAlign
std::map< std::string, Align > MapAlign
Definition MyGUI_Align.h:125
MyGUI::Align::operator|
friend Align operator|(Enum const &a, Enum const &b)
Definition MyGUI_Align.h:105
MyGUI::Align::isStretch
bool isStretch() const
Definition MyGUI_Align.h:89
MyGUI::Align::isVStretch
bool isVStretch() const
Definition MyGUI_Align.h:84
MyGUI::Align::isRight
bool isRight() const
Definition MyGUI_Align.h:64
MyGUI::Align::isCenter
bool isCenter() const
Definition MyGUI_Align.h:54
MyGUI::Align::isHCenter
bool isHCenter() const
Definition MyGUI_Align.h:44
MyGUI::Align::isLeft
bool isLeft() const
Definition MyGUI_Align.h:59
MyGUI::Align::isBottom
bool isBottom() const
Definition MyGUI_Align.h:79
MyGUI::Align::operator!=
friend bool operator!=(Align const &a, Align const &b)
Definition MyGUI_Align.h:120
MyGUI::Align::isDefault
bool isDefault() const
Definition MyGUI_Align.h:94
MyGUI::Align::operator==
friend bool operator==(Align const &a, Align const &b)
Definition MyGUI_Align.h:115
MyGUI::Align::operator|
friend Align operator|(Align const &a, Align const &b)
Definition MyGUI_Align.h:110
MyGUI::Align::operator|=
Align & operator|=(Align const &_other)
Definition MyGUI_Align.h:99