Class Button

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class Button : public nanogui::Widget

[Normal/Toggle/Radio/Popup] Button widget.

Subclassed by nanogui::PopupButton, nanogui::ToolButton

Public Types

enum Flags

Flags to specify the button behavior (can be combined with binary OR)

Values:

NormalButton = (1 << 0)

A normal Button.

RadioButton = (1 << 1)

A radio Button.

ToggleButton = (1 << 2)

A toggle Button.

PopupButton = (1 << 3)

A popup Button.

enum IconPosition

The available icon positions.

Values:

Left

Button icon on the far left.

LeftCentered

Button icon on the left, centered (depends on caption text length).

RightCentered

Button icon on the right, centered (depends on caption text length).

Right

Button icon on the far right.

Public Functions

Button(Widget *parent, const std::string &caption = "Untitled", int icon = 0)

Creates a button attached to the specified parent.

Parameters

const std::string &caption() const

Returns the caption of this Button.

void setCaption(const std::string &caption)

Sets the caption of this Button.

const Color &backgroundColor() const

Returns the background color of this Button.

void setBackgroundColor(const Color &backgroundColor)

Sets the background color of this Button.

const Color &textColor() const

Returns the text color of the caption of this Button.

void setTextColor(const Color &textColor)

Sets the text color of the caption of this Button.

int icon() const

Returns the icon of this Button. See nanogui::Button::mIcon.

void setIcon(int icon)

Sets the icon of this Button. See nanogui::Button::mIcon.

int flags() const

The current flags of this Button (see nanogui::Button::Flags for options).

void setFlags(int buttonFlags)

Sets the flags of this Button (see nanogui::Button::Flags for options).

IconPosition iconPosition() const

The position of the icon for this Button.

void setIconPosition(IconPosition iconPosition)

Sets the position of the icon for this Button.

bool pushed() const

Whether or not this Button is currently pushed.

void setPushed(bool pushed)

Sets whether or not this Button is currently pushed.

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

The current callback to execute (for any type of button).

void setCallback(const std::function<void()> &callback)

Set the push callback (for any type of button).

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

The current callback to execute (for toggle buttons).

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

Set the change callback (for toggle buttons).

void setButtonGroup(const std::vector<Button *> &buttonGroup)

Set the button group (for radio buttons).

const std::vector<Button *> &buttonGroup() const

The current button group (for radio buttons).

virtual Vector2i preferredSize(NVGcontext *ctx) const

The preferred size of this Button.

virtual bool mouseButtonEvent(const Vector2i &p, int button, bool down, int modifiers)

The callback that is called when any type of mouse button event is issued to this Button.

virtual void draw(NVGcontext *ctx)

Responsible for drawing the Button.

virtual void save(Serializer &s) const

Saves the state of this Button provided the given Serializer.

virtual bool load(Serializer &s)

Sets the state of this Button provided the given Serializer.

Protected Attributes

std::string mCaption

The caption of this Button.

int mIcon

The icon of this Button (0 means no icon).

The icon to display with this Button. If not 0, may either be a picture icon, or one of the icons enumerated in File entypo.h. The kind of icon (image or Entypo) is determined by the functions nanogui::nvgIsImageIcon() and its reciprocal counterpart nanogui::nvgIsFontIcon().

IconPosition mIconPosition

The position to draw the icon at.

bool mPushed

Whether or not this Button is currently pushed.

int mFlags

The current flags of this button (see nanogui::Button::Flags for options).

Color mBackgroundColor

The background color of this Button.

Color mTextColor

The color of the caption text of this Button.

std::function<void()> mCallback

The callback issued for all types of buttons.

std::function<void(bool)> mChangeCallback

The callback issued for toggle buttons.

std::vector<Button *> mButtonGroup

The button group for radio buttons.