3 #include <SimoxUtility/meta/type_traits/is_any_of.h>
4 #include <SimoxUtility/meta/type_traits/is_std_array.h>
6 #include "../../WidgetBuilder.h"
11 template <
class CL,
class MT, MT CL::*ptr>
17 SetMin(
auto& builder, [[maybe_unused]] MT defaultValue)
25 builder.min(
std::min(MT{0}, defaultValue));
30 SetMax(
auto& builder, [[maybe_unused]] MT defaultValue)
38 builder.max(
std::max(MT{100}, defaultValue));
92 template <
class CL,
class MT, MT CL::*ptr,
class =
void>
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 \
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); \
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)
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>;
117 static_assert(is_spinbox || is_slider,
"the given type for element_widget can't be used");
121 if constexpr (is_slider)
130 element::SetMin(w, 0);
131 element::SetMax(w, 100);
132 element::SetDescription(w);
133 element::SetSteps(w);
134 if constexpr (is_spinbox)
136 element::SetDecimals(w);
140 static_assert(!is_not_undefined_t(element::decimals),
141 "element_decimals can't be set for a slider");
144 return {element::MakeLabel(name), w};
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>;
155 static_assert(is_checkbox || is_toggleButton,
156 "the given type for element_widget can't be used");
160 if constexpr (is_checkbox)
169 w.
label(element::GetLabel(name));
172 "element_min can't be set for bool widgets");
174 "element_max can't be set for bool widgets");
176 element::SetDescription(w);
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");
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>;
212 element::SetMin(w, Eigen::Vector3f(-100, -100, -100));
219 element::SetMax(w, Eigen::Vector3f(100, 100, 100));
224 element::SetSteps(w);
225 if constexpr (is_spinbox)
227 element::SetDecimals(w);
231 static_assert(!is_not_undefined_t(element::decimals),
232 "element_decimals can't be set for a slider");
240 #undef create_specalization_for_type
246 template <
class CL,
class MT, MT CL::*ptr>
251 std::enable_if_t<std::is_integral_v<MT> && !std::is_same_v<MT, bool>>> : std::true_type
255 static std::vector<RemoteGui::WidgetPtr>
256 create(MT val,
const std::string& prefix,
const std::string& name)
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>;
264 static_assert(is_spinbox || is_slider,
265 "the given type for element_widget can't be used");
269 if constexpr (is_slider)
279 element::SetMin(w, 0);
280 element::SetMax(w, 100);
282 element::SetDescription(w);
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");
289 return {element::MakeLabel(name), w};
294 #include <SimoxUtility/meta/enum/adapt_enum.h>
299 template <
class CL,
class MT, MT CL::*ptr>
303 std::enable_if_t<simox::meta::is_enum_adapted_v<MT>>> :
308 static std::vector<RemoteGui::WidgetPtr>
309 create(MT val,
const std::string& prefix,
const std::string& name)
315 "the given type for element_widget can't be used");
318 static_assert(is_undefined_t(element::decimals));
319 static_assert(is_undefined_t(element::steps));
320 static_assert(is_undefined_t(element::label));
324 const auto&
names = simox::meta::enum_names<MT>;
326 builder.addOptions(
names.template names<std::vector>());
327 builder.value(
names.to_name(val));
328 element::SetDescription(builder);
330 return {element::MakeLabel(name), builder};