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/module.hpp"
9#include "widget_id.hpp"
10#include <limits>
11#include <cstdint>
12#include <compare>
13
14namespace hi::inline v1 {
15
16enum class hitbox_type : uint8_t {
17 outside,
18 _default,
19 button,
20 scroll_bar,
21 text_edit,
22 move_area,
23 bottom_resize_border,
24 top_resize_border,
25 left_resize_border,
26 right_resize_border,
27 bottom_left_resize_corner,
28 bottom_right_resize_corner,
29 top_left_resize_corner,
30 top_right_resize_corner,
31 application_icon
32};
33
34class hitbox {
35public:
36 hitbox_type type;
37 widget_id widget_id;
38
39 constexpr hitbox(hitbox const&) noexcept = default;
40 constexpr hitbox(hitbox&&) noexcept = default;
41 constexpr hitbox& operator=(hitbox const&) noexcept = default;
42 constexpr hitbox& operator=(hitbox&&) noexcept = default;
43
44 constexpr hitbox() noexcept : widget_id(), _elevation(-std::numeric_limits<float>::max()), type(hitbox_type::outside) {}
45
46 constexpr hitbox(
47 hi::widget_id widget_id,
48 float elevation = -std::numeric_limits<float>::max(),
49 hitbox_type type = hitbox_type::_default) noexcept :
50 widget_id(widget_id), _elevation(elevation), type(type)
51 {
52 }
53
54 [[nodiscard]] constexpr friend std::strong_ordering operator<=>(hitbox const& lhs, hitbox const& rhs) noexcept
55 {
56 if ((lhs.widget_id == nullptr) == (rhs.widget_id == nullptr)) {
57 // Either both are widgets, or both are not widgets.
58 hilet elevation_ordering = lhs._elevation <=> rhs._elevation;
59 if (elevation_ordering == std::partial_ordering::equivalent) {
60 return to_underlying(lhs.type) <=> to_underlying(rhs.type);
61 } else if (elevation_ordering == std::partial_ordering::less) {
62 return std::strong_ordering::less;
63 } else if (elevation_ordering == std::partial_ordering::greater) {
64 return std::strong_ordering::greater;
65 } else {
67 }
68 } else if (lhs.widget_id == nullptr) {
69 // If lhs is not a widget than it is less.
70 return std::strong_ordering::less;
71 } else {
72 // Otherwise the lhs is greater.
73 return std::strong_ordering::greater;
74 }
75 }
76
77private:
78 float _elevation;
79};
80
81} // namespace hi::inline v1
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
Definition hitbox.hpp:34