Class TextBox

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class TextBox : public nanogui::Widget

Fancy text box with builtin regular expression-based validation.

Remark

This class overrides nanogui::Widget::mIconExtraScale to be 0.8f, which affects all subclasses of this Widget. Subclasses must explicitly set a different value if needed (e.g., in their constructor).

Subclassed by nanogui::FloatBox< T >, nanogui::IntBox< T >, nanogui::detail::FormWidget< std::string, std::true_type >, nanogui::FloatBox< Scalar >, nanogui::IntBox< Scalar >

Public Types

enum Alignment

How to align the text in the text box.

Values:

Left
Center
Right

Public Functions

TextBox(Widget *parent, const std::string &value = "Untitled")
bool editable() const
void setEditable(bool editable)
bool spinnable() const
void setSpinnable(bool spinnable)
const std::string &value() const
void setValue(const std::string &value)
const std::string &defaultValue() const
void setDefaultValue(const std::string &defaultValue)
Alignment alignment() const
void setAlignment(Alignment align)
const std::string &units() const
void setUnits(const std::string &units)
int unitsImage() const
void setUnitsImage(int image)
const std::string &format() const

Return the underlying regular expression specifying valid formats.

void setFormat(const std::string &format)

Specify a regular expression specifying valid formats.

const std::string &placeholder() const

Return the placeholder text to be displayed while the text box is empty.

void setPlaceholder(const std::string &placeholder)

Specify a placeholder text to be displayed while the text box is empty.

virtual void setTheme(Theme *theme)

Set the Theme used to draw this widget.

std::function<bool(const std::string &str)> callback() const

The callback to execute when the value of this TextBox has changed.

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

Sets the callback to execute when the value of this TextBox has changed.

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

Handle a mouse button event (default implementation: propagate to children)

virtual bool mouseMotionEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers)

Handle a mouse motion event (default implementation: propagate to children)

virtual bool mouseDragEvent(const Vector2i &p, const Vector2i &rel, int button, int modifiers)

Handle a mouse drag event (default implementation: do nothing)

virtual bool focusEvent(bool focused)

Handle a focus change event (default implementation: record the focus status, but do nothing)

virtual bool keyboardEvent(int key, int scancode, int action, int modifiers)

Handle a keyboard event (default implementation: do nothing)

virtual bool keyboardCharacterEvent(unsigned int codepoint)

Handle text input (UTF-32 format) (default implementation: do nothing)

virtual Vector2i preferredSize(NVGcontext *ctx) const

Compute the preferred size of the widget.

virtual void draw(NVGcontext *ctx)

Draw the widget (and all child widgets)

virtual void save(Serializer &s) const

Save the state of the widget into the given Serializer instance.

virtual bool load(Serializer &s)

Restore the state of the widget from the given Serializer instance.

Protected Types

enum SpinArea

The location (if any) for the spin area.

Values:

None
Top
Bottom

Protected Functions

bool checkFormat(const std::string &input, const std::string &format)
bool copySelection()
void pasteFromClipboard()
bool deleteSelection()
void updateCursor(NVGcontext *ctx, float lastx, const NVGglyphPosition *glyphs, int size)
float cursorIndex2Position(int index, float lastx, const NVGglyphPosition *glyphs, int size)
int position2CursorIndex(float posx, float lastx, const NVGglyphPosition *glyphs, int size)
SpinArea spinArea(const Vector2i &pos)

Protected Attributes

bool mEditable
bool mSpinnable
bool mCommitted
std::string mValue
std::string mDefaultValue
Alignment mAlignment
std::string mUnits
std::string mFormat
int mUnitsImage
std::function<bool(const std::string &str)> mCallback
bool mValidFormat
std::string mValueTemp
std::string mPlaceholder
int mCursorPos
int mSelectionPos
Vector2i mMousePos
Vector2i mMouseDownPos
Vector2i mMouseDragPos
int mMouseDownModifier
float mTextOffset
double mLastClick