Widgets.cpp
Go to the documentation of this file.
1#include "Widgets.h"
2
3#include "Impl.h"
4
6{
7
8 Widget::Widget(void* iceWidget) : impl(new WidgetImpl)
9 {
10 impl->desc = static_cast<RemoteGui::Widget*>(iceWidget);
11
12 // Set a default name, so the client code does not need to bother
13 static std::atomic<std::uint64_t> counter{0};
14 std::uint64_t uniqueNumber = counter++;
15 setName(std::to_string(uniqueNumber));
16 }
17
18 void
19 Widget::setName(const std::string& name)
20 {
21 impl->desc->name = name;
22 }
24 const std::string&
26 {
27 return impl->desc->name;
28 }
29
31 {
32 }
33
34 Label::Label(const std::string& text) : Label()
35 {
36 setText(text);
37 }
38
39 void
40 Label::setText(const std::string& text)
41 {
42 impl->setValue(text);
43 }
44
49
50 void
52 {
53 auto* concrete = static_cast<RemoteGui::IntSpinBox*>(impl->desc.get());
54 concrete->min = min;
55 concrete->max = max;
56 }
57
58 void
60 {
61 impl->setValue(newValue);
62 }
63
64 bool
66 {
67 return impl->hasValueChanged();
68 }
69
70 int
72 {
73 return impl->getValue<int>();
74 }
75
79
80 HBoxLayout::HBoxLayout(std::initializer_list<Widget> children) : HBoxLayout()
81 {
82 addChildren(children);
83 }
84
88
89 VBoxLayout::VBoxLayout(std::initializer_list<Widget> children) : VBoxLayout()
90 {
91 addChildren(children);
92 }
93
94 void
96 {
97 impl->addChild(child.impl);
98 }
99
100 void
101 ContainerWidget::addChildren(std::initializer_list<Widget> children)
102 {
103 for (auto& child : children)
104 {
105 addChild(child);
106 }
107 }
108
112
116
118 {
119 impl->desc->defaultValue = makeValue(0);
120 }
121
122 void
123 Button::setLabel(const std::string& label)
124 {
125 auto* concrete = static_cast<RemoteGui::Button*>(impl->desc.get());
126 concrete->label = label;
127 }
128
129 bool
131 {
132 return impl->tab->getButton(getName()).clicked();
133 }
134
136 {
137 setValue("");
138 }
139
140 std::string
142 {
143 return impl->getValue<std::string>();
144 }
145
146 void
147 LineEdit::setValue(const std::string& text)
148 {
149 auto* concrete = static_cast<RemoteGui::LineEdit*>(impl->desc.get());
150 concrete->defaultValue = makeValue(text);
151 }
152
153 bool
155 {
156 return impl->hasValueChanged();
157 }
158
162
163 void
164 ComboBox::addOption(const std::string& option)
165 {
166 auto* concrete = static_cast<RemoteGui::ComboBox*>(impl->desc.get());
167 concrete->options.push_back(option);
168
169 // Set the default value to the first option that is set
170 if (concrete->defaultValue.type == VALUE_VARIANT_EMPTY)
171 {
172 concrete->defaultValue = makeValue(option);
173 }
174 }
175
176 void
177 ComboBox::addOptions(std::initializer_list<std::string> options)
178 {
179 for (auto& option : options)
180 {
182 }
183 }
184
185 void
186 ComboBox::setOptions(const std::vector<std::string>& options)
187 {
188 auto* concrete = static_cast<RemoteGui::ComboBox*>(impl->desc.get());
189 concrete->options = options;
190 if (options.size() > 0)
191 {
192 concrete->defaultValue = makeValue(options.front());
193 }
194 }
195
196 void
197 ComboBox::setValue(const std::string& newValue)
198 {
199 impl->setValue(newValue);
200 }
201
202 std::string
204 {
205 return impl->getValue<std::string>();
206 }
207
208 void
210 {
211 auto* concrete = static_cast<RemoteGui::ComboBox*>(impl->desc.get());
212 if (index < 0 || index >= (int)concrete->options.size())
213 {
214 throw std::runtime_error("ComboBox::setIndex(i) Index i is invalid");
215 }
216 setValue(concrete->options[index]);
217 }
218
219 int
221 {
222 auto* concrete = static_cast<RemoteGui::ComboBox*>(impl->desc.get());
223 std::string value = getValue();
224 for (int i = 0; i < (int)concrete->options.size(); ++i)
225 {
226 if (concrete->options[i] == value)
227 {
228 return i;
229 }
230 }
231 return -1;
232 }
233
234 bool
236 {
237 return impl->hasValueChanged();
238 }
239
241 {
242 setValue(false);
243 }
244
245 bool
247 {
248 return impl->getValue<bool>();
249 }
250
251 void
252 CheckBox::setValue(bool newValue)
253 {
254 impl->setValue(newValue);
255 }
256
257 bool
259 {
260 return impl->hasValueChanged();
261 }
262
267
268 void
269 ToggleButton::setLabel(const std::string& label)
270 {
271 auto* concrete = static_cast<RemoteGui::ToggleButton*>(impl->desc.get());
272 concrete->label = label;
273 }
274
275 bool
277 {
278 return impl->getValue<bool>();
279 }
280
281 void
283 {
284 impl->setValue(newValue);
285 }
286
287 bool
289 {
290 return impl->hasValueChanged();
291 }
292
297
298 void
300 {
301 auto* concrete = static_cast<RemoteGui::IntSlider*>(impl->desc.get());
302 concrete->min = min;
303 concrete->max = max;
304 }
305
306 int
308 {
309 return impl->getValue<int>();
310 }
311
312 void
314 {
315 impl->setValue(newValue);
316 }
317
318 bool
320 {
321 return impl->hasValueChanged();
322 }
323
328
329 void
331 {
332 auto* concrete = static_cast<RemoteGui::FloatSpinBox*>(impl->desc.get());
333 concrete->min = min;
334 concrete->max = max;
335 }
336
337 void
339 {
340 auto* concrete = static_cast<RemoteGui::FloatSpinBox*>(impl->desc.get());
341 concrete->steps = steps;
342 }
343
344 void
346 {
347 auto* concrete = static_cast<RemoteGui::FloatSpinBox*>(impl->desc.get());
348 concrete->decimals = decimals;
349 }
350
351 float
353 {
354 return impl->getValue<float>();
355 }
356
357 void
359 {
360 impl->setValue(newValue);
361 }
362
363 bool
365 {
366 return impl->hasValueChanged();
367 }
368
373
374 void
376 {
377 auto* concrete = static_cast<RemoteGui::FloatSlider*>(impl->desc.get());
378 concrete->min = min;
379 concrete->max = max;
380 }
381
382 void
384 {
385 auto* concrete = static_cast<RemoteGui::FloatSlider*>(impl->desc.get());
386 concrete->steps = steps;
387 }
388
389 float
391 {
392 return impl->getValue<float>();
393 }
394
395 void
396 FloatSlider::setValue(float newValue)
397 {
398 impl->setValue(newValue);
399 }
400
401 bool
403 {
404 return impl->hasValueChanged();
405 }
406
410
411 GroupBox::GroupBox(std::initializer_list<Widget> children) : GroupBox()
412 {
413 for (auto& child : children)
414 {
415 addChild(child);
416 }
417 }
418
419 void
420 GroupBox::setLabel(const std::string& text)
421 {
422 auto* concrete = static_cast<RemoteGui::GroupBox*>(impl->desc.get());
423 concrete->label = text;
424 }
425
426 void
428 {
429 auto* concrete = static_cast<RemoteGui::GroupBox*>(impl->desc.get());
430 concrete->collapsed = collapsed;
431 }
432
436
438 GridLayout::add(const Widget& child, Pos pos, Span span)
439 {
440 impl->addChild(child.impl);
441
442 auto* concrete = static_cast<RemoteGui::GridLayout*>(impl->desc.get());
443 concrete->childrenLayoutInfo.push_back({pos.row, pos.column, span.rows, span.columns});
444
445 return *this;
446 }
447
448} // namespace armarx::RemoteGui::Client
uint8_t index
#define option(type, fn)
ValueVariant makeValue(bool value)
Definition Storage.cpp:144
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
void setLabel(std::string const &label)
Definition Widgets.cpp:123
void addOption(std::string const &option)
Definition Widgets.cpp:164
void setValue(std::string const &newValue)
Definition Widgets.cpp:197
void setOptions(std::vector< std::string > const &options)
Definition Widgets.cpp:186
void addOptions(std::initializer_list< std::string > options)
Definition Widgets.cpp:177
void addChild(Widget const &child)
Definition Widgets.cpp:95
void addChildren(std::initializer_list< Widget > children)
Definition Widgets.cpp:101
void setRange(float min, float max)
Definition Widgets.cpp:375
void setRange(float min, float max)
Definition Widgets.cpp:330
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition Widgets.cpp:438
void setLabel(std::string const &text)
Definition Widgets.cpp:420
void setCollapsed(bool collapsed)
Definition Widgets.cpp:427
void setRange(int min, int max)
Definition Widgets.cpp:299
void setRange(int min, int max)
Definition Widgets.cpp:51
void setText(std::string const &text)
Definition Widgets.cpp:40
void setValue(std::string const &text)
Definition Widgets.cpp:147
void setLabel(std::string const &label)
Definition Widgets.cpp:269
std::string const & getName() const
Definition Widgets.cpp:25
void setName(std::string const &name)
Definition Widgets.cpp:19
std::shared_ptr< WidgetImpl > impl
Definition Widgets.h:28