HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
widget_layout.hpp
1// Copyright Take Vos 2021-2022.
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
9#pragma once
10
11#include "gui_window_size.hpp"
12#include "../layout/module.hpp"
13#include "../geometry/module.hpp"
14#include "../time/module.hpp"
15#include "../utility/utility.hpp"
16#include "../settings/settings.hpp"
17#include "../macros.hpp"
18
19
20
21namespace hi { inline namespace v1 {
22
39public:
44 constexpr static int redraw_overhang = 2;
45
50
54
58
62
66
70
73 gui_window_size window_size_state = gui_window_size::normal;
74
77 float elevation = 0.0f;
78
90
95 extent2 sub_pixel_size = {1.0f, 1.0f};
96
99 utc_nanoseconds display_time_point = {};
100
101 constexpr widget_layout(widget_layout const&) noexcept = default;
107
112 gui_window_size window_size_state,
113 hi::subpixel_orientation subpixel_orientation,
114 utc_nanoseconds display_time_point) noexcept :
115 to_parent(),
116 from_parent(),
117 to_window(),
118 from_window(),
123 sub_pixel_size(hi::sub_pixel_size(subpixel_orientation)),
125 {
126 }
127
128 [[nodiscard]] constexpr bool empty() const noexcept
129 {
130 // Theme must always be set if layout is valid.
131 return display_time_point == utc_nanoseconds{};
132 }
133
134 [[nodiscard]] constexpr explicit operator bool() const noexcept
135 {
136 return not empty();
137 }
138
139 [[nodiscard]] constexpr translate3 to_window3() const noexcept
140 {
141 return translate3{to_window, elevation};
142 }
143
149 [[nodiscard]] constexpr bool contains(point3 mouse_position) const noexcept
150 {
152 }
153
155 {
156 return shape.rectangle;
157 }
158
162 {
163 return to_window * rectangle();
164 }
165
172
182
183 [[nodiscard]] constexpr float width() const noexcept
184 {
185 return shape.width();
186 }
187
188 [[nodiscard]] constexpr float height() const noexcept
189 {
190 return shape.height();
191 }
192
193 [[nodiscard]] constexpr extent2 size() const noexcept
194 {
195 return shape.size();
196 }
197
205 [[nodiscard]] constexpr widget_layout
207 {
208 widget_layout r = *this;
209 r.shape.rectangle = aarectangle{child_shape.size()};
210
211 if (child_shape.baseline) {
212 r.shape.baseline = *child_shape.baseline - child_shape.y();
213
214 } else if (r.shape.baseline) {
215 // Use the baseline of the current layout and translate it.
216 *r.shape.baseline -= child_shape.y();
217 }
218
219 if (child_shape.centerline) {
220 r.shape.centerline = *child_shape.centerline - child_shape.x();
221
222 } else if (r.shape.centerline) {
223 // Use the baseline of the current layout and translate it.
224 *r.shape.centerline -= child_shape.x();
225 }
226
228 r.from_parent = ~r.to_parent;
229 r.to_window = r.to_parent * this->to_window;
230 r.from_window = r.from_parent * this->from_window;
231 r.clipping_rectangle = r.from_parent * intersect(this->clipping_rectangle, new_clipping_rectangle);
233 return r;
234 }
235
246
253 {
254 auto r = *this;
256 return r;
257 }
258};
259
260}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
constexpr extent2 size() const noexcept
Get size of the rectangle.
Definition aarectangle.hpp:182
constexpr bool contains(point2 const &rhs) const noexcept
Check if a 2D coordinate is inside the rectangle.
Definition aarectangle.hpp:264
A high-level geometric extent.
Definition extent2.hpp:29
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:21
Definition translate2.hpp:14
The layout of a widget.
Definition widget_layout.hpp:38
translate2 to_parent
This matrix transforms local coordinates to the coordinates of the parent widget.
Definition widget_layout.hpp:53
utc_nanoseconds display_time_point
The layout created for displaying at this time point.
Definition widget_layout.hpp:99
constexpr aarectangle clipping_rectangle_on_window() const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:168
translate2 from_parent
This matrix transforms parent widget's coordinates to local coordinates.
Definition widget_layout.hpp:57
aarectangle clipping_rectangle
The clipping rectangle.
Definition widget_layout.hpp:89
constexpr bool contains(point3 mouse_position) const noexcept
Check if the mouse position is inside the widget.
Definition widget_layout.hpp:149
float elevation
The elevation of the widget above the window.
Definition widget_layout.hpp:77
constexpr aarectangle clipping_rectangle_on_window(aarectangle narrow_clipping_rectangle) const noexcept
Get the clipping rectangle in window coordinate system.
Definition widget_layout.hpp:178
translate2 to_window
This matrix transforms local coordinates to window coordinates.
Definition widget_layout.hpp:61
extent2 sub_pixel_size
The size of a sub-pixel.
Definition widget_layout.hpp:95
static constexpr int redraw_overhang
The amount of pixels that the redraw request will overhang the widget.
Definition widget_layout.hpp:44
translate2 from_window
This matrix transforms window coordinates to local coordinates.
Definition widget_layout.hpp:65
constexpr widget_layout override_clip(aarectangle new_clipping_rectangle) const noexcept
Override e context with the new clipping rectangle.
Definition widget_layout.hpp:252
extent2 window_size
Size of the window.
Definition widget_layout.hpp:69
box_shape shape
Shape of the widget.
Definition widget_layout.hpp:49
constexpr aarectangle rectangle_on_window() const noexcept
Get the rectangle in window coordinate system.
Definition widget_layout.hpp:161
gui_window_size window_size_state
The size state of the window.
Definition widget_layout.hpp:73
constexpr widget_layout transform(box_shape const &child_shape, float child_elevation, aarectangle new_clipping_rectangle) const noexcept
Create a new widget_layout for the child widget.
Definition widget_layout.hpp:206
constexpr widget_layout transform(box_shape const &child_shape, float child_elevation=1.0f) const noexcept
Create a new widget_layout for the child widget.
Definition widget_layout.hpp:242
Definition box_shape.hpp:18