LayoutWidgets.h
Go to the documentation of this file.
1#pragma once
2
3#include "Basic.h"
4
6{
7 template <typename Derived>
9 {
10 Derived&
11 appendChild(WidgetPtr const& child)
12 {
13 Derived& this_ = *static_cast<Derived*>(this);
14 this_.widget().children.push_back(child);
15 return this_;
16 }
17
18 Derived&
19 prependChild(WidgetPtr const& child)
20 {
21 Derived& this_ = *static_cast<Derived*>(this);
22 this_.widget().children.insert(this_.widget().children.begin(), child);
23 return this_;
24 }
25
26 Derived&
27 addChild(WidgetPtr const& child)
28 {
29 return appendChild(child);
30 }
31
32 Derived&
33 addChildren(std::vector<WidgetPtr> const& children)
34 {
35 Derived& this_ = *static_cast<Derived*>(this);
36 this_.widget().children.insert(
37 this_.widget().children.end(), children.begin(), children.end());
38 return this_;
39 }
40
41 Derived&
42 children(std::vector<WidgetPtr> const& children)
43 {
44 Derived& this_ = *static_cast<Derived*>(this);
45 this_.widget().children = children;
46 return this_;
47 }
48
49 Derived&
50 child(WidgetPtr const& child)
51 {
52 Derived& this_ = *static_cast<Derived*>(this);
53 this_.widget().children = {child};
54 return this_;
55 }
56
57 const WidgetPtr&
58 child(std::size_t i)
59 {
60 Derived& this_ = *static_cast<Derived*>(this);
61 return this_.widget().children.at(i);
62 }
63
64 Derived&
65 addTextLabel(std::string const& text)
66 {
67 return appendChild(new Label("", makeValue(text), {}, {}, {}));
68 }
69
70 Derived&
72 {
73 return appendChild(new HSpacer);
74 }
75
76 Derived&
78 {
79 return appendChild(new VSpacer);
80 }
81
82 Derived&
84 {
85 return appendChild(new Widget);
86 }
87
88 Derived&
90 {
91 return appendChild(new HLine);
92 }
93
94 Derived&
96 {
97 return appendChild(new VLine);
98 }
99 };
100
102 public NoValueMixin<HBoxLayout, HBoxLayoutBuilder>,
103 public ChildrenMixin<HBoxLayoutBuilder>
104 {
105 using NoValueMixin::NoValueMixin;
106 };
107
109 public NoValueMixin<VBoxLayout, VBoxLayoutBuilder>,
110 public ChildrenMixin<VBoxLayoutBuilder>
111 {
112 using NoValueMixin::NoValueMixin;
113 };
114
116 public NoValueMixin<SimpleGridLayout, SimpleGridLayoutBuilder>,
117 public ChildrenMixin<SimpleGridLayoutBuilder>
118 {
120 using NoValueMixin::NoValueMixin;
121
123 cols(int n)
124 {
125 widget().columns = n;
126 return *this;
127 }
128
130 columns(int n)
131 {
132 widget().columns = n;
133 return *this;
134 }
135
136 using Base::addChild;
137
139 addChild(WidgetPtr const& child, int colspan)
140 {
141 SimpleGridLayoutSpanningChildPtr c = new SimpleGridLayoutSpanningChild;
142 c->children.emplace_back(child);
143 c->columns = colspan;
144 return appendChild(c);
145 }
146
147 using Base::addTextLabel;
148
150 addTextLabel(std::string const& text, int colspan)
151 {
152 return addChild(new Label("", makeValue(text), {}, {}, {}), colspan);
153 }
154
155 using Base::addHSpacer;
156
158 addHSpacer(int colspan)
159 {
160 return addChild(new HSpacer, colspan);
161 }
162
163 using Base::addVSpacer;
164
166 addVSpacer(int colspan)
167 {
168 return addChild(new VSpacer, colspan);
169 }
170
172
174 addEmptyWidget(int colspan)
175 {
176 return addChild(new Widget, colspan);
177 }
178
179 using Base::addHLine;
180
182 addHLine(int colspan)
183 {
184 return addChild(new HLine, colspan);
185 }
186
187 using Base::addVLine;
188
190 addVLine(int colspan)
191 {
192 return addChild(new VLine, colspan);
193 }
194 };
195
197 public NoValueMixin<GroupBox, GroupBoxBuilder>,
198 public ChildrenMixin<GroupBoxBuilder>,
199 public LabelMixin<GroupBoxBuilder>
200 {
201 GroupBoxBuilder(const std::string& name) : NoValueMixin(name)
202 {
203 label(name);
204 }
205
207 collapsed(bool isCollapsed = true)
208 {
209 this->widget().collapsed = isCollapsed;
210 return *this;
211 }
212 };
213
214 struct GridLayoutBuilder : public NoValueMixin<GridLayout, GridLayoutBuilder>
215 //can't use ChildrenMixin since it is missing the index information
216 {
217 using NoValueMixin::NoValueMixin;
218
220 addChild(WidgetPtr const& child, int row, int col, int spanRow = 1, int spanCol = 1)
221 {
222 this->widget().children.emplace_back(child);
223 this->widget().childrenLayoutInfo.push_back({row, col, spanRow, spanCol});
224 return *this;
225 }
226
228 addTextLabel(std::string const& text, int row, int col, int spanRow = 1, int spanCol = 1)
229 {
230 return addChild(new Label("", makeValue(text), {}, {}, {}), row, col, spanRow, spanCol);
231 }
232
234 addHSpacer(int row, int col, int spanRow = 1, int spanCol = 1)
235 {
236 return addChild(new HSpacer, row, col, spanRow, spanCol);
237 }
238
240 addVSpacer(int row, int col, int spanRow = 1, int spanCol = 1)
241 {
242 return addChild(new VSpacer, row, col, spanRow, spanCol);
243 }
244
246 addEmptyWidget(int row, int col, int spanRow = 1, int spanCol = 1)
247 {
248 return addChild(new Widget, row, col, spanRow, spanCol);
249 }
250
252 addHLine(int row, int col, int spanRow = 1, int spanCol = 1)
253 {
254 return addChild(new HLine, row, col, spanRow, spanCol);
255 }
256
258 addVLine(int row, int col, int spanRow = 1, int spanCol = 1)
259 {
260 return addChild(new VLine, row, col, spanRow, spanCol);
261 }
262 };
263} // namespace armarx::RemoteGui::detail
264
265namespace armarx::RemoteGui
266{
267 inline detail::HBoxLayoutBuilder
268 makeHBoxLayout(std::string const& name = "")
269 {
270 return detail::HBoxLayoutBuilder(name);
271 }
272
273 inline detail::SimpleGridLayoutBuilder
274 makeSimpleGridLayout(std::string const& name = "")
275 {
277 }
278
279 inline detail::GridLayoutBuilder
280 makeGridLayout(std::string const& name = "")
281 {
282 return detail::GridLayoutBuilder(name);
283 }
284
285 inline detail::VBoxLayoutBuilder
286 makeVBoxLayout(std::string const& name = "")
287 {
288 return detail::VBoxLayoutBuilder(name);
289 }
290
291 inline detail::GroupBoxBuilder
292 makeGroupBox(std::string const& name = "")
293 {
294 return detail::GroupBoxBuilder(name);
295 }
296} // namespace armarx::RemoteGui
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Definition Bitmap.cpp:801
constexpr T c
detail::VBoxLayoutBuilder makeVBoxLayout(std::string const &name="")
ValueVariant makeValue(bool value)
Definition Storage.cpp:144
detail::HBoxLayoutBuilder makeHBoxLayout(std::string const &name="")
detail::GridLayoutBuilder makeGridLayout(std::string const &name="")
detail::SimpleGridLayoutBuilder makeSimpleGridLayout(std::string const &name="")
detail::GroupBoxBuilder makeGroupBox(std::string const &name="")
Derived & prependChild(WidgetPtr const &child)
Derived & addChildren(std::vector< WidgetPtr > const &children)
Derived & addChild(WidgetPtr const &child)
const WidgetPtr & child(std::size_t i)
Derived & addTextLabel(std::string const &text)
Derived & appendChild(WidgetPtr const &child)
SimpleGridLayoutBuilder & children(std::vector< WidgetPtr > const &children)
SimpleGridLayoutBuilder & child(WidgetPtr const &child)
GridLayoutBuilder & addHSpacer(int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addChild(WidgetPtr const &child, int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addTextLabel(std::string const &text, int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addHLine(int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addVSpacer(int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addVLine(int row, int col, int spanRow=1, int spanCol=1)
GridLayoutBuilder & addEmptyWidget(int row, int col, int spanRow=1, int spanCol=1)
GroupBoxBuilder & collapsed(bool isCollapsed=true)
GroupBoxBuilder & label(std::string const &label)
Definition Basic.h:216
SimpleGridLayoutBuilder & addTextLabel(std::string const &text, int colspan)
SimpleGridLayoutBuilder & addHSpacer(int colspan)
SimpleGridLayoutBuilder & addChild(WidgetPtr const &child, int colspan)
SimpleGridLayoutBuilder & addHLine(int colspan)
SimpleGridLayoutBuilder & addEmptyWidget(int colspan)
ChildrenMixin< SimpleGridLayoutBuilder > Base
SimpleGridLayoutBuilder & addVLine(int colspan)
SimpleGridLayoutBuilder & addVSpacer(int colspan)