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::abstract_button_widget tt::grid_widget tt::icon_widget tt::label_widget tt::overlay_widget tt::row_column_widget< Axis > tt::scroll_bar_widget< Axis > tt::scroll_widget< Axis, ControlsWindow > tt::selection_widget tt::system_menu_widget tt::tab_widget tt::text_field_widget tt::text_widget tt::toolbar_widget tt::window_traffic_lights_widget tt::window_widget

Public Member Functions

 widget (gui_window &window, widget *parent) noexcept
 
 widget (const widget &)=delete
 
widgetoperator= (const widget &)=delete
 
 widget (widget &&)=delete
 
widgetoperator= (widget &&)=delete
 
virtual void init () noexcept
 Should be called right after allocating and constructing a widget.
 
virtual void deinit () noexcept
 Should be called right after allocating and constructing a widget.
 
virtual float margin () const noexcept
 Get the margin around the Widget.
 
extent2 minimum_size () const noexcept
 Minimum size.
 
extent2 preferred_size () const noexcept
 Preferred size.
 
extent2 maximum_size () const noexcept
 Maximum size.
 
void set_layout_parameters (geo::transformer auto const &local_to_parent, extent2 size, aarectangle const &clipping_rectangle) noexcept
 Set the location and size of the widget inside the window.
 
void set_layout_parameters_from_parent (aarectangle child_rectangle, aarectangle parent_clipping_rectangle, float draw_layer_delta) noexcept
 
void set_layout_parameters_from_parent (aarectangle child_rectangle) noexcept
 
matrix3 parent_to_local () const noexcept
 
matrix3 local_to_parent () const noexcept
 
matrix3 window_to_local () const noexcept
 
matrix3 local_to_window () const noexcept
 
extent2 size () const noexcept
 
float width () const noexcept
 
float height () const noexcept
 
aarectangle rectangle () const noexcept
 Get the rectangle in local coordinates.
 
virtual float base_line () const noexcept
 Return the base-line where the text should be located.
 
aarectangle clipping_rectangle () const noexcept
 
virtual hitbox hitbox_test (point2 position) const noexcept
 Find the widget that is under the mouse cursor.
 
virtual bool accepts_keyboard_focus (keyboard_focus_group group) const noexcept
 Check if the widget will accept keyboard focus.
 
