Dusk Audio Framework
Loading...
Searching...
No Matches
Widget Class Reference

#include <Widget.hpp>

Inheritance diagram for Widget:
SubWidget TopLevelWidget CairoBaseWidget< SubWidget > ImageBaseButton< CairoImage > ImageBaseButton< OpenGLImage > ImageBaseKnob< CairoImage > ImageBaseKnob< OpenGLImage > ImageBaseSlider< CairoImage > ImageBaseSlider< OpenGLImage > ImageBaseSwitch< CairoImage > ImageBaseSwitch< OpenGLImage > NanoBaseWidget< SubWidget > ImageBaseButton< ImageType > ImageBaseKnob< ImageType > ImageBaseSlider< ImageType > ImageBaseSwitch< ImageType > CairoBaseWidget< TopLevelWidget > NanoBaseWidget< TopLevelWidget > StandaloneWindow

Classes

struct  BaseEvent
struct  KeyboardEvent
struct  CharacterInputEvent
struct  MouseEvent
struct  MotionEvent
struct  ScrollEvent
struct  ResizeEvent
struct  FocusEvent
struct  PositionChangedEvent

Public Member Functions

virtual ~Widget ()
bool isVisible () const noexcept
void setVisible (bool visible)
void show ()
void hide ()
uint getWidth () const noexcept
uint getHeight () const noexcept
const Size< uint > getSize () const noexcept
void setWidth (uint width) noexcept
void setHeight (uint height) noexcept
void setSize (uint width, uint height) noexcept
void setSize (const Size< uint > &size) noexcept
uint getId () const noexcept
const char * getName () const noexcept
void setId (uint id) noexcept
void setName (const char *name) noexcept
Application & getApp () const noexcept
Window & getWindow () const noexcept
const GraphicsContext & getGraphicsContext () const noexcept
TopLevelWidget * getTopLevelWidget () const noexcept
std::list< SubWidget * > getChildren () const noexcept
virtual void repaint () noexcept
virtual bool wantsKeyboardFocus ()
Application & getParentApp () const noexcept
Window & getParentWindow () const noexcept

Protected Member Functions

virtual void onDisplay ()
virtual bool onKeyboard (const KeyboardEvent &)
virtual bool onCharacterInput (const CharacterInputEvent &)
virtual bool onMouse (const MouseEvent &)
virtual bool onMotion (const MotionEvent &)
virtual bool onScroll (const ScrollEvent &)
virtual void onResize (const ResizeEvent &)
virtual void onFocusChanged (const FocusEvent &)
virtual bool onSpecial (const SpecialEvent &)

Friends

class SubWidget
class TopLevelWidget

Detailed Description

Base DGL Widget class.

This is the base Widget class, from which all widgets are built.

All widgets have a parent widget where they'll be drawn, this can be the top-level widget or a group widget. This parent is never changed during a widget's lifetime.

Widgets receive events in relative coordinates. (0, 0) means its top-left position.

The top-level widget will draw subwidgets in the order they are constructed. Early subwidgets are drawn first, at the bottom, then newer ones on top. Events are sent in the inverse order so that the top-most widgets get a chance to catch the event and stop its propagation.

All widget event callbacks do nothing by default and onDisplay MUST be reimplemented by subclasses.

Note
It is not possible to subclass this Widget class directly, you must use SubWidget or TopLevelWidget instead.

Constructor & Destructor Documentation

◆ ~Widget()

virtual Widget::~Widget ( )
virtual

Destructor.

Member Function Documentation

◆ isVisible()

bool Widget::isVisible ( ) const
noexcept

Check if this widget is visible within its parent window. Invisible widgets do not receive events except resize.

◆ setVisible()

void Widget::setVisible ( bool visible)

Set widget visible (or not) according to visible.

◆ show()

void Widget::show ( )

Show widget. This is the same as calling setVisible(true).

◆ hide()

void Widget::hide ( )

Hide widget. This is the same as calling setVisible(false).

◆ getWidth()

uint Widget::getWidth ( ) const
noexcept

Get width.

◆ getHeight()

uint Widget::getHeight ( ) const
noexcept

Get height.

◆ getSize()

const Size< uint > Widget::getSize ( ) const
noexcept

Get size.

◆ setWidth()

void Widget::setWidth ( uint width)
noexcept

Set width.

◆ setHeight()

void Widget::setHeight ( uint height)
noexcept

Set height.

◆ setSize() [1/2]

void Widget::setSize ( uint width,
uint height )
noexcept

Set size using width and height values.

◆ setSize() [2/2]

void Widget::setSize ( const Size< uint > & size)
noexcept

