VCV Rack API v2
Loading...
Searching...
No Matches
rack::widget::Widget Struct Reference

A node in the 2D scene graph. More...

#include <Widget.hpp>

Inheritance diagram for rack::widget::Widget:
[legend]
Collaboration diagram for rack::widget::Widget:
[legend]

Classes

struct  ActionEvent
 Occurs after a certain action is triggered on a Widget. More...
 
struct  AddEvent
 Occurs after a Widget is added to a parent. More...
 
struct  ButtonEvent
 Occurs each mouse button press or release. More...
 
struct  ChangeEvent
 Occurs after the value of a Widget changes. More...
 
struct  ContextCreateEvent
 Occurs after the Window (including OpenGL and NanoVG contexts) are created. More...
 
struct  ContextDestroyEvent
 Occurs before the Window (including OpenGL and NanoVG contexts) are destroyed. More...
 
struct  DeselectEvent
 Occurs when a different Widget is selected. More...
 
struct  DirtyEvent
 Occurs when the pixel buffer of this module must be refreshed. More...
 
struct  DoubleClickEvent
 Occurs when the left mouse button is pressed a second time on the same Widget within a time duration. More...
 
struct  DragBaseEvent
 
struct  DragDropEvent
 Occurs when the mouse button is released over a Widget while dragging. More...
 
struct  DragEndEvent
 Occurs when a Widget stops being dragged by releasing the mouse button. More...
 
struct  DragEnterEvent
 Occurs when the mouse enters a Widget while dragging. More...
 
struct  DragHoverEvent
 Occurs every frame when the mouse is hovering over a Widget while another Widget (possibly the same one) is being dragged. More...
 
struct  DragLeaveEvent
 Occurs when the mouse leaves a Widget while dragging. More...
 
struct  DragMoveEvent
 Occurs every frame on the dragged Widget. More...
 
struct  DragStartEvent
 Occurs when a Widget begins being dragged. More...
 
struct  DrawArgs
 
struct  EnterEvent
 Occurs when a Widget begins consuming the Hover event. More...
 
struct  HideEvent
 Occurs after a Widget is hidden with Widget::hide(). More...
 
struct  HoverEvent
 Occurs every frame when the mouse is hovering over a Widget. More...
 
struct  HoverKeyEvent
 Occurs when a key is pressed, released, or repeated while the mouse is hovering a Widget. More...
 
struct  HoverScrollEvent
 Occurs when the mouse scroll wheel is moved while the mouse is hovering a Widget. More...
 
struct  HoverTextEvent
 Occurs when a character is typed while the mouse is hovering a Widget. More...
 
struct  KeyBaseEvent
 An event prototype with a GLFW key. More...
 
struct  LeaveEvent
 Occurs when a different Widget is entered. More...
 
struct  PathDropEvent
 Occurs when a selection of files from the operating system is dropped onto a Widget. More...
 
struct  PositionBaseEvent
 An event prototype with a vector position. More...
 
struct  RemoveEvent
 Occurs before a Widget is removed from its parent. More...
 
struct  RepositionEvent
 Occurs after a Widget's position is set by Widget::setPosition(). More...
 
struct  ResizeEvent
 Occurs after a Widget's size is set by Widget::setSize(). More...
 
struct  SelectEvent
 Occurs when a Widget begins consuming the Button press event for the left mouse button. More...
 
struct  SelectKeyEvent
 Occurs when a key is pressed, released, or repeated while a Widget is selected. More...
 
struct  SelectTextEvent
 Occurs when text is typed while a Widget is selected. More...
 
struct  ShowEvent
 Occurs after a Widget is shown with Widget::show(). More...
 
struct  TextBaseEvent
 An event prototype with a Unicode character. More...
 

Public Types

using BaseEvent = widget::BaseEvent
 

Public Member Functions

virtual ~Widget ()
 
math::Rect getBox ()
 
void setBox (math::Rect box)
 Calls setPosition() and then setSize().
 
math::Vec getPosition ()
 
