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/utility.hpp"
13#include "../macros.hpp"
14#include <concepts>
15
16
17
18namespace hi { inline namespace v1 {
19
23class margins {
24public:
25 using array_type = simd<float, 4>;
26 using value_type = array_type::value_type;
27
28 constexpr margins(margins const&) noexcept = default;
29 constexpr margins(margins&&) noexcept = default;
30 constexpr margins& operator=(margins const&) noexcept = default;
31 constexpr margins& operator=(margins&&) noexcept = default;
32
33 [[nodiscard]] constexpr margins() noexcept : _v() {}
34 [[nodiscard]] constexpr margins(float margin) noexcept : _v(margin, margin, margin, margin) {}
35 [[nodiscard]] constexpr margins(float left, float bottom, float right, float top) noexcept :
36 _v(left, bottom, right, top)
37 {
38 }
39 [[nodiscard]] constexpr explicit margins(array_type v) noexcept : _v(v) {}
40
41 [[nodiscard]] constexpr explicit operator array_type() const noexcept
42 {
43 return _v;
44 }
45
46 [[nodiscard]] constexpr float left() const noexcept
47 {
48 return _v.x();
49 }
50
51 [[nodiscard]] constexpr float& left() noexcept
52 {
53 return _v.x();
54 }
55
56 [[nodiscard]] constexpr float bottom() const noexcept
57 {
58 return _v.y();
59 }
60
61 [[nodiscard]] constexpr float& bottom() noexcept
62 {
63 return _v.y();
64 }
65
66 [[nodiscard]] constexpr float right() const noexcept
67 {
68 return _v.z();
69 }
70
71 [[nodiscard]] constexpr float& right() noexcept
72 {
73 return _v.z();
74 }
75
76 [[nodiscard]] constexpr float top() const noexcept
77 {
78 return _v.w();
79 }
80
81 [[nodiscard]] constexpr float& top() noexcept
82 {
83 return _v.w();
84 }
85
86 template<int I>
87 [[nodiscard]] constexpr friend float get(margins const& rhs) noexcept
88 {
89 return get<I>(rhs._v);
90 }
91
92 [[nodiscard]] constexpr float operator[](std::size_t i) const noexcept
93 {
94 return _v[i];
95 }
96
97 constexpr margins& operator+=(margins const& rhs) noexcept
98 {
99 _v += rhs._v;
100 return *this;
101 }
102
103 [[nodiscard]] constexpr friend margins max(margins const& lhs, margins const& rhs) noexcept
104 {
105 return margins{max(lhs._v, rhs._v)};
106 }
107
108 [[nodiscard]] constexpr friend bool operator==(margins const& lhs, margins const& rhs) noexcept
109 {
110 return equal(lhs._v, rhs._v);
111 }
112
113private:
114 array_type _v;
115};
116
117}} // 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
The left, bottom, right and top margins.
Definition margins.hpp:23