BuGUI
BUtton Grid User Interface
Loading...
Searching...
No Matches
buttons.hpp
1#pragma once
2#include "base_hardware.hpp"
3#include <color/color_converter.hpp>
4#include <io/button_presser.hpp>
5#include <concepts/device.hpp>
6#include <macros/labels.hpp>
7
8#include <functional>
9
10namespace bugui
11{
14template <typename Device, typename Controller>
15struct buttons : virtual base_hardware
16{ };
17
20template <has_buttons Device, typename Controller>
21class buttons<Device, Controller>
22 : virtual public base_hardware
23{
24 using id_type = Device::buttons::id_type;
25
26 using color_cnvtr = color_converter<typename Device::color>;
27 // TODO : create list of colour converter
28 // from the list of available buttons (c++ 26 reflection)
29 color_cnvtr cvrtr{};
30
31protected:
32 bool on_button_received(Controller* ctrlr, id_type id)
33 {
34#define call_ctrlr(F) \
35 if constexpr(F##_button<Device, Controller>) \
36 if (id == Device::buttons::F##_id()) \
37 { \
38 ctrlr->on_##F(btn_prsr); \
39 ctrlr->set_##F##_held(btn_prsr); \
40 return true; \
41 }
42// FIXME : find more succinct macro
43#define CALL_MACRO(r, data, elem) call_ctrlr(elem)
44 FOR_EACH_LABEL(CALL_MACRO)
45#undef CALL_MACRO
46#undef call_ctrlr
47
48 return false;
49 }
50
51 void paint(const button_painter& p
52 , std::function<
53 void(id_type, const color_cnvtr&)
54 >&& func)
55 {
56 labels l{p.get_label()};
57 cvrtr.set(p.get_color());
58
59#define call_func(F) \
60 if constexpr(device_##F##_button<Device>) \
61 if (l == labels::F) \
62 func(Device::buttons::F##_id(), cvrtr);
63// FIXME : find a more succinct macro
64#define CALL_MACRO(r, data, elem) call_func(elem)
65 FOR_EACH_LABEL(CALL_MACRO)
66#undef CALL_MACRO
67#undef call_func
68 }
69
70 button_presser btn_prsr;
71};
72
73} // namespace bugui
Conveys button colors from the controller to the base_hardware.
Definition button_painter.hpp:10
color get_color() const
Retieves the current color.
Definition button_painter.hpp:48
labels get_label() const
Retieves the current button label.
Definition button_painter.hpp:51
Definition button_presser.hpp:10
Empty struct for devices that do not feature labelled buttons.
Definition buttons.hpp:16
Povides convertion of color objects to device specific integer values.
Definition color_converter.hpp:94
void set(const color &color) override
Sets the original color.
Definition color_converter.hpp:97