HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
tt::Widget Class Reference

#include <TTauri/Widgets/Widget.hpp>

Inheritance diagram for tt::Widget:
tt::ButtonWidget tt::CheckboxWidget< ValueType > tt::ColumnWidget tt::ContainerWidget tt::ImageWidget tt::LineInputWidget tt::RadioButtonWidget< ValueType > tt::RowWidget tt::SystemMenuWidget tt::ToggleWidget< ValueType > tt::ToolbarButtonWidget tt::ToolbarWidget tt::WindowTrafficLightsWidget tt::WindowWidget

Public Member Functions

 Widget (Window &window, Widget *parent, vec defaultExtent) noexcept
 
 Widget (const Widget &)=delete
 
Widgetoperator= (const Widget &)=delete
 
 Widget (Widget &&)=delete
 
Widgetoperator= (Widget &&)=delete
 
virtual WidgetaddWidget (Alignment alignment, std::unique_ptr< Widget > childWidget) noexcept
 Add a widget directly to this widget.
 
template<typename T , typename... Args>
T & makeWidgetDirectly (Args &&... args)
 Add a widget directly to this widget.
 
template<typename T , typename... Args>
T & makeWidget (Args &&... args)
 Add a widget directly to this widget.
 
template<typename T , typename... Args>
T & makeAlignedWidgetDirectly (Alignment alignement, Args &&... args)
 Add a widget directly to this widget.
 
template<typename T , typename... Args>
T & makeAlignedWidget (Alignment alignment, Args &&... args)
 Add a widget directly to this widget.
 
aarect makeWindowRectangle () const noexcept
 Create a window rectangle from left, bottom, width and height Thread-safety: locks window.widgetSolverMutex.
 
void setMinimumExtent (vec newMinimumExtent) noexcept
 
void setMinimumExtent (float width, float height) noexcept
 
void setPreferredExtent (vec newPreferredExtent) noexcept
 
void setFixedExtent (vec newFixedExtent) noexcept
 
void setFixedHeight (float height) noexcept
 
void setFixedWidth (float width) noexcept
 
rhea::constraint placeBelow (Widget const &rhs, float margin=theme->margin) const noexcept
 
rhea::constraint placeAbove (Widget const &rhs, float margin=theme->margin) const noexcept
 
rhea::constraint placeLeftOf (Widget const &rhs, float margin=theme->margin) const noexcept
 
rhea::constraint placeRightOf (Widget const &rhs, float margin=theme->margin) const noexcept
 
rhea::constraint placeAtTop (float margin=theme->margin) const noexcept
 
rhea::constraint placeAtBottom (float margin=theme->margin) const noexcept
 
rhea::constraint placeLeft (float margin=theme->margin) const noexcept
 
rhea::constraint placeRight (float margin=theme->margin) const noexcept
 
vec extent () const noexcept
 
void setExtent (vec rhs) noexcept
 
vec offsetFromParent () const noexcept
 
void setOffsetFromParent (vec rhs) noexcept
 
vec offsetFromWindow () const noexcept
 
void setOffsetFromWindow (vec rhs) noexcept
 
aarect rectangle () const noexcept
 Get the rectangle in local coordinates.
 
aarect windowRectangle () const noexcept
 Get the rectangle in window coordinates.
 
aarect clippingRectangle () const noexcept
 Get the clipping-rectangle in window coordinates.
 
GUIDevicedevice () const noexcept
 
virtual HitBox hitBoxTest (vec position) const noexcept
 Find the widget that is under the mouse cursor.
 
virtual bool acceptsFocus () const noexcept
 Check if the widget will accept keyboard focus.
 
ssize_t nestingLevel () noexcept
 Get nesting level used for selecting colors for the widget.
 
float z () noexcept
 Get z value for compositing order.
 
virtual int needs (hires_utc_clock::time_point displayTimePoint) noexcept
 Request the needs of the widget.
 
virtual void layout (hires_utc_clock::time_point displayTimePoint) noexcept
 Layout the widget.
 
int layoutChildren (hires_utc_clock::time_point displayTimePoint, bool force) noexcept
 Layout children of this widget.
 
