1 #pragma once
2 #include "NanoVG.hpp"
3 #include "ui/Geometry.h"
4 #include <string>
5 #include <vector>
6 #include <functional>
7 class ColorPalette;
8 
9 class SpinBoxChooser : public NanoWidget {
10 public:
11     SpinBoxChooser(Widget *group, const ColorPalette &palette);
12     void clearChoices();
13     void addChoice(int32_t value, const char *text);
14 
15     const std::string &textAtIndex(int32_t index);
16 
17     int32_t valueIndex() const;
18     void setValueIndex(int32_t index);
19 
20     int32_t value() const;
21     void setValue(int32_t value);
22 
23     std::function<void(int32_t)> ValueChangedCallback;
24 
25 protected:
26     void onNanoDisplay() override;
27     void onResize(const ResizeEvent &ev) override;
28     bool onMouse(const MouseEvent &ev) override;
29 
30 private:
31     void updateLayout();
32 
33 private:
34     int32_t fValueIndex = 0;
35     std::vector<std::pair<int32_t, std::string>> fChoices;
36     const ColorPalette &fPalette;
37     Rect fBoundsLeftButton;
38     Rect fBoundsRightButton;
39     Rect fBoundsCenterLabel;
40 };
41