void setPosition (math::Vec pos)
 Sets position and triggers RepositionEvent if position changed.
 
math::Vec getSize ()
 
void setSize (math::Vec size)
 Sets size and triggers ResizeEvent if size changed.
 
widget::WidgetgetParent ()
 
bool isVisible ()
 
void setVisible (bool visible)
 Sets visible and triggers ShowEvent or HideEvent if changed.
 
void show ()
 Makes Widget visible and triggers ShowEvent if changed.
 
void hide ()
 Makes Widget not visible and triggers HideEvent if changed.
 
void requestDelete ()
 Requests this Widget's parent to delete it in the next step().
 
virtual math::Rect getChildrenBoundingBox ()
 Returns the smallest rectangle containing this widget's children (visible and invisible) in its local coordinates.
 
virtual math::Rect getVisibleChildrenBoundingBox ()
 
bool isDescendantOf (Widget *ancestor)
 Returns whether ancestor is a parent or distant parent of this widget.
 
virtual math::Vec getRelativeOffset (math::Vec v, Widget *ancestor)
 Returns v (given in local coordinates) transformed into the coordinate system of ancestor.
 
math::Vec getAbsoluteOffset (math::Vec v)
 Returns v transformed into world/root/global/absolute coordinates.
 
virtual float getRelativeZoom (Widget *ancestor)
 Returns the zoom level in the coordinate system of ancestor.
 
float getAbsoluteZoom ()
 
virtual math::Rect getViewport (math::Rect r=math::Rect::inf())
 Returns a subset of the given Rect bounded by the box of this widget and all ancestors.
 
template<class T >
T * getAncestorOfType ()
 
template<class T >
T * getFirstDescendantOfType ()
 
bool hasChild (Widget *child)
 Checks if the given widget is a child of this widget.
 
void addChild (Widget *child)
 Adds widget to the top of the children.
 
void addChildBottom (Widget *child)
 Adds widget to the bottom of the children.
 
void addChildBelow (Widget *child, Widget *sibling)
 Adds widget directly below another widget.
 
void addChildAbove (Widget *child, Widget *sibling)
 
void removeChild (Widget *child)
 Removes widget from list of children if it exists.
 
void clearChildren ()
 Removes and deletes all child Widgets.
 
virtual void step ()
 Advances the module by one frame.
 
virtual void draw (const DrawArgs &args)
 Draws the widget to the NanoVG context.
 
virtual DEPRECATED void draw (NVGcontext *vg)
 Override draw(const DrawArgs &args) instead.
 
virtual void drawLayer (const DrawArgs &args, int layer)
 Draw additional layers.
 
void drawChild (Widget *child, const DrawArgs &args, int layer=0)
 Draws a particular child.
 
template<typename TMethod , class TEvent >
void recurseEvent (TMethod f, const TEvent &e)
 Recurses an event to all visible Widgets.
 
template<typename TMethod , class TEvent >
void recursePositionEvent (TMethod f, const TEvent &e)
 Recurses an event to all visible Widgets until it is consumed.
 
virtual void onHover (const HoverEvent &e)
 
virtual void onButton (const ButtonEvent &e)
 
virtual void onDoubleClick (const DoubleClickEvent &e)
 
virtual void onHoverKey (const HoverKeyEvent &e)
 
virtual void onHoverText (const HoverTextEvent &e)
 
virtual void onHoverScroll (const HoverScrollEvent &e)
 
virtual void onEnter (const EnterEvent &e)
 
virtual void onLeave (const LeaveEvent &e)
 
virtual void onSelect (const SelectEvent &e)
 
virtual void onDeselect (const DeselectEvent &e)
 
virtual void onSelectKey (const SelectKeyEvent &e)
 
virtual void onSelectText (const SelectTextEvent &e)
 
virtual void onDragStart (const DragStartEvent &e)
 
virtual void onDragEnd (const DragEndEvent &e)
 
virtual void onDragMove (const DragMoveEvent &e)
 
virtual void onDragHover (const DragHoverEvent &e)
 
