1 #pragma once 2 #include "NanoVG.hpp" 3 #include "ui/Geometry.h" 4 #include <string> 5 #include <vector> 6 #include <memory> 7 class ColorPalette; 8 9 class MainToolBar : public NanoWidget { 10 public: 11 MainToolBar(Widget *group, ColorPalette &palette); 12 void addButton(int id, const char *label, const char *icon); 13 void setSelected(int id, bool sel); 14 float getIdealWidth() const; 15 16 class Listener { 17 public: 18 virtual ~Listener() {} 19 virtual void onToolBarItemClicked(int id) = 0; 20 }; 21 22 void setListener(Listener *l) { fListener = l; } 23 24 protected: 25 void onNanoDisplay() override; 26 void onResize(const ResizeEvent &ev) override; 27 bool onMouse(const MouseEvent &ev) override; 28 29 private: 30 void updatePositionsAndSizes(); 31 32 private: 33 struct Item { 34 int id = 0; 35 int type = 0; 36 std::string label; 37 std::string icon; 38 bool selected = false; 39 }; 40 41 enum ItemType { 42 kTypeIcon, 43 }; 44 45 private: 46 ColorPalette &fPalette; 47 std::vector<Item> fLayout; 48 std::vector<RectF> fItemRects; 49 Listener *fListener = nullptr; 50 }; 51