virtual bool constrain (hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
 Update the constraints of the widget.
 
virtual void layout (hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
 Update the internal layout of the widget.
 
virtual color background_color () const noexcept
 
virtual color foreground_color () const noexcept
 
virtual color focus_color () const noexcept
 
virtual color accent_color () const noexcept
 
virtual color label_color () const noexcept
 
virtual void draw (draw_context context, hires_utc_clock::time_point display_time_point) noexcept
 Draw the widget.
 
virtual void request_redraw () const noexcept
 
virtual bool handle_event (command command) noexcept
 Handle command.
 
virtual bool handle_event (std::vector< command > const &commands) noexcept
 
virtual bool handle_command_recursive (command command, std::vector< widget const * > const &reject_list) noexcept
 Handle command recursive.
 
virtual bool handle_event (mouse_event const &event) noexcept
 
virtual bool handle_event (keyboard_event const &event) noexcept
 Handle keyboard event.
 
virtual widget const * find_next_widget (widget const *current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
 Find the next widget that handles keyboard focus.
 
widget const * find_first_widget (keyboard_focus_group group) const noexcept
 
widget const * find_last_widget (keyboard_focus_group group) const noexcept
 
bool is_first (keyboard_focus_group group) const noexcept
 Is this widget the first widget in the parent container.
 
bool is_last (keyboard_focus_group group) const noexcept
 Is this widget the last widget in the parent container.
 
virtual void scroll_to_show (tt::rectangle rectangle) noexcept
 Scroll to show the given rectangle on the window.
 
std::vector< widget const * > parent_chain () const noexcept
 Get a list of parents of a given widget.
 
void clear () noexcept
 Remove and deallocate all child widgets.
 
widgetadd_widget (std::unique_ptr< widget > widget) noexcept
 Add a widget directly to this widget.
 

Data Fields

gui_windowwindow
 Convenient reference to the Window.
 
widget *const parent
 Pointer to the parent widget.
 
std::string id
 A name of widget, should be unique between siblings.
 
observable< bool > enabled = true
 The widget is enabled.
 
observable< bool > visible = true
 The widget is visible.
 
float draw_layer
 The draw layer of the widget.
 
int semantic_layer
 The draw layer of the widget.
 
int logical_layer
 The logical layer of the widget.
 

Detailed Description

An interactive graphical object as part of the user-interface.

Rendering is done in four distinct phases:

  1. Updating Constraints: widget::constrain()
  2. Update layout parameters widget::set_layout_parameters()
  3. Updating Layout: widget::layout()
  4. Drawing: widget::draw()

Constructor & Destructor Documentation

◆ widget()

tt::widget::widget ( gui_window & window,
widget * parent )
noexcept

Constructor for creating sub views.

Member Function Documentation

◆ accepts_keyboard_focus()

virtual bool tt::widget::accepts_keyboard_focus ( keyboard_focus_group group) const
inlinevirtualnoexcept

Check if the widget will accept keyboard focus.

Precondition
mutex must be locked by current thread.

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ add_widget()

widget & tt::widget::add_widget ( std::unique_ptr< widget > widget)
noexcept

Add a widget directly to this widget.

Thread safety: locks.

◆ base_line()

virtual float tt::widget::base_line ( ) const
virtualnoexcept

Return the base-line where the text should be located.

Returns
Number of pixels from the bottom of the widget where the base-line is located.

◆ clear()

void tt::widget::clear ( )
noexcept

Remove and deallocate all child widgets.

◆ constrain()

virtual bool tt::widget::constrain ( hires_utc_clock::time_point display_time_point,
bool need_reconstrain )
virtualnoexcept

Update the constraints of the widget.

This function is called on each vertical sync, even if no drawing is to be done.

This function may be used for expensive calculations, such as text-shaping, which should only be done when the data changes. Because this function is called on every vertical sync it should cache these calculations.

Subclasses should call constrain() on its base-class to check if its or any of its children's constraints where changed, before doing specific constraining

If the container, due to a change in constraints, wants the window to resize to the minimum size it should set window::request_resize to true.

Postcondition
This function will change what is returned by widget::minimum_size(), widget::preferred_size() and widget::maximum_size().
Parameters
display_time_pointThe time point when the widget will be shown on the screen.
need_reconstrainForce the widget to re-constrain.
Returns
True if its or any children's constraints has changed.

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ deinit()

virtual void tt::widget::deinit ( )
virtualnoexcept

Should be called right after allocating and constructing a widget.

◆ draw()

virtual void tt::widget::draw ( draw_context context,
hires_utc_clock::time_point display_time_point )
virtualnoexcept

Draw the widget.

This function is called by the window (optionally) on every frame. It should recursively call this function on every visible child. This function is only called when updateLayout() has returned true.

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.

Precondition
mutex must be locked by current thread.
Parameters
contextThe context to where the widget will draw.
display_time_pointThe time point when the widget will be shown on the screen.

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ find_next_widget()

virtual widget const * tt::widget::find_next_widget ( widget const * current_keyboard_widget,
keyboard_focus_group group,
keyboard_focus_direction direction ) const
virtualnoexcept

Find the next widget that handles keyboard focus.

This recursively looks for the current keyboard widget, then returns the next (or previous) widget that returns true from accepts_keyboard_focus().

Parameters
current_keyboard_widgetThe widget that currently has focus; or empty to get the first widget that accepts focus.
groupThe group to which the widget must belong.
directionThe direction in which to walk the widget tree.
Returns
A pointer to the next widget.
Return values
currentKeyboardWidgetwhen currentKeyboardWidget was found but no next widget was found.
emptywhen currentKeyboardWidget is not found in this Widget.

◆ handle_command_recursive()

virtual bool tt::widget::handle_command_recursive ( command command,
std::vector< widget const * > const & reject_list )
virtualnoexcept

Handle command recursive.

Handle a command and pass it to each child.

Parameters
commandThe command to handle by this widget.
reject_listThe widgets that should ignore this command
Returns
True when the command was handled by this widget or recursed child.

◆ handle_event() [1/3]

virtual bool tt::widget::handle_event ( command command)
virtualnoexcept

Handle command.

If a widget does not fully handle a command it should pass the command to the super class' handle_event().

◆ handle_event() [2/3]

virtual bool tt::widget::handle_event ( keyboard_event const & event)
virtualnoexcept

Handle keyboard event.

Called by the operating system when editing text, or entering special keys

Parameters
eventThe keyboard event.
Returns
If this widget has handled the keyboard event.

◆ handle_event() [3/3]

virtual bool tt::widget::handle_event ( mouse_event const & event)
virtualnoexcept

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.

In most cased overriding methods should call the super's handle_event() at the start of the function, to detect hover.

When this method does not handle the event the window will call handle_event() on the widget's parent.

Parameters
eventThe mouse event, positions are in window coordinates.
Returns
If this widget has handled the mouse event.

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ hitbox_test()

virtual hitbox tt::widget::hitbox_test ( point2 position) const
virtualnoexcept

Find the widget that is under the mouse cursor.

This function will recursively test with visual child widgets, when widgets overlap on the screen the hitbox object with the highest elevation is returned.

Parameters
positionThe coordinate of the mouse local to the widget.
Returns
A hit_box object with the cursor-type and a reference to the widget.

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ init()

virtual void tt::widget::init ( )
virtualnoexcept

Should be called right after allocating and constructing a widget.

◆ is_first()

bool tt::widget::is_first ( keyboard_focus_group group) const
noexcept

Is this widget the first widget in the parent container.

◆ is_last()

bool tt::widget::is_last ( keyboard_focus_group group) const
noexcept

Is this widget the last widget in the parent container.

◆ layout()

virtual void tt::widget::layout ( hires_utc_clock::time_point display_time_point,
bool need_layout )
virtualnoexcept

Update the internal layout of the widget.

This function is called on each vertical sync, even if no drawing is to be done.

This function may be used for expensive calculations, such as geometry calculations, which should only be done when the data or sizes change. Because this function is called on every vertical sync it should cache these calculations.

Subclasses should call widget::set_layout_parameters() to position and size each child relative to this widget. At the end of the function the subclass should call layout() on its base-class to recursively update the layout of the children.

Precondition
widget::set_layout_parameters() should be called.
Postcondition
This function will change what is returned by widget::size() and the transformation matrices.
Parameters
display_time_pointThe time point when the widget will be shown on the screen.
need_layoutForce the widget to layout

Reimplemented in tt::scroll_bar_widget< Axis >.

◆ margin()

virtual float tt::widget::margin ( ) const
virtualnoexcept

Get the margin around the Widget.

A container widget should layout the children in such a way that the maximum margin of neighboring widgets is maintained.

Precondition
mutex must be locked by current thread.
Returns
The margin for this widget.

◆ maximum_size()

extent2 tt::widget::maximum_size ( ) const
noexcept

Maximum size.

The maximum size of a widget. Containers will try to not grow a widget beyond the maximum size, but it may do so to satisfy the minimum constraint on a neighboring widget. For windows the maximum size becomes a hard limit for the window size.

◆ minimum_size()

extent2 tt::widget::minimum_size ( ) const
noexcept

Minimum size.

The absolute minimum size of the widget. A container will never reserve less space for the widget. For windows this size becomes a hard limit for the minimum window size.

◆ parent_chain()

std::vector< widget const * > tt::widget::parent_chain ( ) const
noexcept

Get a list of parents of a given widget.

The chain includes the given widget.

◆ preferred_size()

extent2 tt::widget::preferred_size ( ) const
noexcept

Preferred size.

The preferred size of a widget. Containers will initialize their layout algorithm at this size before growing or shrinking. For scroll-views this size will be used in the scroll-direction. For tab-views this is propagated. For windows this size is used to set the initial window size.

◆ rectangle()

aarectangle tt::widget::rectangle ( ) const
noexcept

Get the rectangle in local coordinates.

Precondition
mutex must be locked by current thread.

◆ scroll_to_show()

virtual void tt::widget::scroll_to_show ( tt::rectangle rectangle)
virtualnoexcept

Scroll to show the given rectangle on the window.

This will call parents, until all parents have scrolled the rectangle to be shown on the window.

◆ set_layout_parameters()

void tt::widget::set_layout_parameters ( geo::transformer auto const & local_to_parent,
extent2 size,
aarectangle const & clipping_rectangle )
noexcept

Set the location and size of the widget inside the window.

The parent should call this set_layout_paramters() before this updateLayout().

If the parent's layout did not change, it does not need to call this set_layout_parameters(). This way the parent does not need to keep a cache, recalculate or query the client for these layout parameters for each frame.

Precondition
mutex must be locked by current thread.

Field Documentation

◆ draw_layer

float tt::widget::draw_layer

The draw layer of the widget.

Drawing layers start at 0.0 and go up to 100.0.

Each child widget that has drawing to do increases the layer by 1.0.

The widget should draw within 0.0 and 1.0 of its drawing layer. The toWindowTransfer and the DrawingContext will already include the draw_layer.

An overlay widget such as pop-ups will increase the layer by 25.0, to make sure the overlay will draw above other widgets in the window. *

◆ enabled

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

The widget is enabled.

When a widget is disabled it is drawn in gray and will not react to user input.

◆ id

std::string tt::widget::id

A name of widget, should be unique between siblings.

◆ logical_layer

int tt::widget::logical_layer

The logical layer of the widget.

The logical layer can be used to determine how far away from the window-widget (root) the current widget is.

Logical layers start at 0 for the window-widget. Each child widget increases the logical layer by 1.

◆ parent

widget* const tt::widget::parent

Pointer to the parent widget.

May be a nullptr only when this is the top level widget.

◆ semantic_layer

int tt::widget::semantic_layer

The draw layer of the widget.

The semantic layer is used mostly by the draw() function for selecting colors from the theme, to denote nesting widgets inside other widgets.

Semantic layers start at 0 for the window-widget and for any pop-up widgets.

The semantic layer is increased by one, whenever a user of the user-interface would understand the next layer to begin.

In most cases it would mean that a container widget that does not draw itself will not increase the semantic_layer number.

◆ visible

observable<bool> tt::widget::visible = true

The widget is visible.

When a widget is invisible it will not be layout or drawn.

◆ window

gui_window& tt::widget::window

Convenient reference to the Window.


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