MakeGuiConfigStruct.h
Go to the documentation of this file.
1#pragma once
2
3#include "MakeGuiElement.h"
4
5namespace armarx::meta::cfg
6{
7 template <class T, class = void>
8 struct gui_definition_create : std::false_type
9 {
10 };
11} // namespace armarx::meta::cfg
12
14{
15 template <class VarName, class CL, class MT, MT CL::*ptr>
16 std::vector<RemoteGui::WidgetPtr>
18 const boost::hana::pair<VarName, boost::hana::struct_detail::member_ptr<MT CL::*, ptr>>&,
19 const std::string& prefix,
20 const CL& val)
21 {
23 const auto varname = hana::to<char const*>(VarName{});
24 const auto& var = val.*ptr;
25 using def_create = gui_definition_create<MT>;
27 if constexpr (def_create::value)
28 {
29 return {def_create::create(var, prefix, varname)};
30 }
31 else if constexpr (elem_create::value)
32 {
33 return elem_create::create(var, prefix, varname);
34 }
35 else
36 {
37 static_assert(!std::is_same_v<MT, MT>, "this member type is not handeled!");
38 return {};
39 }
40 }
41} // namespace armarx::meta::cfg::detail
42
43namespace armarx::meta::cfg
44{
45 template <class T>
46 struct gui_definition_create<T, std::enable_if_t<meta::cfg::gui_definition_enabled_v<T>>> :
47 std::true_type
48 {
49 template <class OverrideLayoutT = undefined_t>
50 static auto
51 create(const T& val, const std::string& prefix, const std::string& name)
52 {
53 using layout_t = first_not_undefined_t<OverrideLayoutT,
55 RemoteGui::GroupBox // default value
56 >;
57
59 namespace hana = boost::hana;
60 static constexpr auto accessors = hana::accessors<T>();
61
62 auto [widget, addChildren] = [&]
63 {
64 static constexpr bool grpbox = std::is_same_v<layout_t, RemoteGui::GroupBox>;
65 static constexpr bool sgrid = std::is_same_v<layout_t, RemoteGui::SimpleGridLayout>;
66 static constexpr bool vbox = std::is_same_v<layout_t, RemoteGui::VBoxLayout>;
67 static constexpr bool hbox = std::is_same_v<layout_t, RemoteGui::HBoxLayout>;
68
69 if constexpr (grpbox || sgrid)
70 {
71 RemoteGui::SimpleGridLayoutPtr l = new RemoteGui::SimpleGridLayout;
72 l->columns = 2;
73 auto add = [l](const auto& cs)
74 {
75 if (cs.size() == 1)
76 {
77 l->children.emplace_back(new RemoteGui::Widget);
78 l->children.emplace_back(cs.front());
79 }
80 else
81 {
82 l->children.insert(l->children.end(), cs.begin(), cs.end());
83 }
84 };
85 if constexpr (grpbox)
86 {
87 return std::make_pair(
88 RemoteGui::makeGroupBox(ConcatID(prefix, name)).label(name).addChild(l),
89 add);
90 }
91 else
92 {
93 return std::make_pair(l, add);
94 }
95 }
96 else if constexpr (vbox || hbox)
97 {
98 RemoteGui::WidgetPtr l = new layout_t;
99 auto add = [l](const auto& cs)
100 { l->children.insert(l->children.end(), cs.begin(), cs.end()); };
101 return std::make_pair(l, add);
102 }
103 else
104 {
105 static_assert(!std::is_same_v<T, T>,
106 "the given type for config_layout can't be used");
107 }
108 }();
109
110 hana::for_each(accessors,
111 [&, addChildren = std::ref(addChildren)](auto& e)
112 {
114 using elem_det = decltype(armarx::meta::cfg::to_element_detail(e));
115 if constexpr (!elem_det::no_remote_gui)
116 {
117 addChildren(
118 detail::DoCreateElement(e, ConcatID(prefix, name), val));
119 }
120 else
121 {
122 // do nothing
123 }
124 });
125
126 return widget;
127 }
128
129 static auto
130 create(const T& val, const std::string& prefix, const std::string& name)
131 {
132 return create<>(val, prefix, name);
133 }
134 };
135} // namespace armarx::meta::cfg
detail::GroupBoxBuilder makeGroupBox(std::string const &name="")
std::vector< RemoteGui::WidgetPtr > DoCreateElement(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr > > &, const std::string &prefix, const CL &val)
::simox::meta::first_not_undefined_t< Ts... > first_not_undefined_t
Definition common.h:20
element_details< CL, MT, ptr > to_element_detail(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr > > &)
std::string ConcatID(const std::string &prefix, const std::string &suffix)
Definition ConcatID.h:8
static auto create(const T &val, const std::string &prefix, const std::string &name)
static auto create(const T &val, const std::string &prefix, const std::string &name)
#define ARMARX_TRACE
Definition trace.h:77
#define ARMARX_TRACE_LITE
Definition trace.h:98