Loading...
Searching...
No Matches
LayoutSVG.h
1/*
2
3MIT License
4
5Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31/*
32 * TreeSVG.h
33 *
34 * Created on: Nov, 2024
35 * Author: mpeura
36 */
37
38#ifndef DRAIN_LAYOUT_SVG
39#define DRAIN_LAYOUT_SVG
40
41#include <drain/util/EnumFlagger.h>
42
43#include "Direction.h"
44
45#include "TreeSVG.h"
46
47namespace drain {
48
49namespace image {
50
51
52
54
57class LayoutSVG {
58
59public:
60
62
66 enum Direction {
67 UNDEFINED_DIRECTION=0,
68 /*
69 RIGHT = 1,
70 LEFT = 2,
71 DOWN = 4,
72 UP = 8,
73 INCR = RIGHT | DOWN,
74 DECR = LEFT | UP,
75 */
76 /*
77 INCR_HORZ = 1,
78 INCR_VERT = 2,
79 INCR = INCR_HORZ | INCR_VERT,
80 DECR_HORZ = 4,
81 DECR_VERT = 8,
82 DECR = DECR_HORZ | DECR_VERT,
83 */
84 INCR = 1,
85 DECR = 2,
86 /*
87 INCR_HORZ = 1+4,
88 DECR_HORZ = 2+4,
89 INCR_VERT = 1+8,
90 DECR_VERT = 2+8,
91 */
92 };
93
94 enum DirectionHorz {
95 //UNDEFINED_DIRECTION=0,
96 RIGHT = INCR,
97 LEFT = DECR,
98 };
99
100 enum DirectionVert {
101 //tDEFINED_DIRECTION=0,
102 DOWN = INCR,
103 UP = DECR,
104 };
105
106
109 STACK_LAYOUT, // Align elements in rows or columns. (Alternate the axis in nesting STACK_LAYOUT levels)
110 ADAPTER, // Translate this group object such that the upper right corner of graphics are in the origin (0,0).
111 // ALIGN, // Align this object, with applicable rules and preferences (populate me with align instructions, unless already set)
112 /* Moved to AlignSVG, for setAlign{Class}(AlignSVG::enum)
113 COMPOUND, // Internal elements are already aligned, bypass recursion.
114 FIXED, // Absolute position - do not align. (Do not adjust coordinates, but allow internal recursion.
115 INDEPENDENT, // No anchoring allowed – but inclusion by collective bounding box applies, unless NEUTRAL.
116 NEUTRAL, // Excluded from the collective bounding box – but anchoring supported, unless INDEPENDENT)
117 */
118 //
119 CROP, // minimize bbox covering all the included objects. \see GroupType::FIXED
120 // Future options
121 // HEADER, // Requests alignment as a title, typically title box combining TEXT (and TSPAN) on a background RECT
122 };
123
124
127
128protected:
129
130 AxisFlagger orientation = AlignBase::HORZ;
131
132 DirectionFlagger direction = INCR;
133
134 inline
135 LayoutSVG(AlignBase::Axis v=AlignBase::HORZ, Direction d=INCR) : orientation(v), direction(d) {
136 }
137
138 inline
139 LayoutSVG(const LayoutSVG & layout) : orientation(layout.orientation), direction(layout.direction){
140 }
141
143
147 template <typename V>
148 inline
149 void setOrientation(const V & axis){
150 orientation.set(Enum<AlignBase::Axis>::getValue(axis));
151 }
152
154
158 template <typename D>
159 inline
160 void setDirection(const D & dir){
161 direction.set(Enum<LayoutSVG::Direction>::getValue(dir));
162 }
163
165
168 template <typename D, typename V>
169 inline
170 void set(const D & d, const V &v){
171 direction.set(Enum<LayoutSVG::Direction>::getValue(d));
172 orientation.set(Enum<AlignBase::Axis>::getValue(v));
173 }
174
175 /*
176 static inline
177 Direction flip(Direction ...){
178 };
179 */
180};
181
182
183} // image::
184
185DRAIN_ENUM_DICT(image::LayoutSVG::Direction);
186DRAIN_ENUM_DICT(image::LayoutSVG::DirectionHorz);
187DRAIN_ENUM_DICT(image::LayoutSVG::DirectionVert);
188DRAIN_ENUM_DICT(image::LayoutSVG::GroupType);
189
190DRAIN_GETKEY_ENUM(image::TreeSVG, image::LayoutSVG::GroupType)
191
192DRAIN_ENUM_CLASSXML(image::LayoutSVG::GroupType)
193
194
195namespace image {
196
197DRAIN_ENUM_OSTREAM(image::LayoutSVG::Direction)
198DRAIN_ENUM_OSTREAM(image::LayoutSVG::DirectionHorz)
199DRAIN_ENUM_OSTREAM(image::LayoutSVG::DirectionVert)
200DRAIN_ENUM_OSTREAM(LayoutSVG::GroupType)
201
202}
203
204} // drain::
205
206
207#endif // DRAIN_ALIGN_SVG_H_
208
Flagger accepting values of enum type E.
Definition EnumFlagger.h:56
Higher level controller for setting alignments.
Definition LayoutSVG.h:57
void setDirection(const D &dir)
Set direction: coordinates increasing or decreasing.
Definition LayoutSVG.h:160
Direction
Direction for "Stacked", horziontally or vertically sequentially aligned layout.
Definition LayoutSVG.h:66
GroupType
Experimental SVG style classes (requests)
Definition LayoutSVG.h:108
void setOrientation(const V &axis)
Set orientation: horizontal or vertical axis.
Definition LayoutSVG.h:149
void set(const D &d, const V &v)
Set direction and orientation.
Definition LayoutSVG.h:170
Definition Data.h:1473
A container for a static dictionary of enumeration values.
Definition Enum.h:51
Definition Direction.h:99