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 _preferred_base_line = _content->preferred_base_line();
40 }
41
42 return has_updated_contraints;
43 }
44
45 [[nodiscard]] void update_layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override
46 {
47 tt_axiom(gui_system_mutex.recurse_lock_count());
48
49 need_layout |= std::exchange(_request_relayout, false);
50 if (need_layout) {
51 // The _window_rectangle, is not allowed to be beyond the edges of the actual window.
52 // Change _window_rectangle to fit the window.
53 ttlet window_rectangle_and_margin = expand(_window_rectangle, _margin);
54 ttlet new_window_rectangle_and_margin = fit(aarect{f32x4{window.extent}}, window_rectangle_and_margin);
55 _window_rectangle = shrink(new_window_rectangle_and_margin, _margin);
56 _window_clipping_rectangle = _window_rectangle;
57
58 tt_axiom(_content);
59 _content->set_layout_parameters(_window_rectangle, _window_clipping_rectangle);
60 }
61
62 super::update_layout(display_time_point, need_layout);
63 }
64
65 void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override
66 {
67 tt_axiom(gui_system_mutex.recurse_lock_count());
68
69 if (overlaps(context, this->window_clipping_rectangle())) {
70 draw_background(context);
71 }
72
73 super::draw(std::move(context), display_time_point);
74 }
75
76 template<typename WidgetType = grid_layout_widget, typename... Args>
77 std::shared_ptr<WidgetType> make_widget(Args &&... args) noexcept
78 {
79 ttlet lock = std::scoped_lock(gui_system_mutex);
80
81 auto widget = super::make_widget<WidgetType>(std::forward<Args>(args)...);
82 tt_axiom(!_content);
83 _content = widget;
84 return widget;
85 }
86
87private:
89
90 void draw_background(draw_context context) noexcept
91 {
92 context.clipping_rectangle = expand(context.clipping_rectangle, theme::global->borderWidth);
93 context.draw_box_with_border_outside(rectangle());
94 }
95};
96
97} // namespace tt
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:33
Definition gui_window.hpp:39
f32x4 extent
The current window extent as set by the GPU library.
Definition gui_window.hpp:78
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:111
void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept
Draw the widget.
Definition abstract_container_widget.hpp:125
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:96
Definition grid_layout_widget.hpp:16
Definition overlay_view_widget.hpp:12
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:45
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:65
Definition widget.hpp:96
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
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:100
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
virtual aarect window_clipping_rectangle() const noexcept
Get the clipping-rectangle in window coordinates.
Definition widget.hpp:320
aarect rectangle() const noexcept
Get the rectangle in local coordinates.
Definition widget.hpp:340
T move(T... args)