Set size.

◆ getId()

uint Widget::getId ( ) const
noexcept

Get the Id associated with this widget. Returns 0 by default.

See also
setId

◆ getName()

const char * Widget::getName ( ) const
noexcept

Get the name associated with this widget. This is completely optional, mostly useful for debugging purposes. Returns an empty string by default.

See also
setName

◆ setId()

void Widget::setId ( uint id)
noexcept

Set an Id to be associated with this widget.

See also
getId

◆ setName()

void Widget::setName ( const char * name)
noexcept

Set a name to be associated with this widget. This is completely optional, only useful for debugging purposes.

Note
name must not be null
See also
getName

◆ getApp()

Application & Widget::getApp ( ) const
noexcept

Get the application associated with this widget's window. This is the same as calling getTopLevelWidget()->getApp().

◆ getWindow()

Window & Widget::getWindow ( ) const
noexcept

Get the window associated with this widget. This is the same as calling getTopLevelWidget()->getWindow().

◆ getGraphicsContext()

const GraphicsContext & Widget::getGraphicsContext ( ) const
noexcept

Get the graphics context associated with this widget's window. GraphicsContext is an empty struct and needs to be casted into a different type in order to be usable, for example GraphicsContext.

See also
CairoSubWidget, CairoTopLevelWidget

◆ getTopLevelWidget()

TopLevelWidget * Widget::getTopLevelWidget ( ) const
noexcept

Get top-level widget, as passed directly in the constructor or going up the chain of group widgets until it finds the top-level one.

◆ getChildren()

std::list< SubWidget * > Widget::getChildren ( ) const
noexcept

Get list of children (a subwidgets) that belong to this widget.

◆ repaint()

virtual void Widget::repaint ( )
virtualnoexcept

Request repaint of this widget's area to the window this widget belongs to. On the raw Widget class this function does nothing.

Reimplemented in StandaloneWindow, SubWidget, and TopLevelWidget.

◆ wantsKeyboardFocus()

virtual bool Widget::wantsKeyboardFocus ( )
virtual

Whether this widget wants the keyboard focus right now, typically because a text field in it is being edited.

This reports the widget's own state only. Window::anyWidgetWantsKeyboardFocus() asks every visible widget of a window, subwidgets included, so an override does not need to ask its children.

An embedded plugin editor on Windows uses the answer in the formats whose hosts have no keyboard focus API (CLAP and VST2): the editor takes the focus when clicked, keeps it while some widget wants it and hands it back to the host window once none does, so host shortcuts keep working after a click on a knob. Elsewhere the answer is informational.

It is asked on every idle of such an editor, so it should be cheap. The default implementation returns false.

◆ onDisplay()

◆ onKeyboard()

virtual bool Widget::onKeyboard ( const KeyboardEvent & )
protectedvirtual

A function called when a key is pressed or released.

Returns
True to stop event propagation, false otherwise.

Reimplemented in ImageBaseAboutWindow< ImageType >, ImageBaseAboutWindow< CairoImage >, ImageBaseAboutWindow< OpenGLImage >, and TopLevelWidget.

◆ onCharacterInput()

virtual bool Widget::onCharacterInput ( const CharacterInputEvent & )
protectedvirtual

A function called when an UTF-8 character is received.

Returns
True to stop event propagation, false otherwise.

Reimplemented in TopLevelWidget.

◆ onMouse()

◆ onMotion()

virtual bool Widget::onMotion ( const MotionEvent & )
protectedvirtual

◆ onScroll()

virtual bool Widget::onScroll ( const ScrollEvent & )
protectedvirtual

A function called on scrolling (e.g. mouse wheel or track pad).

Returns
True to stop event propagation, false otherwise.

Reimplemented in ImageBaseKnob< ImageType >, ImageBaseKnob< CairoImage >, ImageBaseKnob< OpenGLImage >, and TopLevelWidget.

◆ onResize()

virtual void Widget::onResize ( const ResizeEvent & )
protectedvirtual

A function called when the widget is resized.

◆ onFocusChanged()

virtual void Widget::onFocusChanged ( const FocusEvent & )
protectedvirtual

A function called when the window this widget belongs to gains or loses the keyboard focus. Unlike the input events this is delivered to every widget, visible or not, so that a widget holding input state can clear it.

Note
The window itself has its own Window::onFocus, this is the widget-side view of it.

◆ onSpecial()

virtual bool Widget::onSpecial ( const SpecialEvent & )
inlineprotectedvirtual

A function called when a special key is pressed or released. DEPRECATED use onKeyboard or onCharacterInput


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