MakeGuiElement.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <SimoxUtility/meta/type_traits/is_any_of.h>
4 #include <SimoxUtility/meta/type_traits/is_std_array.h>
5 
6 #include "../../WidgetBuilder.h"
7 #include "../Common.h"
8 
9 namespace armarx::meta::cfg
10 {
11  template <class CL, class MT, MT CL::*ptr>
13  {
15 
16  static void
17  SetMin(auto& builder, [[maybe_unused]] MT defaultValue)
18  {
19  if constexpr (is_not_undefined_t(element::min))
20  {
21  builder.min(element::min);
22  }
23  else
24  {
25  builder.min(std::min(MT{0}, defaultValue));
26  }
27  }
28 
29  static void
30  SetMax(auto& builder, [[maybe_unused]] MT defaultValue)
31  {
32  if constexpr (is_not_undefined_t(element::max))
33  {
34  builder.max(element::max);
35  }
36  else
37  {
38  builder.max(std::max(MT{100}, defaultValue));
39  }
40  }
41 
42  static void
43  SetDescription(auto& builder)
44  {
45  if constexpr (is_not_undefined_t(element::description))
46  {
47  builder.toolTip(element::description);
48  }
49  }
50 
51  static void
52  SetSteps(auto& builder)
53  {
54  if constexpr (is_not_undefined_t(element::steps))
55  {
56  builder.steps(element::steps);
57  }
58  }
59 
60  static void
61  SetDecimals(auto& builder)
62  {
63  if constexpr (is_not_undefined_t(element::decimals))
64  {
65  builder.decimals(element::decimals);
66  }
67  }
68 
69  static std::string
70  GetLabel(const std::string& name)
71  {
72  if constexpr (is_not_undefined_t(element::label))
73  {
74  return element::label;
75  }
76  return name;
77  }
78 
79  static auto
80  MakeLabel(const std::string& name)
81  {
82  auto b = RemoteGui::makeTextLabel(GetLabel(name));
83  SetDescription(b);
84  return b;
85  }
86  };
87 } // namespace armarx::meta::cfg
88 
89 //element def (variant types except int)
90 namespace armarx::meta::cfg
91 {
92  template <class CL, class MT, MT CL::*ptr, class = void>
93  struct gui_definition_create_element : std::false_type
94  {
95  };
96 
97 #define create_specalization_for_type(type) \
98  template <class CL, type CL::*ptr> \
99  struct gui_definition_create_element<CL, type, ptr, void> : std::true_type \
100  { \
101  using element = gui_definition_create_element_details<CL, type, ptr>; \
102  static std::vector<RemoteGui::WidgetPtr> \
103  create(type val, const std::string& prefix, const std::string& name); \
104  }; \
105  template <class CL, type CL::*ptr> \
106  std::vector<RemoteGui::WidgetPtr> gui_definition_create_element<CL, type, ptr>::create( \
107  type val, const std::string& prefix, const std::string& name)
108 
110  {
111  ARMARX_TRACE;
112  using widget_t = typename element::widget_t;
113  static constexpr bool is_spinbox =
114  simox::meta::is_any_of_v<widget_t, RemoteGui::FloatSpinBox, undefined_t>;
115  static constexpr bool is_slider = std::is_same_v<RemoteGui::FloatSlider, widget_t>;
116 
117  static_assert(is_spinbox || is_slider, "the given type for element_widget can't be used");
118 
119  auto w = [&]
120  {
121  if constexpr (is_slider)
122  {
123  return RemoteGui::makeFloatSlider(ConcatID(prefix, name)).value(val);
124  }
125  else
126  {
127  return RemoteGui::makeFloatSpinBox(ConcatID(prefix, name)).value(val);
128  }
129  }();
130  element::SetMin(w, 0);
131  element::SetMax(w, 100);
132  element::SetDescription(w);
133  element::SetSteps(w);
134  if constexpr (is_spinbox)
135  {
136  element::SetDecimals(w);
137  }
138  else
139  {
140  static_assert(!is_not_undefined_t(element::decimals),
141  "element_decimals can't be set for a slider");
142  }
143 
144  return {element::MakeLabel(name), w};
145  }
146 
148  {
149  ARMARX_TRACE;
150  using widget_t = typename element::widget_t;
151  static constexpr bool is_checkbox =
152  simox::meta::is_any_of_v<widget_t, RemoteGui::CheckBox, undefined_t>;
153  static constexpr bool is_toggleButton = std::is_same_v<RemoteGui::ToggleButton, widget_t>;
154 
155  static_assert(is_checkbox || is_toggleButton,
156  "the given type for element_widget can't be used");
157 
158  auto w = [&]
159  {
160  if constexpr (is_checkbox)
161  {
162  return RemoteGui::makeCheckBox(ConcatID(prefix, name)).value(val);
163  }
164  else
165  {
166  return RemoteGui::makeToggleButton(ConcatID(prefix, name)).value(val);
167  }
168  }();
169  w.label(element::GetLabel(name));
170 
171  static_assert(!is_not_undefined_t(element::min),
172  "element_min can't be set for bool widgets");
173  static_assert(!is_not_undefined_t(element::max),
174  "element_max can't be set for bool widgets");
175 
176  element::SetDescription(w);
177 
178  static_assert(!is_not_undefined_t(element::decimals),
179  "element_decimals can't be set for bool widgets");
180  static_assert(!is_not_undefined_t(element::steps),
181  "element_steps can't be set for bool widgets");
182  return {w};
183  }
184 
186  {
187  ARMARX_TRACE;
188  return {
190  RemoteGui::makeLineEdit(ConcatID(prefix, name)).value(val) ///TODO
191  };
192  }
193 
195  {
196  ARMARX_TRACE;
197  return {
199  RemoteGui::makePosRPYSpinBoxes(ConcatID(prefix, name)).value(val) ///TODO
200  };
201  }
202 
204  {
205  ARMARX_TRACE;
206  using widget_t = typename element::widget_t;
207  static constexpr bool is_spinbox =
208  simox::meta::is_any_of_v<widget_t, RemoteGui::FloatSpinBox, undefined_t>;
209  auto w = RemoteGui::makeVector3fSpinBoxes(ConcatID(prefix, name)).value(val);
210  if constexpr (is_not_undefined_t(element::min))
211  {
212  element::SetMin(w, Eigen::Vector3f(-100, -100, -100));
213  }
214  else
215  {
216  }
217  if constexpr (is_not_undefined_t(element::max))
218  {
219  element::SetMax(w, Eigen::Vector3f(100, 100, 100));
220  }
221  else
222  {
223  }
224  element::SetSteps(w);
225  if constexpr (is_spinbox)
226  {
227  element::SetDecimals(w);
228  }
229  else
230  {
231  static_assert(!is_not_undefined_t(element::decimals),
232  "element_decimals can't be set for a slider");
233  }
234  return {
235  RemoteGui::makeTextLabel(name), w ///TODO
236 
237  };
238  }
239 
240 #undef create_specalization_for_type
241 } // namespace armarx::meta::cfg
242 
243 //element def (integral types except bool)
244 namespace armarx::meta::cfg
245 {
246  template <class CL, class MT, MT CL::*ptr>
248  CL,
249  MT,
250  ptr,
251  std::enable_if_t<std::is_integral_v<MT> && !std::is_same_v<MT, bool>>> : std::true_type
252  {
254 
255  static std::vector<RemoteGui::WidgetPtr>
256  create(MT val, const std::string& prefix, const std::string& name)
257  {
258  ARMARX_TRACE;
259  using widget_t = typename element::widget_t;
260  static constexpr bool is_spinbox =
261  simox::meta::is_any_of_v<widget_t, RemoteGui::IntSpinBox, undefined_t>;
262  static constexpr bool is_slider = std::is_same_v<RemoteGui::IntSlider, widget_t>;
263 
264  static_assert(is_spinbox || is_slider,
265  "the given type for element_widget can't be used");
266 
267  auto w = [&]
268  {
269  if constexpr (is_slider)
270  {
271  return RemoteGui::makeIntSlider(ConcatID(prefix, name)).value(val);
272  }
273  else
274  {
275  return RemoteGui::makeIntSpinBox(ConcatID(prefix, name)).value(val);
276  }
277  }();
278 
279  element::SetMin(w, 0);
280  element::SetMax(w, 100);
281 
282  element::SetDescription(w);
283 
284  static_assert(!is_not_undefined_t(element::decimals),
285  "element_decimals can't be set for int spin boxes or sliders");
286  static_assert(!is_not_undefined_t(element::steps),
287  "element_steps can't be set for int spin boxes or sliders");
288 
289  return {element::MakeLabel(name), w};
290  }
291  };
292 } // namespace armarx::meta::cfg
293 
294 #include <SimoxUtility/meta/enum/adapt_enum.h>
295 
296 //element def (enum types)
297 namespace armarx::meta::cfg
298 {
299  template <class CL, class MT, MT CL::*ptr>
301  MT,
302  ptr,
303  std::enable_if_t<simox::meta::is_enum_adapted_v<MT>>> :
304  std::true_type
305  {
307 
308  static std::vector<RemoteGui::WidgetPtr>
309  create(MT val, const std::string& prefix, const std::string& name)
310  {
311  ARMARX_TRACE;
312  static_assert(simox::meta::is_any_of_v<typename element::widget_t,
313  RemoteGui::ComboBox,
314  undefined_t>,
315  "the given type for element_widget can't be used");
316  static_assert(is_undefined_t(element::min));
317  static_assert(is_undefined_t(element::max));
318  static_assert(is_undefined_t(element::decimals));
319  static_assert(is_undefined_t(element::steps));
320  static_assert(is_undefined_t(element::label));
321 
322  auto builder = RemoteGui::makeComboBox(ConcatID(prefix, name));
323 
324  const auto& names = simox::meta::enum_names<MT>;
325 
326  builder.addOptions(names.template names<std::vector>());
327  builder.value(names.to_name(val));
328  element::SetDescription(builder);
329 
330  return {element::MakeLabel(name), builder};
331  }
332  };
333 } // namespace armarx::meta::cfg
armarx::RemoteGui::makeIntSlider
detail::IntSliderBuilder makeIntSlider(std::string const &name)
Definition: IntegerWidgets.h:46
armarx::meta::cfg::gui_definition_create_element< CL, MT, ptr, std::enable_if_t< std::is_integral_v< MT > &&!std::is_same_v< MT, bool > > >::create
static std::vector< RemoteGui::WidgetPtr > create(MT val, const std::string &prefix, const std::string &name)
Definition: MakeGuiElement.h:256
armarx::RemoteGui::makeVector3fSpinBoxes
detail::Vector3fSpinBoxesBuilder makeVector3fSpinBoxes(std::string const &name, float limpos=1000)
Definition: Vector3fWidgets.h:140
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::RemoteGui::makeLineEdit
detail::LineEditBuilder makeLineEdit(std::string const &name)
Definition: StringWidgets.h:55
armarx::meta::cfg::element_details::label
static constexpr auto label
Definition: element_details.h:72
armarx::meta::cfg::gui_definition_create_element
Definition: MakeGuiElement.h:93
armarx::RemoteGui::makeTextLabel
detail::LabelBuilder makeTextLabel(std::string const &text)
Definition: StaticWidgets.h:24
armarx::meta::cfg::element_details::max
static constexpr auto max
Definition: element_details.h:67
armarx::meta::cfg::create_specalization_for_type
create_specalization_for_type(float)
Definition: MakeGuiElement.h:109
armarx::meta::cfg::element_details::decimals
static constexpr auto decimals
Definition: element_details.h:70
armarx::meta::cfg::gui_definition_create_element< CL, MT, ptr, std::enable_if_t< simox::meta::is_enum_adapted_v< MT > > >::create
static std::vector< RemoteGui::WidgetPtr > create(MT val, const std::string &prefix, const std::string &name)
Definition: MakeGuiElement.h:309
armarx::meta::cfg
Definition: PluginCfgStruct.h:31
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::meta::cfg::gui_definition_create_element_details::SetMin
static void SetMin(auto &builder, [[maybe_unused]] MT defaultValue)
Definition: MakeGuiElement.h:17
armarx::RemoteGui::makeIntSpinBox
detail::IntSpinBoxBuilder makeIntSpinBox(std::string const &name)
Definition: IntegerWidgets.h:40
armarx::meta::cfg::gui_definition_create_element_details::GetLabel
static std::string GetLabel(const std::string &name)
Definition: MakeGuiElement.h:70
armarx::RemoteGui::makeCheckBox
detail::CheckBoxBuilder makeCheckBox(std::string const &name)
Definition: BoolWidgets.h:27
armarx::RemoteGui::makeFloatSlider
detail::FloatSliderBuilder makeFloatSlider(std::string const &name)
Definition: FloatWidgets.h:64
armarx::meta::cfg::gui_definition_create_element_details::SetDecimals
static void SetDecimals(auto &builder)
Definition: MakeGuiElement.h:61
armarx::RemoteGui::detail::ValueMixin::value
Derived & value(ValueT const &value)
Definition: Basic.h:84
armarx::RemoteGui::detail::LabelMixin::label
Derived & label(std::string const &label)
Definition: Basic.h:216
armarx::meta::cfg::ConcatID
std::string ConcatID(const std::string &prefix, const std::string &suffix)
Definition: ConcatID.h:8
max
T max(T t1, T t2)
Definition: gdiam.h:51
armarx::meta::cfg::gui_definition_create_element_details::MakeLabel
static auto MakeLabel(const std::string &name)
Definition: MakeGuiElement.h:80
armarx::meta::cfg::gui_definition_create_element_details::SetDescription
static void SetDescription(auto &builder)
Definition: MakeGuiElement.h:43
armarx::meta::cfg::gui_definition_create_element_details::SetMax
static void SetMax(auto &builder, [[maybe_unused]] MT defaultValue)
Definition: MakeGuiElement.h:30
armarx::RemoteGui::makePosRPYSpinBoxes
detail::PosRPYSpinBoxesBuilder makePosRPYSpinBoxes(std::string const &name, float limpos=1000, float limrpy=M_PI)
Definition: Matrix4fWidgets.h:87
armarx::meta::cfg::element_details
Definition: element_details.h:59
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:13
armarx::meta::cfg::element_details::widget_t
element_widget< CL, MT, ptr > widget_t
Definition: element_details.h:84
std
Definition: Application.h:66
armarx::meta::cfg::element_details::description
static constexpr auto description
Definition: element_details.h:68
armarx::RemoteGui::makeComboBox
detail::ComboBoxBuilder makeComboBox(std::string const &name)
Definition: StringWidgets.h:61
armarx::meta::cfg::element_details::steps
static constexpr auto steps
Definition: element_details.h:71
min
T min(T t1, T t2)
Definition: gdiam.h:44
armarx::meta::cfg::element_details::min
static constexpr auto min
Definition: element_details.h:66
armarx::meta::cfg::gui_definition_create_element_details::SetSteps
static void SetSteps(auto &builder)
Definition: MakeGuiElement.h:52
armarx::RemoteGui::makeFloatSpinBox
detail::FloatSpinBoxBuilder makeFloatSpinBox(std::string const &name)
Definition: FloatWidgets.h:58
armarx::meta::cfg::gui_definition_create_element_details
Definition: MakeGuiElement.h:12
armarx::RemoteGui::makeToggleButton
detail::ToggleButtonBuilder makeToggleButton(std::string const &name)
Definition: BoolWidgets.h:35
armarx::meta::cfg::undefined_t
::simox::meta::undefined_t undefined_t
Definition: common.h:17