Class Widget¶
Defined in File widget.h
Page Contents
Inheritance Relationships¶
Base Type¶
public nanogui::Object
(Class Object)
Derived Types¶
public nanogui::Button
(Class Button)public nanogui::CheckBox
(Class CheckBox)public nanogui::ColorWheel
(Class ColorWheel)public nanogui::GLCanvas
(Class GLCanvas)public nanogui::Graph
(Class Graph)public nanogui::ImagePanel
(Class ImagePanel)public nanogui::ImageView
(Class ImageView)public nanogui::Label
(Class Label)public nanogui::ProgressBar
(Class ProgressBar)public nanogui::Screen
(Class Screen)public nanogui::Slider
(Class Slider)public nanogui::StackedWidget
(Class StackedWidget)public nanogui::TabHeader
(Class TabHeader)public nanogui::TabWidget
(Class TabWidget)public nanogui::TextBox
(Class TextBox)public nanogui::VScrollPanel
(Class VScrollPanel)public nanogui::Window
(Class Window)
Class Documentation¶
-
class
Widget
: public nanogui::Object¶ Base class of all widgets.
Widget is the base class of all widgets in
nanogui
. It can also be used as an panel to arrange an arbitrary number of child widgets using a layout generator (see Layout).Subclassed by nanogui::Button, nanogui::CheckBox, nanogui::ColorWheel, nanogui::GLCanvas, nanogui::Graph, nanogui::ImagePanel, nanogui::ImageView, nanogui::Label, nanogui::ProgressBar, nanogui::Screen, nanogui::Slider, nanogui::StackedWidget, nanogui::TabHeader, nanogui::TabWidget, nanogui::TextBox, nanogui::VScrollPanel, nanogui::Window
Public Functions
-
int
width
() const¶ Return the width of the widget.
-
void
setWidth
(int width)¶ Set the width of the widget.
-
int
height
() const¶ Return the height of the widget.
-
void
setHeight
(int height)¶ Set the height of the widget.
-
void
setFixedSize
(const Vector2i &fixedSize)¶ Set the fixed size of this widget.
If nonzero, components of the fixed size attribute override any values computed by a layout generator associated with this widget. Note that just setting the fixed size alone is not enough to actually change its size; this is done with a call to setSize or a call to performLayout() in the parent widget.
-
const Vector2i &
fixedSize
() const¶ Return the fixed size (see setFixedSize())
-
int
fixedWidth
() const¶
-
int
fixedHeight
() const¶
-
void
setFixedWidth
(int width)¶ Set the fixed width (see setFixedSize())
-
void
setFixedHeight
(int height)¶ Set the fixed height (see setFixedSize())
-
bool
visible
() const¶ Return whether or not the widget is currently visible (assuming all parents are visible)
-
void
setVisible
(bool visible)¶ Set whether or not the widget is currently visible (assuming all parents are visible)
-
bool
visibleRecursive
() const¶ Check if this widget is currently visible, taking parent widgets into account.
-
int
childCount
() const¶ Return the number of child widgets.
-
const std::vector<Widget *> &
children
() const¶ Return the list of child widgets of the current widget.
-
virtual void
addChild
(int index, Widget *widget)¶ Add a child widget to the current widget at the specified index.
This function almost never needs to be called by hand, since the constructor of Widget automatically adds the current widget to its parent
-
void
removeChild
(int index)¶ Remove a child widget by index.
-
template<typename
WidgetClass
, typename ...Args
>
WidgetClass *add
(const Args&... args)¶ Variadic shorthand notation to construct and add a child widget.
-
void
setId
(const std::string &id)¶ Associate this widget with an ID value (optional)
-
const std::string &
id
() const¶ Return the ID value associated with this widget, if any.
-
bool
enabled
() const¶ Return whether or not this widget is currently enabled.
-
void
setEnabled
(bool enabled)¶ Set whether or not this widget is currently enabled.
-
bool
focused
() const¶ Return whether or not this widget is currently focused.
-
void
setFocused
(bool focused)¶ Set whether or not this widget is currently focused.
-
void
requestFocus
()¶ Request the focus to be moved to this widget.
-
const std::string &
tooltip
() const¶
-
void
setTooltip
(const std::string &tooltip)¶
-
int
fontSize
() const¶ Return current font size. If not set the default of the current theme will be returned.
-
void
setFontSize
(int fontSize)¶ Set the font size of this widget.
-
bool
hasFontSize
() const¶ Return whether the font size is explicitly specified for this widget.
-
float
iconExtraScale
() const¶ The amount of extra scaling applied to icon fonts. See nanogui::Widget::mIconExtraScale.
-
void
setIconExtraScale
(float scale)¶ Sets the amount of extra scaling applied to icon fonts. See nanogui::Widget::mIconExtraScale.
-
Widget *
findWidget
(const Vector2i &p)¶ Determine the widget located at the given position value (recursive)
-
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
mouseEnterEvent
(const Vector2i &p, bool enter)¶ Handle a mouse enter/leave event (default implementation: record this fact, but do nothing)
-
virtual bool
scrollEvent
(const Vector2i &p, const Vector2f &rel)¶ Handle a mouse scroll event (default implementation: propagate to children)
-
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 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
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 Functions
-
virtual
~Widget
()¶ Free all resources used by the widget and any children.
-
float
icon_scale
() const¶ Convenience definition for subclasses to get the full icon scale for this class of Widget. It simple returns the value
mTheme->mIconScale * this->mIconExtraScale
.- Remark
See also: nanogui::Theme::mIconScale and nanogui::Widget::mIconExtraScale. This tiered scaling strategy may not be appropriate with fonts other than
entypo.ttf
.
Protected Attributes
-
std::string
mId
¶
-
bool
mVisible
¶ Whether or not this Widget is currently visible. When a Widget is not currently visible, no time is wasted executing its drawing method.
-
bool
mEnabled
¶ Whether or not this Widget is currently enabled. Various different kinds of derived types use this to determine whether or not user input will be accepted. For example, when
mEnabled == false
, the state of a CheckBox cannot be changed, or a TextBox will not allow new input.
-
bool
mFocused
¶
-
bool
mMouseFocus
¶
-
std::string
mTooltip
¶
-
int
mFontSize
¶
-
float
mIconExtraScale
¶ The amount of extra icon scaling used in addition the the theme’s default icon font scale. Default value is
1.0
, which implies that nanogui::Widget::icon_scale simply returns the value of nanogui::Theme::mIconScale.Most widgets do not need extra scaling, but some (e.g., CheckBox, TextBox) need to adjust the Theme’s default icon scaling (nanogui::Theme::mIconScale) to properly display icons within their bounds (upscale, or downscale).
Note
When using
nvgFontSize
for icons in subclasses, make sure to call thenanogui::Widget::icon_scale()
function. Expected usage when drawing icon fonts is something like:virtual void draw(NVGcontext *ctx) { // fontSize depends on the kind of Widget. Search for `FontSize` // in the Theme class (e.g., standard vs button) float ih = fontSize; // assuming your Widget has a declared `mIcon` if (nvgIsFontIcon(mIcon)) { ih *= icon_scale(); nvgFontFace(ctx, "icons"); nvgFontSize(ctx, ih); /// remaining drawing code (see button.cpp for more) } }
-
int