improve to_json(StyleP)

This commit is contained in:
GenevensiS
2026-01-17 07:55:34 +01:00
parent a741a4d26d
commit 28d5993fe6
13 changed files with 637 additions and 150 deletions
+28 -7
View File
@@ -81,6 +81,9 @@ String to_string(Alignment align) {
ret.resize(ret.size() - 1); // drop trailing ' '
return ret;
}
String alignment_to_string(const Alignment& align) {
return to_string(align);
}
// we need custom io, because there can be both a horizontal and a vertical component
@@ -97,12 +100,12 @@ template <> void GetDefaultMember::handle(const Alignment& align) {
// ----------------------------------------------------------------------------- : Direction
IMPLEMENT_REFLECTION_ENUM(Direction) {
VALUE_N("left to right", LEFT_TO_RIGHT);
VALUE_N("right to left", RIGHT_TO_LEFT);
VALUE_N("top to bottom", TOP_TO_BOTTOM);
VALUE_N("bottom to top", BOTTOM_TO_TOP);
VALUE_N("horizontal", LEFT_TO_RIGHT);
VALUE_N("vertical", TOP_TO_BOTTOM);
VALUE_N("left to right", LEFT_TO_RIGHT);
VALUE_N("right to left", RIGHT_TO_LEFT);
VALUE_N("top to bottom", TOP_TO_BOTTOM);
VALUE_N("bottom to top", BOTTOM_TO_TOP);
VALUE_N("horizontal", LEFT_TO_RIGHT);
VALUE_N("vertical", TOP_TO_BOTTOM);
VALUE_N("top-right to bottom-left", TOP_RIGHT_TO_BOTTOM_LEFT);
VALUE_N("bottom-left to top-right", BOTTOM_LEFT_TO_TOP_RIGHT);
VALUE_N("top-left to bottom-right", TOP_LEFT_TO_BOTTOM_RIGHT);
@@ -121,4 +124,22 @@ RealPoint move_in_direction(Direction dir, const RealPoint& point, const RealSiz
case BOTTOM_RIGHT_TO_TOP_LEFT: return RealPoint(point.x - to_move.width - spacing, point.y - to_move.height - spacing);
default: return point; // should not happen
}
}
}
/// Convert a Direction to a String
String to_string(Direction direction) {
switch (direction) {
case LEFT_TO_RIGHT: return "left to right";
case RIGHT_TO_LEFT: return "right to left";
case TOP_TO_BOTTOM: return "top to bottom";
case BOTTOM_TO_TOP: return "bottom to top";
case TOP_RIGHT_TO_BOTTOM_LEFT: return "top-right to bottom-left";
case BOTTOM_LEFT_TO_TOP_RIGHT: return "bottom-left to top-right";
case TOP_LEFT_TO_BOTTOM_RIGHT: return "top-left to bottom-right";
case BOTTOM_RIGHT_TO_TOP_LEFT: return "bottom-right to top-left";
default: return "left to right";
}
}
String direction_to_string(const Direction& direction) {
return to_string(direction);
}
+4
View File
@@ -57,6 +57,8 @@ RealPoint align_in_rect(Alignment align, const RealSize& to_align, const RealRec
Alignment alignment_from_string(const String&);
String alignment_to_string(const Alignment&);
// ----------------------------------------------------------------------------- : Direction
/// Direction to place something in
@@ -75,3 +77,5 @@ enum Direction {
/** If the direction is horizontal the to_move.width is used, otherwise to_move.height */
RealPoint move_in_direction(Direction dir, const RealPoint& point, const RealSize to_move, double spacing = 0);
String direction_to_string(const Direction&);