|
HikoGUI
A low latency retained GUI
|
#include <ttauri/widgets/widget.hpp>
Public Member Functions | |
| widget (gui_window &window, std::shared_ptr< abstract_container_widget > parent) noexcept | |
| widget (const widget &)=delete | |
| widget & | operator= (const widget &)=delete |
| widget (widget &&)=delete | |
| widget & | operator= (widget &&)=delete |
| virtual void | init () noexcept |
| Should be called right after allocating and constructing a widget. | |
| float | margin () const noexcept |
| Get the margin around the Widget. | |
| float | draw_layer () const noexcept |
| The first drawing layer of the widget. | |
| int | logical_layer () const noexcept |
| The logical layer of the widget. | |
| int | semantic_layer () const noexcept |
| The semantic layer of the widget. | |
| ranged_int< 3 > | width_resistance () const noexcept |
| Get the resistance in width. | |
| ranged_int< 3 > | height_resistance () const noexcept |
| Get the resistance in height. | |
| interval_vec2 | preferred_size () const noexcept |
| Get the size-range of the widget. | |
| relative_base_line | preferred_base_line () const noexcept |
| Get the relative_base_line of the widget. | |
| void | set_layout_parameters (aarect const &window_rectangle, aarect const &window_clipping_rectangle, float window_base_line=std::numeric_limits< float >::infinity()) noexcept |
| Set the location and size of the widget inside the window. | |
| aarect | window_rectangle () const noexcept |
| Get the rectangle in window coordinates. | |
| virtual aarect | window_clipping_rectangle () const noexcept |
| Get the clipping-rectangle in window coordinates. | |
| float | window_base_line () const noexcept |
| Get the base-line distance from the bottom of the window. | |
| aarect | rectangle () const noexcept |
| Get the rectangle in local coordinates. | |
| float | base_line () const noexcept |
| Get the base-line in local coordinates. | |
| gui_device * | device () const noexcept |
| virtual hit_box | hitbox_test (f32x4 window_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 | update_constraints (hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept |
| Update the constraints of the widget. | |
| virtual void | update_layout (hires_utc_clock::time_point display_time_point, bool need_layout) noexcept |
| Update the internal layout of the widget. | |
| virtual draw_context | make_draw_context (draw_context context) const noexcept |
| Make a draw context for this widget. | |
| virtual void | draw (draw_context context, hires_utc_clock::time_point display_time_point) noexcept |
| Draw the widget. | |
| 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< std::shared_ptr< widget > > 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 std::shared_ptr< widget > | find_next_widget (std::shared_ptr< widget > const ¤t_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept |
| Find the next widget that handles keyboard focus. | |
| std::shared_ptr< abstract_container_widget const > | shared_parent () const noexcept |
| Get a shared_ptr to the parent. | |
| std::shared_ptr< abstract_container_widget > | shared_parent () noexcept |
| Get a shared_ptr to the parent. | |
| abstract_container_widget const & | parent () const noexcept |
| Get a reference to the parent. | |
| abstract_container_widget & | parent () noexcept |
| Get a reference to the parent. | |
| 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. | |
Public Member Functions inherited from std::enable_shared_from_this< widget > | |
| T | enable_shared_from_this (T... args) |
| T | operator= (T... args) |
| T | shared_from_this (T... args) |
| T | ~enable_shared_from_this (T... args) |
Static Public Member Functions | |
| static std::vector< std::shared_ptr< widget > > | parent_chain (std::shared_ptr< tt::widget > const &child_widget) noexcept |
| Get a list of parents of a given widget. | |
Data Fields | |
| gui_window & | window |
| Convenient reference to the Window. | |
| observable< bool > | enabled = true |
| The widget is enabled. | |
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.
All methods should make sure the mutex is locked by the current thread.
Rendering is done in three distinct phases:
Each of these phases is executed to completion for all widget belonging to a window before the next phases is executed.
In this phases the widget will update the constraints to determine the position and size of the widget inside the window.
The updateConstraints() function will be called on each widget recursively. You should minimize the cost of this function as much as possible.
Since this function is called on each frame, the widget should first check if constraint changes are needed.
A widget should return true if any of the constraints has changed.
A widget may update its internal (expensive) layout calculations from the updateLayout() function.
Since this function is called on each frame, the widget should first check if layout calculations are needed. If a constraint has changed (the window size is also a constraint) then the forceLayout flag is set.
A widget should return true if the window needs to be redrawn.
A widget can draw itself when the draw() function is called. This phase is only entered when one of the widget's layout was changed. But if this phase is entered then all the widgets' draw() functions are called.
|
noexcept |
Constructor for creating sub views.
|
inlinevirtualnoexcept |
Check if the widget will accept keyboard focus.
mutex must be locked by current thread. Reimplemented in tt::abstract_button_widget< T >, tt::abstract_button_widget< bool >, tt::abstract_button_widget< value_type >, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::selection_widget< T >, tt::text_field_widget< T >, and tt::toolbar_tab_button_widget< T >.
|
inlinenoexcept |
Get the base-line in local coordinates.
mutex must be locked by current thread.
|
inlinevirtualnoexcept |
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.
mutex must be locked by current thread. | context | The context to where the widget will draw. |
| display_time_point | The time point when the widget will be shown on the screen. |
Reimplemented in tt::abstract_container_widget, tt::toolbar_widget, tt::button_widget< T >, tt::checkbox_widget< T >, tt::checkbox_widget< bool >, tt::label_widget, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, tt::overlay_view_widget, tt::radio_button_widget< T >, tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::selection_widget< T >, tt::system_menu_widget, tt::tab_view_widget< T >, tt::text_field_widget< T >, tt::toggle_widget, tt::toolbar_tab_button_widget< T >, and tt::window_traffic_lights_widget.
|
inlinenoexcept |
The first drawing 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 popups will increase the layer by 25.0, to make sure the overlay will draw above other widgets in the window.
mutex must be locked by current thread.
|
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().
| current_keyboard_widget | The widget that currently has focus; or empty to get the first widget that accepts focus. |
| group | The group to which the widget must belong. |
| direction | The direction in which to walk the widget tree. |
| currentKeyboardWidget | when currentKeyboardWidget was found but no next widget was found. |
| empty | when currentKeyboardWidget is not found in this Widget. |
Reimplemented in tt::abstract_container_widget, tt::selection_widget< T >, and tt::tab_view_widget< T >.
|
virtualnoexcept |
Handle command recursive.
Handle a command and pass it to each child.
| command | The command to handle by this widget. |
| reject_list | The widgets that should ignore this command |
Reimplemented in tt::abstract_container_widget.
|
virtualnoexcept |
Handle command.
If a widget does not fully handle a command it should pass the command to the super class' handle_event().
Reimplemented in tt::abstract_button_widget< T >, tt::abstract_button_widget< bool >, tt::abstract_button_widget< value_type >, tt::selection_widget< T >, tt::text_field_widget< T >, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, and tt::toolbar_tab_button_widget< T >.
|
virtualnoexcept |
Handle keyboard event.
Called by the operating system when editing text, or entering special keys
| event | The keyboard event. |
Reimplemented in tt::text_field_widget< T >.
|
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.
| event | The mouse event, positions are in window coordinates. |
Reimplemented in tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::abstract_button_widget< T >, tt::abstract_button_widget< bool >, tt::abstract_button_widget< value_type >, tt::scroll_view_widget< CanScrollHorizontally, CanScrollVertically, ControlsWindow >, tt::selection_widget< T >, tt::text_field_widget< T >, and tt::window_traffic_lights_widget.
|
inlinenoexcept |
Get the resistance in height.
The amount of resistance the widget has for resizing to larger than the minimum size.
mutex must be locked by current thread. | 0 | Greedy: Widget will try to become the largest. |
| 1 | Normal: Widget will share the space with others. |
| 2 | Resist: Widget will try to maintain minimum size. |
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.
| window_position | The coordinate of the mouse on the window. Use fromWindowTransform to convert to widget-local coordinates. |
Reimplemented in tt::abstract_container_widget, tt::toolbar_widget, tt::abstract_button_widget< T >, tt::abstract_button_widget< bool >, tt::abstract_button_widget< value_type >, tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::scroll_view_widget< CanScrollHorizontally, CanScrollVertically, ControlsWindow >, tt::selection_widget< T >, tt::system_menu_widget, tt::tab_view_widget< T >, tt::text_field_widget< T >, tt::window_traffic_lights_widget, and tt::window_widget.
|
inlinevirtualnoexcept |
Should be called right after allocating and constructing a widget.
Reimplemented in tt::button_widget< T >, tt::checkbox_widget< T >, tt::checkbox_widget< bool >, tt::grid_layout_widget, tt::label_widget, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, tt::radio_button_widget< T >, tt::scroll_view_widget< CanScrollHorizontally, CanScrollVertically, ControlsWindow >, tt::selection_widget< T >, tt::toolbar_tab_button_widget< T >, and tt::window_widget.
|
noexcept |
Is this widget the first widget in the parent container.
|
noexcept |
Is this widget the last widget in the parent container.
|
inlinenoexcept |
The logical layer of the widget.
The logical layer can be used to determine how for 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.
mutex must be locked by current thread.
|
virtualnoexcept |
Make a draw context for this widget.
This function will make a draw context with the correct transformation and default color values.
mutex must be locked by current thread. | context | A template drawing context. This template may be taken from the parent's draw call. |
Reimplemented in tt::abstract_button_widget< T >, tt::abstract_button_widget< bool >, and tt::abstract_button_widget< value_type >.
|
inlinenoexcept |
Get the margin around the Widget.
A container widget should layout the children in such a way that the maximum margin of neighbouring widgets is maintained.
mutex must be locked by current thread.
|
noexcept |
Get a reference to the parent.
It is undefined behavior to call this function when the widget does not have a parent.
|
noexcept |
Get a reference to the parent.
It is undefined behavior to call this function when the widget does not have a parent.
|
staticnoexcept |
Get a list of parents of a given widget.
The chain includes the given widget.
|
inlinenoexcept |
Get the relative_base_line of the widget.
This value is used by a container widget to align the text of its children on the same base-line.
By taking std::max() of the preferred_base_line() of all children, you will get the highest priority relative-base-line. The container can then use the relative_base_line::position() method to get the base-line position that should be used for all widgets in a row.
mutex must be locked by current thread. updateConstraint() must be called first.
|
inlinenoexcept |
Get the size-range of the widget.
This size-range is used to determine the size of container widgets and eventually the size of the window.
mutex must be locked by current thread. updateConstraint() must be called first.
|
inlinenoexcept |
Get the rectangle in local coordinates.
mutex must be locked by current thread.
|
inlinenoexcept |
The semantic 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.
mutex must be locked by current thread.
|
inlinenoexcept |
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.
mutex must be locked by current thread. | window_rectangle | The location and size of the widget inside the window. |
| window_clipping_rectangle | The location and size of the clipping rectangle, beyond which not to draw or accept mouse events. |
| window_base_line | The position of the text base-line from the bottom of the window. When not given the middle of the _window_rectangle is used together with the preferred relative base-line. |
|
noexcept |
Get a shared_ptr to the parent.
|
noexcept |
Get a shared_ptr to the parent.
|
virtualnoexcept |
Update the constraints of the widget.
This function is called on each vertical sync, even if no drawing is to be done. It should recursively call updateConstraints() on each of the visible children, so they get a chance to update.
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 updateConstraints() on its base-class to check if the constraints where changed. Widget::update_constraints() will check if requestConstraints was set. Container::update_constraints() will check if any of the children changed constraints.
If the container, due to a change in constraints, wants the window to resize to the minimum size it should set window.requestResize to true.
This function will change what is returned by preferred_size() and preferred_base_line().
mutex must be locked by current thread. | display_time_point | The time point when the widget will be shown on the screen. |
| need_reconstrain | Force the widget to re-constrain. |
Reimplemented in tt::abstract_container_widget, tt::row_column_layout_widget< Arrangement >, tt::toolbar_widget, tt::button_widget< T >, tt::checkbox_widget< T >, tt::checkbox_widget< bool >, tt::grid_layout_widget, tt::label_widget, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, tt::overlay_view_widget, tt::radio_button_widget< T >, tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::scroll_view_widget< CanScrollHorizontally, CanScrollVertically, ControlsWindow >, tt::selection_widget< T >, tt::system_menu_widget, tt::tab_view_widget< T >, tt::text_field_widget< T >, tt::toggle_widget, tt::toolbar_tab_button_widget< T >, tt::window_traffic_lights_widget, and tt::window_widget.
|
virtualnoexcept |
Update the internal layout of the widget.
This function is called on each vertical sync, even if no drawing is to be done. It should recursively call updateLayout() on each of the visible children, so they get a chance to update.
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.
This function will likely call set_window_rectangle() and set_window_base_line() on its children, before calling updateLayout() on that child.
Subclasses should call updateLayout() on its children, call updateLayout() on its base class with forceLayout argument to the result of layoutRequest.exchange(false).
mutex must be locked by current thread. | display_time_point | The time point when the widget will be shown on the screen. |
| need_layout | Force the widget to layout |
Reimplemented in tt::abstract_container_widget, tt::menu_item_widget< T >, tt::menu_item_widget< value_type >, tt::row_column_layout_widget< Arrangement >, tt::toolbar_widget, tt::window_widget, tt::grid_layout_widget, tt::overlay_view_widget, tt::radio_button_widget< T >, tt::scroll_bar_widget< IsVertical >, tt::scroll_bar_widget< false >, tt::scroll_bar_widget< true >, tt::scroll_view_widget< CanScrollHorizontally, CanScrollVertically, ControlsWindow >, tt::selection_widget< T >, tt::system_menu_widget, tt::tab_view_widget< T >, tt::text_field_widget< T >, tt::toggle_widget, tt::toolbar_tab_button_widget< T >, tt::window_traffic_lights_widget, tt::button_widget< T >, tt::checkbox_widget< T >, tt::checkbox_widget< bool >, and tt::label_widget.
|
inlinenoexcept |
Get the resistance in width.
The amount of resistance the widget has for resizing to larger than the minimum size.
mutex must be locked by current thread. | 0 | Greedy: Widget will try to become the largest. |
| 1 | Normal: Widget will share the space with others. |
| 2 | Resist: Widget will try to maintain minimum size. |
|
inlinenoexcept |
Get the base-line distance from the bottom of the window.
mutex must be locked by current thread.
|
inlinevirtualnoexcept |
Get the clipping-rectangle in window coordinates.
mutex must be locked by current thread. Reimplemented in tt::toolbar_tab_button_widget< T >.
|
inlinenoexcept |
Get the rectangle in window coordinates.
mutex must be locked by current thread. | observable<bool> tt::widget::enabled = true |
The widget is enabled.
| gui_window& tt::widget::window |
Convenient reference to the Window.