Class CheckBox

Inheritance Relationships

Base Type

Derived Type

Class Documentation

class CheckBox : public nanogui::Widget

Two-state check box widget.

Remark

This class overrides 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).

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)>())

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”.

const std::string &caption() const

The caption of this CheckBox.

void setCaption(const std::string &caption)

Sets the caption of this CheckBox.

const bool &checked() const

Whether or not this CheckBox is currently checked.

void setChecked(const bool &checked)

Sets whether or not this CheckBox is currently checked.

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.

std::function<void(bool)> callback() const

Returns the current callback of this CheckBox.

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:

  1. This CheckBox is “enabled” (see nanogui::Widget::mEnabled).

  2. p is inside this CheckBox.

  3. button is GLFW_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 parameter down == 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 Vector2i preferredSize(NVGcontext *ctx) const

The preferred size of this CheckBox.

virtual void draw(NVGcontext *ctx)

Draws this CheckBox.

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

std::string mCaption

The caption text of this CheckBox.

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.

bool mChecked

Whether or not this CheckBox is currently checked or unchecked.

std::function<void(bool)> mCallback

The function to execute when nanogui::CheckBox::mChecked is changed.