-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widget.h
60 lines (43 loc) · 1.21 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
#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
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