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