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
5#pragma once
6
7#include "../rapid/numeric_array.hpp"
8
9namespace hi::inline v1 {
10
11class margins {
12public:
13 constexpr margins(margins const &) noexcept = default;
14 constexpr margins(margins &&) noexcept = default;
15 constexpr margins &operator=(margins const &) noexcept = default;
16 constexpr margins &operator=(margins &&) noexcept = default;
17
18 [[nodiscard]] constexpr margins() noexcept : _v() {}
19 [[nodiscard]] constexpr margins(float margin) noexcept : _v(margin, margin, margin, margin) {}
20 [[nodiscard]] constexpr margins(float left, float bottom, float right, float top) noexcept : _v(left, bottom, right, top) {}
21 [[nodiscard]] constexpr explicit margins(f32x4 v) noexcept : _v(v) {}
22
23 [[nodiscard]] constexpr explicit operator f32x4() const noexcept
24 {
25 return _v;
26 }
27
28 [[nodiscard]] constexpr float const &left() const noexcept
29 {
30 return _v.x();
31 }
32
33 [[nodiscard]] constexpr float &left() noexcept
34 {
35 return _v.x();
36 }
37
38 [[nodiscard]] constexpr float const &bottom() const noexcept
39 {
40 return _v.y();
41 }
42
43 [[nodiscard]] constexpr float &bottom() noexcept
44 {
45 return _v.y();
46 }
47
48 [[nodiscard]] constexpr float const &right() const noexcept
49 {
50 return _v.z();
51 }
52
53 [[nodiscard]] constexpr float &right() noexcept
54 {
55 return _v.z();
56 }
57
58 [[nodiscard]] constexpr float const &top() const noexcept
59 {
60 return _v.w();
61 }
62
63 [[nodiscard]] constexpr float &top() noexcept
64 {
65 return _v.w();
66 }
67
68 template<int I>
69 [[nodiscard]] constexpr friend float get(margins const &rhs) noexcept
70 {
71 return get<I>(rhs._v);
72 }
73
74 [[nodiscard]] constexpr float operator[](std::size_t i) const noexcept
75 {
76 return _v[i];
77 }
78
79 [[nodiscard]] constexpr friend margins max(margins const &lhs, margins const &rhs) noexcept
80 {
81 return margins{max(lhs._v, rhs._v)};
82 }
83
84 [[nodiscard]] constexpr friend bool operator==(margins const &lhs, margins const &rhs) noexcept = default;
85
86private:
87 f32x4 _v;
88};
89
90} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:15
@ bottom
Align to the bottom.
@ top
Align to the top.
Definition margins.hpp:11