-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWidget.h
86 lines (64 loc) · 1.87 KB
/
Widget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include <mc_control/ControllerClient.h>
#include <imgui.h>
#include <memory>
#include <string>
// #ifdef SPDLOG_FMT_EXTERNAL
// # include <fmt/ranges.h>
// #else
// # include <spdlog/fmt/bundled/ranges.h>
// #endif
// #include <mc_rtc/fmt_eigen.h>
// #include <fmt/core.h>
// #include <vector>
#include <fmt/core.h>
#include <fmt/ranges.h>
#include <string_view>
#include <vector>
#include <string>
#include <Eigen/Dense>
template <>
struct fmt::formatter<Eigen::VectorXd> : fmt::formatter<std::string> {
template <typename FormatContext>
auto format(const Eigen::VectorXd& vec, FormatContext& ctx) {
std::string result = "[";
for (int i = 0; i < vec.size(); ++i) {
result += fmt::format("{}{}", vec[i], (i < vec.size() - 1 ? ", " : ""));
}
result += "]";
return formatter<std::string>::format(result, ctx);
}
};
namespace mc_rtc::imgui
{
/* Typedef for brievity */
using ElementId = mc_control::ElementId;
/** Forward declaration */
struct Client;
/** A widget in the GUI */
struct Widget
{
inline Widget(Client & client, const ElementId & id) : client(client), id(id) {}
virtual ~Widget() = default;
Client & client;
ElementId id;
bool seen = true;
/** Draw the 2D elements of the widget */
virtual void draw2D() {}
/** Draw the 3D elements of the widget */
virtual void draw3D() {}
inline std::string label(std::string_view label, std::string_view extra = "")
{
return fmt::format("{}##{}{}{}", label, id.category, id.name, extra);
}
inline std::string label(std::string_view label, int i)
{
return fmt::format("{}##{}{}{}", label, id.category, id.name, i);
}
inline std::string label(std::string_view label, size_t i)
{
return fmt::format("{}##{}{}{}", label, id.category, id.name, i);
}
};
using WidgetPtr = std::unique_ptr<Widget>;
} // namespace mc_rtc::imgui