virtual void draw (DrawContext const &drawContext, hires_utc_clock::time_point displayTimePoint) noexcept
 Draw widget.
 
virtual void handleCommand (string_ltag command) noexcept
 Handle command.
 
virtual void handleMouseEvent (MouseEvent const &event) noexcept
 
std::vector< Widget * > childPointers (bool reverse) const noexcept
 
virtual WidgetnextKeyboardWidget (Widget const *currentKeyboardWidget, bool reverse) const noexcept
 
virtual void handleKeyboardEvent (KeyboardEvent const &event) noexcept
 

Data Fields

rhea::variable const left
 Location of the frame compared to the window.
 
rhea::variable const bottom
 
rhea::variable const width
 
rhea::variable const height
 
rhea::linear_expression const right = left + width
 
rhea::linear_expression const centre = left + width * 0.5
 
rhea::linear_expression const top = bottom + height
 
rhea::linear_expression const middle = bottom + height * 0.5
 
float elevation
 
std::atomic< R32G32SFloat_extent
 
std::atomic< R32G32SFloat_offsetFromParent
 
std::atomic< R32G32SFloat_offsetFromWindow
 
std::atomic< bool > forceLayout = true
 
std::atomic< bool > forceRedraw = true
 
observable< bool > enabled = true
 The widget is enabled.
 

Detailed Description

View of a widget. A view contains the dynamic data for a Widget. It is often accompanied with a Backing which contains that static data of an Widget and the drawing code. Backings are shared between Views.

Thread-safety: All method of the widget should lock the mutex, exceptions are: hitBoxTest(), needs() All public members should be thread-safe, for example: std::atomic and tt::observer The following methods should only be called from the render thread: needs(), layout(), layoutChildren(), draw(),

Constructor & Destructor Documentation

◆ Widget()

tt::Widget::Widget ( Window & window,
Widget * parent,
vec defaultExtent )
noexcept

Constructor for creating sub views.

Member Function Documentation

◆ acceptsFocus()

virtual bool tt::Widget::acceptsFocus ( ) const
inlinevirtualnoexcept

Check if the widget will accept keyboard focus.

Thread safety: reads atomics.

Reimplemented in tt::ButtonWidget, tt::CheckboxWidget< ValueType >, tt::LineInputWidget, tt::RadioButtonWidget< ValueType >, and tt::ToggleWidget< ValueType >.

◆ addWidget()

virtual Widget & tt::Widget::addWidget ( Alignment alignment,
std::unique_ptr< Widget > childWidget )
virtualnoexcept

Add a widget directly to this widget.

Thread safety: locks.

Reimplemented in tt::ColumnWidget, tt::RowWidget, and tt::ToolbarWidget.

◆ clippingRectangle()

aarect tt::Widget::clippingRectangle ( ) const
inlinenoexcept

Get the clipping-rectangle in window coordinates.

Thread safety: calls windowRectangle()

◆ draw()

virtual void tt::Widget::draw ( DrawContext const & drawContext,
hires_utc_clock::time_point displayTimePoint )
virtualnoexcept

Draw widget.

The overriding function should call the base class's draw(), the place where the call this function will determine the order of the vertices into each buffer. This is important when needing to do the painters algorithm for alpha-compositing. However the pipelines are always drawn in the same order.

Thread safety: locks, must be called from render-thread

Reimplemented in tt::ButtonWidget, tt::CheckboxWidget< ValueType >, tt::ImageWidget, tt::LineInputWidget, tt::RadioButtonWidget< ValueType >, tt::SystemMenuWidget, tt::ToggleWidget< ValueType >, tt::ToolbarButtonWidget, tt::ToolbarWidget, and tt::WindowTrafficLightsWidget.

◆ handleCommand()

virtual void tt::Widget::handleCommand ( string_ltag command)
virtualnoexcept

◆ handleKeyboardEvent()

virtual void tt::Widget::handleKeyboardEvent ( KeyboardEvent const & event)
inlinevirtualnoexcept

Handle keyboard event. Called by the operating system when editing text, or entering special keys

Thread safety: locks

