Commit 767b8611 authored by twanvl's avatar twanvl

reading alignments

parent 3583a8f5
...@@ -34,13 +34,23 @@ RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRec ...@@ -34,13 +34,23 @@ RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRec
// ----------------------------------------------------------------------------- : Reflection stuff // ----------------------------------------------------------------------------- : Reflection stuff
/// Convert a String to an Alignment /// Convert a String to an Alignment
Alignment fromString(const String& str) { Alignment from_string(const String& s) {
int al = 0; int al = ALIGN_TOP_LEFT;
if (s.find(_("left")) !=String::npos) al = ALIGN_LEFT | (al & ALIGN_VERTICAL);
if (s.find(_("center")) !=String::npos) al = ALIGN_CENTER | (al & ALIGN_VERTICAL);
if (s.find(_("right")) !=String::npos) al = ALIGN_RIGHT | (al & ALIGN_VERTICAL);
if (s.find(_("justify")) !=String::npos) al = ALIGN_JUSTIFY | (al & ALIGN_VERTICAL);
if (s.find(_("justify-words")) !=String::npos) al = ALIGN_JUSTIFY_WORDS | (al & ALIGN_VERTICAL);
if (s.find(_("shrink-overflow"))!=String::npos) al = ALIGN_JUSTIFY_OVERFLOW | (al & ~ALIGN_JUSTIFY_OVERFLOW);
if (s.find(_("top")) !=String::npos) al = ALIGN_TOP | (al & ALIGN_HORIZONTAL);
if (s.find(_("middle")) !=String::npos) al = ALIGN_MIDDLE | (al & ALIGN_HORIZONTAL);
if (s.find(_("bottom")) !=String::npos) al = ALIGN_BOTTOM | (al & ALIGN_HORIZONTAL);
if (s.find(_("stretch")) !=String::npos) al = ALIGN_STRETCH;
return static_cast<Alignment>(al); return static_cast<Alignment>(al);
} }
/// Convert an Alignment to a String /// Convert an Alignment to a String
String toString(Alignment align) { String to_string(Alignment align) {
String ret; String ret;
// vertical // vertical
if (align & ALIGN_TOP) ret += _(" top"); if (align & ALIGN_TOP) ret += _(" top");
...@@ -61,11 +71,11 @@ String toString(Alignment align) { ...@@ -61,11 +71,11 @@ String toString(Alignment align) {
// we need custom io, because there can be both a horizontal and a vertical component // we need custom io, because there can be both a horizontal and a vertical component
template <> void Reader::handle(Alignment& align) { template <> void Reader::handle(Alignment& align) {
align = fromString(value); align = from_string(value);
} }
template <> void Writer::handle(const Alignment& align) { template <> void Writer::handle(const Alignment& align) {
handle(toString(align)); handle(to_string(align));
} }
template <> void GetDefaultMember::handle(const Alignment& align) { template <> void GetDefaultMember::handle(const Alignment& align) {
handle(toString(align)); handle(to_string(align));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment