forked from mitsuba-renderer/nanogui
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheckbox.h
More file actions
107 lines (87 loc) · 3.5 KB
/
Copy pathcheckbox.h
File metadata and controls
107 lines (87 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
The widget drawing code is based on the NanoVG demo application
by Mikko Mononen.
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE.txt file.
*/
/**
* \file nanogui/checkbox.h
*
* \brief Two-state check box Widget.
*/
#pragma once
#include <nanogui/widget.h>
NAMESPACE_BEGIN(nanogui)
/**
* \class CheckBox checkbox.h nanogui/checkbox.h
*
* \brief Two-state check box widget.
*
* \remark
* This class overrides \ref nanogui::Widget::mIconExtraScale to be ``1.2f``,
* which affects all subclasses of this Widget. Subclasses must explicitly
* set a different value if needed (e.g., in their constructor).
*/
class NANOGUI_EXPORT CheckBox : public Widget {
public:
/**
* Adds a CheckBox to the specified ``parent``.
*
* \param parent
* The Widget to add this CheckBox to.
*
* \param caption
* The caption text of the CheckBox (default ``"Untitled"``).
*
* \param callback
* If provided, the callback to execute when the CheckBox is checked or
* unchecked. Default parameter function does nothing. See
* \ref nanogui::CheckBox::mPushed for the difference between "pushed"
* and "checked".
*/
CheckBox(Widget *parent, std::string_view caption = "Untitled",
const std::function<void(bool)> &callback = std::function<void(bool)>());
/// The caption of this check box.
std::string_view caption() const { return m_caption; }
/// Sets the caption of this check box
void set_caption(std::string_view caption) {
if (m_caption != caption) {
m_caption = caption;
preferred_size_changed();
}
}
/// Return whether or not this widget is currently checked.
const bool &checked() const { return m_checked; }
/// Sets whether or not this widget is currently checked
void set_checked(const bool &checked) { m_checked = checked; }
/// Whether or not this widget is currently pushed. See \ref nanogui::CheckBox::m_pushed.
const bool &pushed() const { return m_pushed; }
void set_pushed(const bool &pushed) { m_pushed = pushed; }
/// Returns the current callback of this CheckBox.
const std::function<void(bool)> &callback() const { return m_callback; }
/// Sets the callback to be executed when this CheckBox is checked / unchecked.
void set_callback(const std::function<void(bool)> &callback) { m_callback = callback; }
/// Mouse button event processing for this check box
virtual bool mouse_button_event(const Vector2i &p, int button, bool down, int modifiers) override;
protected:
/// The preferred size of this CheckBox.
virtual Vector2i preferred_size_impl(NVGcontext *ctx) const override;
public:
/// Draws this CheckBox.
virtual void draw(NVGcontext *ctx) override;
protected:
/// The caption text of this CheckBox.
std::string m_caption;
/**
* Internal tracking variable to distinguish between mouse click and release.
* \ref nanogui::CheckBox::m_callback is only called upon release. See
* \ref nanogui::CheckBox::mouse_button_event for specific conditions.
*/
bool m_pushed;
/// Whether or not this CheckBox is currently checked or unchecked.
bool m_checked;
/// The function to execute when \ref nanogui::CheckBox::m_checked is changed.
std::function<void(bool)> m_callback;
};
NAMESPACE_END(nanogui)