HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
overlay_view_widget.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "widget.hpp"
8#include "grid_layout_widget.hpp"
9
10namespace tt {
11
13public:
15
17 {
18 if (parent) {
19 // The overlay-widget will reset the semantic_layer as it is the bottom
20 // layer of this virtual-window. However the draw-layer should be above
21 // any other widget drawn.
22 ttlet lock = std::scoped_lock(gui_system_mutex);
23 _draw_layer = parent->draw_layer() + 20.0f;
24 _semantic_layer = 0;
25 }
26 }
27
29
30 [[nodiscard]] bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override
31 {
32 tt_axiom(gui_system_mutex.recurse_lock_count());
33
34 auto has_updated_contraints = super::update_constraints(display_time_point, need_reconstrain);
35
36 if (has_updated_contraints) {
37 tt_axiom(_content);
38 _preferred_size = _content->preferred_size();
39 }
40
41 return has_updated_contraints;
42 }
43
44 [[nodiscard]] void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
45 {
46 tt_axiom(gui_system_mutex.recurse_lock_count());
47
48 need_layout |= std::exchange(_request_relayout, false);
49 if (need_layout) {
50 tt_axiom(_content);
51 _content->set_layout_parameters_from_parent(rectangle(), rectangle(), 1.0f);
52 }
53
54 super::update_layout(display_time_point, need_layout);
55 }
56
57 void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
58 {
59 tt_axiom(gui_system_mutex.recurse_lock_count());
60
61 if (overlaps(context, _clipping_rectangle)) {
62 draw_background(context);
63 }
64
65 super::draw(std::move(context), display_time_point);
66 }
67
72 [[nodiscard]] aarectangle make_overlay_rectangle_from_parent(aarectangle requested_rectangle) const noexcept
73 {
74 tt_axiom(gui_system_mutex.recurse_lock_count());
75
76 if (auto parent = _parent.lock()) {
77 ttlet requested_window_rectangle = aarectangle{parent->local_to_window() * requested_rectangle};
78 ttlet window_bounds = aarectangle{10.0f, 10.0f, window.extent.width() - 20.0f, window.extent.height() - 50.0f};
79 ttlet response_window_rectangle = fit(window_bounds, requested_window_rectangle);
80 return aarectangle{parent->window_to_local() * response_window_rectangle};
81 } else {
82 tt_no_default();
83 }
84 }
85
86 template<typename WidgetType = grid_layout_widget, typename... Args>
87 std::shared_ptr<WidgetType> make_widget(Args &&... args) noexcept
88 {
89 ttlet lock = std::scoped_lock(gui_system_mutex);
90
91 auto widget = super::make_widget<WidgetType>(std::forward<Args>(args)...);
92 tt_axiom(!_content);
93 _content = widget;
94 return widget;
95 }
96
97 [[nodiscard]] color background_color() const noexcept override
98 {
99 return theme::global->fillColor(_semantic_layer + 1);
100 }
101
102 [[nodiscard]] color foreground_color() const noexcept override
103 {
104 return theme::global->borderColor(_semantic_layer + 1);
105 }
106
107private:
109
110 void draw_background(draw_context context) noexcept
111 {
112 context.draw_box_with_border_inside(rectangle(), background_color(), foreground_color());
113 }
114};
115
116} // namespace tt
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:18
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:91
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:102
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:37
extent2 extent
The current window extent as set by the GPU library.
Definition gui_window.hpp:76
int recurse_lock_count() const noexcept
This function should be used in tt_axiom() to check if the lock is held by current thread.
Definition unfair_recursive_mutex.hpp:60
Definition abstract_container_widget.hpp:11
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept
Update the internal layout of the widget.
Definition abstract_container_widget.hpp:110
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition abstract_container_widget.hpp:124
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept
Update the constraints of the widget.
Definition abstract_container_widget.hpp:95
Definition grid_layout_widget.hpp:16
Definition overlay_view_widget.hpp:12
aarectangle make_overlay_rectangle_from_parent(aarectangle requested_rectangle) const noexcept
Make an overlay rectangle.
Definition overlay_view_widget.hpp:72
void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
Update the internal layout of the widget.
Definition overlay_view_widget.hpp:44
bool update_constraints(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override
Update the constraints of the widget.
Definition overlay_view_widget.hpp:30
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
Draw the widget.
Definition overlay_view_widget.hpp:57
Definition widget.hpp:97
float draw_layer() const noexcept
The first drawing layer of the widget.
Definition widget.hpp:149
widget(gui_window &window, std::shared_ptr< abstract_container_widget > parent) noexcept
aarectangle rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:342
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:101
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
T move(T... args)