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