Class FormHelper

Page Contents

Class Documentation

class FormHelper

Convenience class to create simple AntTweakBar-style layouts that expose variables of various types using NanoGUI widgets.

Example:

// [ ... initialize NanoGUI, construct screen ... ]

FormHelper* h = new FormHelper(screen);

// Add a new windows widget
h->addWindow(Eigen::Vector2i(10,10),"Menu");

// Start a new group
h->addGroup("Group 1");

// Expose an integer variable by reference
h->addVariable("integer variable", aInt);

// Expose a float variable via setter/getter functions
h->addVariable(
  [&](float value) { aFloat = value; },
  [&]() { return *aFloat; },
  "float variable");

// add a new button
h->addButton("Button", [&]() { std::cout << "Button pressed" << std::endl; });

Public Functions

FormHelper(Screen *screen)

Create a helper class to construct NanoGUI widgets on the given screen.

Window *addWindow(const Vector2i &pos, const std::string &title = "Untitled")

Add a new top-level window.

Label *addGroup(const std::string &caption)

Add a new group that may contain several sub-widgets.

template<typename Type>
detail::FormWidget<Type> *addVariable(const std::string &label, const std::function<void(const Type&)> &setter, const std::function<Type()> &getterbool editable = true, )

Add a new data widget controlled using custom getter/setter functions.

template<typename Type>
detail::FormWidget<Type> *addVariable(const std::string &label, Type &value, bool editable = true)

Add a new data widget that exposes a raw variable in memory.

Button *addButton(const std::string &label, const std::function<void()> &cb)

Add a button with a custom callback.

void addWidget(const std::string &label, Widget *widget)

Add an arbitrary (optionally labeled) widget to the layout.

void refresh()

Cause all widgets to re-synchronize with the underlying variable state.

Window *window()

Access the currently active Window instance.

void setWindow(Window *window)

Set the active Window instance.

void setFixedSize(const Vector2i &fw)

Specify a fixed size for newly added widgets.

Vector2i fixedSize()

The current fixed size being used for newly added widgets.

const std::string &groupFontName() const

The font name being used for group headers.

void setGroupFontName(const std::string &name)

Sets the font name to be used for group headers.

const std::string &labelFontName() const

The font name being used for labels.

void setLabelFontName(const std::string &name)

Sets the font name being used for labels.

int groupFontSize() const

The size of the font being used for group headers.

void setGroupFontSize(int value)

Sets the size of the font being used for group headers.

int labelFontSize() const

The size of the font being used for labels.

void setLabelFontSize(int value)

Sets the size of the font being used for labels.

int widgetFontSize() const

The size of the font being used for non-group / non-label widgets.

void setWidgetFontSize(int value)

Sets the size of the font being used for non-group / non-label widgets.

Protected Attributes

ref<Screen> mScreen

A reference to the nanogui::Screen this FormHelper is assisting.

ref<Window> mWindow

A reference to the nanogui::Window this FormHelper is controlling.

ref<AdvancedGridLayout> mLayout

A reference to the nanogui::AdvancedGridLayout this FormHelper is using.

std::vector<std::function<void()>> mRefreshCallbacks

The callbacks associated with all widgets this FormHelper is managing.

std::string mGroupFontName = "sans-bold"

The group header font name.

std::string mLabelFontName = "sans"

The label font name.

Vector2i mFixedSize = Vector2i(0, )

The fixed size for newly added widgets.

int mGroupFontSize = 20

The font size for group headers.

int mLabelFontSize = 16

The font size for labels.

int mWidgetFontSize = 16

The font size for non-group / non-label widgets.

int mPreGroupSpacing = 15

The spacing used before new groups.

int mPostGroupSpacing = 5

The spacing used after each group.

int mVariableSpacing = 5

The spacing between all other widgets.