Reimplemented in tt::LineInputWidget.

◆ handleMouseEvent()

virtual void tt::Widget::handleMouseEvent ( MouseEvent const & event)
inlinevirtualnoexcept

Handle mouse event. Called by the operating system to show the position and button state of the mouse. This is called very often so it must be made efficient. This function is also used to determine the mouse cursor.

Thread safety: locks

Reimplemented in tt::ButtonWidget, tt::CheckboxWidget< ValueType >, tt::ImageWidget, tt::LineInputWidget, tt::RadioButtonWidget< ValueType >, tt::ToggleWidget< ValueType >, tt::ToolbarButtonWidget, and tt::WindowTrafficLightsWidget.

◆ hitBoxTest()

virtual HitBox tt::Widget::hitBoxTest ( vec position) const
virtualnoexcept

◆ layout()

virtual void tt::Widget::layout ( hires_utc_clock::time_point displayTimePoint)
virtualnoexcept

Layout the widget.

super::layout() should be called at start of the overriden function.

Thread safety: locks, must be called from render-thread

Reimplemented in tt::ButtonWidget, tt::CheckboxWidget< ValueType >, tt::ImageWidget, tt::LineInputWidget, tt::RadioButtonWidget< ValueType >, tt::SystemMenuWidget, tt::ToggleWidget< ValueType >, and tt::WindowTrafficLightsWidget.

◆ layoutChildren()

int tt::Widget::layoutChildren ( hires_utc_clock::time_point displayTimePoint,
bool force )
noexcept

Layout children of this widget.

Thread safety: locks, must be called from render-thread

Parameters
forceForce the layout of the widget.

◆ makeAlignedWidget()

template<typename T , typename... Args>
T & tt::Widget::makeAlignedWidget ( Alignment alignment,
Args &&... args )
inline

Add a widget directly to this widget.

Thread safety: modifies atomic. calls addWidget() and addWidgetDirectly()

◆ makeAlignedWidgetDirectly()

template<typename T , typename... Args>
T & tt::Widget::makeAlignedWidgetDirectly ( Alignment alignement,
Args &&... args )
inline

Add a widget directly to this widget.

Thread safety: calls _addWidget

◆ makeWidget()

template<typename T , typename... Args>
T & tt::Widget::makeWidget ( Args &&... args)
inline

Add a widget directly to this widget.

Thread safety: modifies atomic. calls addWidget() and addWidgetDirectly()

◆ makeWidgetDirectly()

template<typename T , typename... Args>
T & tt::Widget::makeWidgetDirectly ( Args &&... args)
inline

Add a widget directly to this widget.

Thread safety: calls _addWidget

◆ makeWindowRectangle()

aarect tt::Widget::makeWindowRectangle ( ) const
noexcept

Create a window rectangle from left, bottom, width and height Thread-safety: locks window.widgetSolverMutex.

◆ needs()

virtual int tt::Widget::needs ( hires_utc_clock::time_point displayTimePoint)
virtualnoexcept

Request the needs of the widget.

This function will be called for each widget on each frame. Therefor it is important to optimize this function.

Thread safety: reads atomics, must be called from render-thread.

Returns
If the widgets needs to be redrawn or layed out on this frame.

Reimplemented in tt::LineInputWidget.

◆ nestingLevel()

ssize_t tt::Widget::nestingLevel ( )
inlinenoexcept

Get nesting level used for selecting colors for the widget.

◆ rectangle()

aarect tt::Widget::rectangle ( ) const
inlinenoexcept

Get the rectangle in local coordinates.

Thread safety: reads atomics.

◆ windowRectangle()

aarect tt::Widget::windowRectangle ( ) const
inlinenoexcept

Get the rectangle in window coordinates.

Thread safety: reads atomics.

◆ z()

float tt::Widget::z ( )
inlinenoexcept

Get z value for compositing order.

Field Documentation

◆ enabled

observable<bool> tt::Widget::enabled = true

The widget is enabled.

◆ left

rhea::variable const tt::Widget::left

Location of the frame compared to the window.

Thread-safety: the box is not modified by the class.


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