Class TabWidget¶
Defined in File tabwidget.h
Page Contents
Inheritance Relationships¶
Base Type¶
public nanogui::Widget
(Class Widget)
Class Documentation¶
-
class
TabWidget
: public nanogui::Widget¶ A wrapper around the widgets TabHeader and StackedWidget which hooks the two classes together.
Warning
Unlike other widgets, children may not be added directly to a TabWidget. For example, the following code will raise an exception:
// `this` might be say a nanogui::Screen instance Window *window = new Window(this, "Window Title"); TabWidget *tabWidget = window->add<TabWidget>(); // this label would be a direct child of tabWidget, // which is forbidden, so an exception will be raised new Label(tabWidget, "Some Label");
Instead, you are expected to be creating tabs and adding widgets to those.
// `this` might be say a nanogui::Screen instance Window *window = new Window(this, "Window Title"); TabWidget *tabWidget = window->add<TabWidget>(); // Create a tab first auto *layer = tabWidget->createTab("Tab Name"); // Add children to the created tabs layer->setLayout(new GroupLayout()); new Label(layer, "Some Label");
A slightly more involved example of creating a TabWidget can also be found in Example 1 (search for
tabWidget
in the file).Public Functions
-
virtual void
addChild
(int index, Widget *widget)¶ Forcibly prevent mis-use of the class by throwing an exception. Children are not to be added directly to the TabWidget, see the class level documentation (TabWidget) for an example.
- Exceptions
std::runtime_error
: An exception is always thrown, as children are not allowed to be added directly to this Widget.
-
void
setActiveTab
(int tabIndex)¶
-
int
activeTab
() const¶
-
int
tabCount
() const¶
-
void
setCallback
(const std::function<void(int)> &callback)¶ Sets the callable objects which is invoked when a tab is changed. The argument provided to the callback is the index of the new active tab.
-
const std::function<void(int)> &
callback
() const¶
-
Widget *
createTab
(const std::string &label)¶ Creates a new tab with the specified name and returns a pointer to the layer.
-
void
addTab
(const std::string &label, Widget *tab)¶ Inserts a tab at the end of the tabs collection and associates it with the provided widget.
-
void
addTab
(int index, const std::string &label, Widget *tab)¶ Inserts a tab into the tabs collection at the specified index and associates it with the provided widget.
-
bool
removeTab
(const std::string &label)¶ Removes the tab with the specified label and returns the index of the label. Returns whether the removal was successful.
-
void
removeTab
(int index)¶ Removes the tab with the specified index.
-
const std::string &
tabLabelAt
(int index) const¶ Retrieves the label of the tab at a specific index.
-
int
tabLabelIndex
(const std::string &label)¶ Retrieves the index of a specific tab using its tab label. Returns -1 if there is no such tab.
-
int
tabIndex
(Widget *tab)¶ Retrieves the index of a specific tab using a widget pointer. Returns -1 if there is no such tab.
-
void
ensureTabVisible
(int index)¶ This function can be invoked to ensure that the tab with the provided index the is visible, i.e to track the given tab. Forwards to the tab header widget. This function should be used whenever the client wishes to make the tab header follow a newly added tab, as the content of the new tab is made visible but the tab header does not track it by default.
-
const Widget *
tab
(const std::string &label) const¶ Returns a
const
pointer to the Widget associated with the specified label.- Return
The Widget associated with this label, or
nullptr
if not found.- Parameters
label
: The label used to create the tab.
-
Widget *
tab
(const std::string &label)¶ Returns a pointer to the Widget associated with the specified label.
- Return
The Widget associated with this label, or
nullptr
if not found.- Parameters
label
: The label used to create the tab.
-
const Widget *
tab
(int index) const¶ Returns a
const
pointer to the Widget associated with the specified index.
-
virtual void
performLayout
(NVGcontext *ctx)¶ Invoke the associated layout generator to properly place child widgets, if any.
-
virtual void
draw
(NVGcontext *ctx)¶ Draw the widget (and all child widgets)
-
virtual void