HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
margins.hpp
1// Copyright Take Vos 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 "../SIMD/module.hpp"
12#include "../utility/module.hpp"
13
14namespace hi { inline namespace v1 {
15namespace geo {
16
20template<typename T>
21class margins {
22public:
23 using value_type = T;
24 using array_type = simd<T, 4>;
25
26 constexpr margins(margins const&) noexcept = default;
27 constexpr margins(margins&&) noexcept = default;
28 constexpr margins& operator=(margins const&) noexcept = default;
29 constexpr margins& operator=(margins&&) noexcept = default;
30
31 [[nodiscard]] constexpr margins() noexcept : _v() {}
32 [[nodiscard]] constexpr margins(value_type margin) noexcept : _v(margin, margin, margin, margin) {}
33 [[nodiscard]] constexpr margins(value_type left, value_type bottom, value_type right, value_type top) noexcept :
34 _v(left, bottom, right, top)
35 {
36 }
37 [[nodiscard]] constexpr explicit margins(array_type v) noexcept : _v(v) {}
38
39 [[nodiscard]] constexpr explicit operator array_type() const noexcept
40 {
41 return _v;
42 }
43
44 [[nodiscard]] constexpr value_type left() const noexcept
45 {
46 return _v.x();
47 }
48
49 [[nodiscard]] constexpr value_type& left() noexcept
50 {
51 return _v.x();
52 }
53
54 [[nodiscard]] constexpr value_type bottom() const noexcept
55 {
56 return _v.y();
57 }
58
59 [[nodiscard]] constexpr value_type& bottom() noexcept
60 {
61 return _v.y();
62 }
63
64 [[nodiscard]] constexpr value_type right() const noexcept
65 {
66 return _v.z();
67 }
68
69 [[nodiscard]] constexpr value_type& right() noexcept
70 {
71 return _v.z();
72 }
73
74 [[nodiscard]] constexpr value_type top() const noexcept
75 {
76 return _v.w();
77 }
78
79 [[nodiscard]] constexpr value_type& top() noexcept
80 {
81 return _v.w();
82 }
83
84 template<int I>
85 [[nodiscard]] constexpr friend value_type get(margins const& rhs) noexcept
86 {
87 return get<I>(rhs._v);
88 }
89
90 [[nodiscard]] constexpr value_type operator[](std::size_t i) const noexcept
91 {
92 return _v[i];
93 }
94
95 constexpr margins& operator+=(margins const& rhs) noexcept
96 {
97 _v += rhs._v;
98 return *this;
99 }
100
101 [[nodiscard]] constexpr friend margins max(margins const& lhs, margins const& rhs) noexcept
102 {
103 return margins{max(lhs._v, rhs._v)};
104 }
105
106 [[nodiscard]] constexpr friend bool operator==(margins const& lhs, margins const& rhs) noexcept
107 {
108 return equal(lhs._v, rhs._v);
109 }
110
111private:
112 array_type _v;
113};
114
115} // namespace geo
116
119
120template<>
121[[nodiscard]] constexpr marginsi narrow_cast(margins const& rhs) noexcept
122{
123 return {
124 narrow_cast<int>(rhs.left()), narrow_cast<int>(rhs.bottom()), narrow_cast<int>(rhs.right()), narrow_cast<int>(rhs.top())};
125}
126
127template<>
128[[nodiscard]] constexpr margins narrow_cast(marginsi const& rhs) noexcept
129{
130 return {
131 narrow_cast<float>(rhs.left()),
132 narrow_cast<float>(rhs.bottom()),
133 narrow_cast<float>(rhs.right()),
134 narrow_cast<float>(rhs.top())};
135}
136
137}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
The left, bottom, right and top margins.
Definition margins.hpp:21