1 /*
2     nanogui/checkbox.h -- Two-state check box widget
3 
4     NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
5     The widget drawing code is based on the NanoVG demo application
6     by Mikko Mononen.
7 
8     All rights reserved. Use of this source code is governed by a
9     BSD-style license that can be found in the LICENSE.txt file.
10 */
11 /** \file */
12 
13 #pragma once
14 
15 #include <nanogui/widget.h>
16 
NAMESPACE_BEGIN(nanogui)17 NAMESPACE_BEGIN(nanogui)
18 
19 /**
20  * \class CheckBox checkbox.h nanogui/checkbox.h
21  *
22  * \brief Two-state check box widget.
23  */
24 class NANOGUI_EXPORT CheckBox : public Widget {
25 public:
26     CheckBox(Widget *parent, const std::string &caption = "Untitled",
27              const std::function<void(bool)> &callback = std::function<void(bool)>());
28 
29     const std::string &caption() const { return mCaption; }
30     void setCaption(const std::string &caption) { mCaption = caption; }
31 
32     const bool &checked() const { return mChecked; }
33     void setChecked(const bool &checked) { mChecked = checked; }
34 
35     const bool &pushed() const { return mPushed; }
36     void setPushed(const bool &pushed) { mPushed = pushed; }
37 
38     std::function<void(bool)> callback() const { return mCallback; }
39     void setCallback(const std::function<void(bool)> &callback) { mCallback = callback; }
40 
41     virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers) override;
42     virtual Vector2i preferredSize(NVGcontext *ctx) const override;
43     virtual void draw(NVGcontext *ctx) override;
44 
45     virtual void save(Serializer &s) const override;
46     virtual bool load(Serializer &s) override;
47 protected:
48     std::string mCaption;
49     bool mPushed, mChecked;
50     std::function<void(bool)> mCallback;
51 };
52 
53 NAMESPACE_END(nanogui)
54