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>
15 static void SetMin(
auto& builder, [[maybe_unused]] MT defaultValue)
23 builder.min(
std::min(MT{0}, defaultValue));
26 static void SetMax(
auto& builder, [[maybe_unused]] MT defaultValue)
34 builder.max(
std::max(MT{100}, defaultValue));
59 static std::string
GetLabel(
const std::string& name)
78 template<
class CL,
class MT, MT CL::* ptr,
class =
void>
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 \
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); \
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) \
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>;
101 static_assert(is_spinbox || is_slider,
"the given type for element_widget can't be used");
105 if constexpr(is_slider)
114 element::SetMin(w, 0);
115 element::SetMax(w, 100);
116 element::SetDescription(w);
117 element::SetSteps(w);
118 if constexpr(is_spinbox)
120 element::SetDecimals(w);
124 static_assert(!is_not_undefined_t(element::decimals),
"element_decimals can't be set for a slider");
127 return {element::MakeLabel(name), w};
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>;
137 static_assert(is_checkbox || is_toggleButton,
"the given type for element_widget can't be used");
141 if constexpr(is_checkbox)
150 w.
label(element::GetLabel(name));
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");
155 element::SetDescription(w);
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");
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>;
190 element::SetMin(w, Eigen::Vector3f(-100, -100, -100));
195 element::SetMax(w, Eigen::Vector3f(100, 100, 100));
198 element::SetSteps(w);
199 if constexpr(is_spinbox)
201 element::SetDecimals(w);
205 static_assert(!is_not_undefined_t(element::decimals),
"element_decimals can't be set for a slider");
213 #undef create_specalization_for_type
220 template<
class CL,
class MT, MT CL::* ptr>
223 std::enable_if_t < std::is_integral_v<MT>&& !std::is_same_v<MT, bool >>
229 static std::vector<RemoteGui::WidgetPtr>
230 create(MT val,
const std::string& prefix,
const std::string& name)
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>;
237 static_assert(is_spinbox || is_slider,
"the given type for element_widget can't be used");
241 if constexpr(is_slider)
251 element::SetMin(w, 0);
252 element::SetMax(w, 100);
254 element::SetDescription(w);
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");
259 return {element::MakeLabel(name), w};
264 #include <SimoxUtility/meta/enum/adapt_enum.h>
268 template<
class CL,
class MT, MT CL::* ptr>
271 std::enable_if_t<simox::meta::is_enum_adapted_v<MT>>
277 static std::vector<RemoteGui::WidgetPtr>
278 create(MT val,
const std::string& prefix,
const std::string& name)
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"
287 static_assert(is_undefined_t(element::decimals));
288 static_assert(is_undefined_t(element::steps));
289 static_assert(is_undefined_t(element::label));
293 const auto&
names = simox::meta::enum_names<MT>;
295 builder.addOptions(
names.template names<std::vector>());
296 builder.value(
names.to_name(val));
297 element::SetDescription(builder);
299 return {element::MakeLabel(name), builder};