1 /* 2 nanogui/imagepanel.h -- Image panel widget which shows a number of 3 square-shaped icons 4 5 NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>. 6 The widget drawing code is based on the NanoVG demo application 7 by Mikko Mononen. 8 9 All rights reserved. Use of this source code is governed by a 10 BSD-style license that can be found in the LICENSE.txt file. 11 */ 12 /** \file */ 13 14 #pragma once 15 16 #include <nanogui/widget.h> 17 NAMESPACE_BEGIN(nanogui)18NAMESPACE_BEGIN(nanogui) 19 20 /** 21 * \class ImagePanel imagepanel.h nanogui/imagepanel.h 22 * 23 * \brief Image panel widget which shows a number of square-shaped icons. 24 */ 25 class NANOGUI_EXPORT ImagePanel : public Widget { 26 public: 27 typedef std::vector<std::pair<int, std::string>> Images; 28 public: 29 ImagePanel(Widget *parent); 30 31 void setImages(const Images &data) { mImages = data; } 32 const Images& images() const { return mImages; } 33 34 std::function<void(int)> callback() const { return mCallback; } 35 void setCallback(const std::function<void(int)> &callback) { mCallback = callback; } 36 37 virtual bool mouseMotionEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers) override; 38 virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override; 39 virtual Vector2i preferredSize(NVGcontext *ctx) const override; 40 virtual void draw(NVGcontext* ctx) override; 41 protected: 42 Vector2i gridSize() const; 43 int indexForPosition(const Vector2i &p) const; 44 protected: 45 Images mImages; 46 std::function<void(int)> mCallback; 47 int mThumbSize; 48 int mSpacing; 49 int mMargin; 50 int mMouseIndex; 51 }; 52 53 NAMESPACE_END(nanogui) 54