HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hitbox.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 "../geometry/module.hpp"
8#include "../utility/utility.hpp"
9#include "widget_id.hpp"
10#include "../macros.hpp"
11#include <limits>
12#include <cstdint>
13#include <compare>
14
15
16
17namespace hi::inline v1 {
18
19enum class hitbox_type : uint8_t {
20 outside,
21 _default,
22 button,
23 scroll_bar,
24 text_edit,
25 move_area,
26 bottom_resize_border,
27 top_resize_border,
28 left_resize_border,
29 right_resize_border,
30 bottom_left_resize_corner,
31 bottom_right_resize_corner,
32 top_left_resize_corner,
33 top_right_resize_corner,
34 application_icon
35};
36
37class hitbox {
38public:
39 hitbox_type type;
40 widget_id widget_id;
41
42 constexpr hitbox(hitbox const&) noexcept = default;
43 constexpr hitbox(hitbox&&) noexcept = default;
44 constexpr hitbox& operator=(hitbox const&) noexcept = default;
45 constexpr hitbox& operator=(hitbox&&) noexcept = default;
46
47 constexpr hitbox() noexcept : widget_id(), _elevation(-std::numeric_limits<float>::max()), type(hitbox_type::outside) {}
48
49 constexpr hitbox(
50 hi::widget_id widget_id,
51 float elevation = -std::numeric_limits<float>::max(),
52 hitbox_type type = hitbox_type::_default) noexcept :
53 widget_id(widget_id), _elevation(elevation), type(type)
54 {
55 }
56
57 [[nodiscard]] constexpr friend std::strong_ordering operator<=>(hitbox const& lhs, hitbox const& rhs) noexcept
58 {
59 if ((lhs.widget_id == nullptr) == (rhs.widget_id == nullptr)) {
60 // Either both are widgets, or both are not widgets.
61 hilet elevation_ordering = lhs._elevation <=> rhs._elevation;
62 if (elevation_ordering == std::partial_ordering::equivalent) {
63 return std::to_underlying(lhs.type) <=> std::to_underlying(rhs.type);
64 } else if (elevation_ordering == std::partial_ordering::less) {
65 return std::strong_ordering::less;
66 } else if (elevation_ordering == std::partial_ordering::greater) {
67 return std::strong_ordering::greater;
68 } else {
69 hi_no_default();
70 }
71 } else if (lhs.widget_id == nullptr) {
72 // If lhs is not a widget than it is less.
73 return std::strong_ordering::less;
74 } else {
75 // Otherwise the lhs is greater.
76 return std::strong_ordering::greater;
77 }
78 }
79
80private:
81 float _elevation;
82};
83
84} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:16
@ outside
The border is drawn outside the edge of a quad.
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition hitbox.hpp:37