virtual void onDragEnter (const DragEnterEvent &e)
 
virtual void onDragLeave (const DragLeaveEvent &e)
 
virtual void onDragDrop (const DragDropEvent &e)
 
virtual void onPathDrop (const PathDropEvent &e)
 
virtual void onAction (const ActionEvent &e)
 
virtual void onChange (const ChangeEvent &e)
 
virtual void onDirty (const DirtyEvent &e)
 
virtual void onReposition (const RepositionEvent &e)
 
virtual void onResize (const ResizeEvent &e)
 
virtual void onAdd (const AddEvent &e)
 
virtual void onRemove (const RemoveEvent &e)
 
virtual void onShow (const ShowEvent &e)
 
virtual void onHide (const HideEvent &e)
 
virtual void onContextCreate (const ContextCreateEvent &e)
 
virtual void onContextDestroy (const ContextDestroyEvent &e)
 
- Public Member Functions inherited from rack::WeakBase
 ~WeakBase ()
 
size_t getWeakCount ()
 

Public Attributes

math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY))
 Position relative to parent and size of widget.
 
Widgetparent = NULL
 Automatically set when Widget is added as a child to another Widget.
 
std::list< Widget * > children
 
bool visible = true
 Disables rendering but allow stepping.
 
bool requestedDelete = false
 If set to true, parent will delete Widget in the next step().
 
- Public Attributes inherited from rack::WeakBase
WeakHandleweakHandle = nullptr
 

Detailed Description

A node in the 2D scene graph.

The bounding box of a Widget is a rectangle specified by box relative to their parent. The appearance is defined by overriding draw(), and the behavior is defined by overriding step() and on*() event handlers.

Member Typedef Documentation

◆ BaseEvent

Constructor & Destructor Documentation

◆ ~Widget()

virtual rack::widget::Widget::~Widget ( )
virtual

Member Function Documentation

◆ getBox()

math::Rect rack::widget::Widget::getBox ( )

◆ setBox()

void rack::widget::Widget::setBox ( math::Rect box)

Calls setPosition() and then setSize().

◆ getPosition()

math::Vec rack::widget::Widget::getPosition ( )

◆ setPosition()

void rack::widget::Widget::setPosition ( math::Vec pos)

Sets position and triggers RepositionEvent if position changed.

◆ getSize()

math::Vec rack::widget::Widget::getSize ( )

◆ setSize()

void rack::widget::Widget::setSize ( math::Vec size)

Sets size and triggers ResizeEvent if size changed.

◆ getParent()

widget::Widget * rack::widget::Widget::getParent ( )

◆ isVisible()

bool rack::widget::Widget::isVisible ( )

◆ setVisible()

void rack::widget::Widget::setVisible ( bool visible)

Sets visible and triggers ShowEvent or HideEvent if changed.

◆ show()

void rack::widget::Widget::show ( )
inline

Makes Widget visible and triggers ShowEvent if changed.

◆ hide()

void rack::widget::Widget::hide ( )
inline

Makes Widget not visible and triggers HideEvent if changed.

◆ requestDelete()

void rack::widget::Widget::requestDelete ( )

Requests this Widget's parent to delete it in the next step().

◆ getChildrenBoundingBox()

virtual math::Rect rack::widget::Widget::getChildrenBoundingBox ( )
virtual

Returns the smallest rectangle containing this widget's children (visible and invisible) in its local coordinates.

Returns Rect(Vec(inf, inf), Vec(-inf, -inf)) if there are no children.

◆ getVisibleChildrenBoundingBox()

virtual math::Rect rack::widget::Widget::getVisibleChildrenBoundingBox ( )
virtual

◆ isDescendantOf()

bool rack::widget::Widget::isDescendantOf ( Widget * ancestor)

Returns whether ancestor is a parent or distant parent of this widget.

◆ getRelativeOffset()

virtual math::Vec rack::widget::Widget::getRelativeOffset ( math::Vec v,
Widget * ancestor )
virtual

Returns v (given in local coordinates) transformed into the coordinate system of ancestor.

