Class CheckBox¶
- Defined in File checkbox.h
Page Contents
Inheritance Relationships¶
Base Type¶
public nanogui::Widget
(Class Widget)
Derived Type¶
public nanogui::detail::FormWidget< bool, std::true_type >
(Template Class FormWidget< bool, std::true_type >)
Class Documentation¶
-
class
CheckBox
: public nanogui::Widget¶ Two-state check box widget.
- Remark
- This class overrides Widget::mIconExtraScale to what is specified by Theme::mCheckBoxIconExtraScale, which affects all subclasses of this Widget. Subclasses must explicitly set a different value if needed (e.g., in their constructor). Note that setTheme also overwrites this value to that specified by the new Theme, so subclasses must also account for this if setting to a non-theme value.
Subclassed by nanogui::detail::FormWidget< bool, std::true_type >
Public Functions
-
CheckBox
(Widget *parent, const std::string &caption = "Untitled", const std::function<void(bool)> &callback = std::function< void(bool)>(), const std::string &font = "", )¶ Adds a CheckBox to the specified
parent
.- Parameters
parent
: The Widget to add this CheckBox to.caption
: The caption text of the CheckBox (default"Untitled"
).callback
: If provided, the callback to execute when the CheckBox is checked or unchecked. Default parameter function does nothing. See nanogui::CheckBox::mPushed for the difference between “pushed” and “checked”.font
: The font face to use (default""
implies Theme::mDefaultFont, which will typically be"sans"
).
The caption of this CheckBox.
-
const bool &
pushed
() const¶ Whether or not this CheckBox is currently pushed. See nanogui::CheckBox::mPushed.
-
void
setPushed
(const bool &pushed)¶ Sets whether or not this CheckBox is currently pushed. See nanogui::CheckBox::mPushed.
-
void
setCallback
(const std::function<void(bool)> &callback)¶ Sets the callback to be executed when this CheckBox is checked / unchecked.
-
virtual bool
mouseButtonEvent
(const Vector2i &p, int button, bool down, int modifiers)¶ The mouse button callback will return
true
when all three conditions are met:- This CheckBox is “enabled” (see nanogui::Widget::mEnabled).
p
is inside this CheckBox.button
isGLFW_MOUSE_BUTTON_1
(left mouse click).
Since a mouse button event is issued for both when the mouse is pressed, as well as released, this function sets nanogui::CheckBox::mPushed to
true
when parameterdown == true
. When the second event (down == false
) is fired, nanogui::CheckBox::mChecked is inverted and nanogui::CheckBox::mCallback is called.That is, the callback provided is only called when the mouse button is released, and the click location remains within the CheckBox boundaries. If the user clicks on the CheckBox and releases away from the bounds of the CheckBox, nanogui::CheckBox::mPushed is simply set back to
false
.
-
virtual void
setTheme
(Theme *theme)¶ Ensures that Widget::mIconExtraScale is updated.
-
virtual void
save
(Serializer &s) const¶ Saves this CheckBox to the specified Serializer.
-
virtual bool
load
(Serializer &s)¶ Loads the state of the specified Serializer to this CheckBox.
Protected Attributes
-
bool
mPushed
¶ Internal tracking variable to distinguish between mouse click and release. nanogui::CheckBox::mCallback is only called upon release. See nanogui::CheckBox::mouseButtonEvent for specific conditions.
-
std::function<void(bool)>
mCallback
¶ The function to execute when nanogui::CheckBox::mChecked is changed.