Reimplemented in rack::widget::ZoomWidget.

◆ getAbsoluteOffset()

math::Vec rack::widget::Widget::getAbsoluteOffset ( math::Vec v)
inline

Returns v transformed into world/root/global/absolute coordinates.

◆ getRelativeZoom()

virtual float rack::widget::Widget::getRelativeZoom ( Widget * ancestor)
virtual

Returns the zoom level in the coordinate system of ancestor.

Only ZoomWidget should override this to return value other than 1.

Reimplemented in rack::widget::ZoomWidget.

◆ getAbsoluteZoom()

float rack::widget::Widget::getAbsoluteZoom ( )
inline

◆ getViewport()

virtual math::Rect rack::widget::Widget::getViewport ( math::Rect r = math::Rect::inf())
virtual

Returns a subset of the given Rect bounded by the box of this widget and all ancestors.

Reimplemented in rack::widget::ZoomWidget.

◆ getAncestorOfType()

template<class T >
T * rack::widget::Widget::getAncestorOfType ( )
inline

◆ getFirstDescendantOfType()

template<class T >
T * rack::widget::Widget::getFirstDescendantOfType ( )
inline

◆ hasChild()

bool rack::widget::Widget::hasChild ( Widget * child)

Checks if the given widget is a child of this widget.

◆ addChild()

void rack::widget::Widget::addChild ( Widget * child)

Adds widget to the top of the children.

Gives ownership of widget to this widget instance.

◆ addChildBottom()

void rack::widget::Widget::addChildBottom ( Widget * child)

Adds widget to the bottom of the children.

◆ addChildBelow()

void rack::widget::Widget::addChildBelow ( Widget * child,
Widget * sibling )

Adds widget directly below another widget.

The sibling widget must already be a child of this widget.

◆ addChildAbove()

void rack::widget::Widget::addChildAbove ( Widget * child,
Widget * sibling )

◆ removeChild()

void rack::widget::Widget::removeChild ( Widget * child)

Removes widget from list of children if it exists.

Triggers RemoveEvent of child. Does not delete widget but transfers ownership to caller

◆ clearChildren()

void rack::widget::Widget::clearChildren ( )

Removes and deletes all child Widgets.

Triggers RemoveEvent of all children.

◆ step()

◆ draw() [1/2]

◆ draw() [2/2]

virtual DEPRECATED void rack::widget::Widget::draw ( NVGcontext * vg)
inlinevirtual

Override draw(const DrawArgs &args) instead.

◆ drawLayer()

virtual void rack::widget::Widget::drawLayer ( const DrawArgs & args,
int layer )
virtual

Draw additional layers.

Custom widgets may draw its children multiple times on different layers, passing an arbitrary layer number each time. Layer 0 calls children's draw(). When overriding, always wrap draw commands in if (layer == ...) {} to avoid drawing on all layers. When overriding, call the superclass's drawLayer(args, layer) to recurse to children.

Reimplemented in rack::app::CableWidget, rack::app::LedDisplay, rack::app::LedDisplayChoice, rack::app::LedDisplayTextField, rack::app::LightWidget, rack::app::ModuleWidget, rack::widget::TransformWidget, and rack::widget::ZoomWidget.

◆ drawChild()

void rack::widget::Widget::drawChild ( Widget * child,
const DrawArgs & args,
int layer = 0 )

Draws a particular child.

Saves and restores NanoVG context to prevent changing the given context.

◆ recurseEvent()

template<typename TMethod , class TEvent >
void rack::widget::Widget::recurseEvent ( TMethod f,
const TEvent & e )
inline

Recurses an event to all visible Widgets.

◆ recursePositionEvent()

template<typename TMethod , class TEvent >
void rack::widget::Widget::recursePositionEvent ( TMethod f,
const TEvent & e )
inline

Recurses an event to all visible Widgets until it is consumed.

◆ onHover()

◆ onButton()

◆ onDoubleClick()

virtual void rack::widget::Widget::onDoubleClick ( const DoubleClickEvent & e)
inlinevirtual

◆ onHoverKey()

◆ onHoverText()

virtual void rack::widget::Widget::onHoverText ( const HoverTextEvent & e)
inlinevirtual

◆ onHoverScroll()

◆ onEnter()

virtual void rack::widget::Widget::onEnter ( const EnterEvent & e)
inlinevirtual

◆ onLeave()

virtual void rack::widget::Widget::onLeave ( const LeaveEvent & e)
inlinevirtual

◆ onSelect()

virtual void rack::widget::Widget::onSelect ( const SelectEvent & e)
inlinevirtual

◆ onDeselect()

virtual void rack::widget::Widget::onDeselect ( const DeselectEvent & e)
inlinevirtual

◆ onSelectKey()

virtual void rack::widget::Widget::onSelectKey ( const SelectKeyEvent & e)
inlinevirtual

Reimplemented in rack::ui::TextField.

◆ onSelectText()

virtual void rack::widget::Widget::onSelectText ( const SelectTextEvent & e)
inlinevirtual

Reimplemented in rack::ui::TextField.

◆ onDragStart()

◆ onDragEnd()

◆ onDragMove()

virtual void rack::widget::Widget::onDragMove ( const DragMoveEvent & e)
inlinevirtual

◆ onDragHover()

◆ onDragEnter()

virtual void rack::widget::Widget::onDragEnter ( const DragEnterEvent & e)
inlinevirtual

Reimplemented in rack::app::PortWidget.

◆ onDragLeave()

virtual void rack::widget::Widget::onDragLeave ( const DragLeaveEvent & e)
inlinevirtual

Reimplemented in rack::app::Knob, and rack::app::PortWidget.

◆ onDragDrop()

virtual void rack::widget::Widget::onDragDrop ( const DragDropEvent & e)
inlinevirtual

◆ onPathDrop()

virtual void rack::widget::Widget::onPathDrop ( const PathDropEvent & e)
inlinevirtual

◆ onAction()

◆ onChange()

virtual void rack::widget::Widget::onChange ( const ChangeEvent & e)
inlinevirtual

◆ onDirty()

virtual void rack::widget::Widget::onDirty ( const DirtyEvent & e)
inlinevirtual

◆ onReposition()

virtual void rack::widget::Widget::onReposition ( const RepositionEvent & e)
inlinevirtual

◆ onResize()

virtual void rack::widget::Widget::onResize ( const ResizeEvent & e)
inlinevirtual

◆ onAdd()

virtual void rack::widget::Widget::onAdd ( const AddEvent & e)
inlinevirtual

Reimplemented in rack::app::CableWidget.

◆ onRemove()

virtual void rack::widget::Widget::onRemove ( const RemoveEvent & e)
inlinevirtual

Reimplemented in rack::app::CableWidget.

◆ onShow()

virtual void rack::widget::Widget::onShow ( const ShowEvent & e)
inlinevirtual

◆ onHide()

virtual void rack::widget::Widget::onHide ( const HideEvent & e)
inlinevirtual

◆ onContextCreate()

virtual void rack::widget::Widget::onContextCreate ( const ContextCreateEvent & e)
inlinevirtual

◆ onContextDestroy()

virtual void rack::widget::Widget::onContextDestroy ( const ContextDestroyEvent & e)
inlinevirtual

Member Data Documentation

◆ box

math::Rect rack::widget::Widget::box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY))

Position relative to parent and size of widget.

◆ parent

Widget* rack::widget::Widget::parent = NULL

Automatically set when Widget is added as a child to another Widget.

◆ children

std::list<Widget*> rack::widget::Widget::children

◆ visible

bool rack::widget::Widget::visible = true

Disables rendering but allow stepping.

Use isVisible(), setVisible(), show(), or hide() instead of using this variable directly.

◆ requestedDelete

bool rack::widget::Widget::requestedDelete = false

If set to true, parent will delete Widget in the next step().

Use requestDelete() instead of using this variable directly.


The documentation for this struct was generated from the following file: