HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
row_column_layout.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 "grid_layout.hpp"
8#include "../geometry/module.hpp"
9
10namespace hi { inline namespace v1 {
11
12template<axis Axis, typename T>
14public:
15 static_assert(Axis == axis::x or Axis == axis::y);
16
17 using value_type = T;
18 using grid_type = grid_layout<T>;
19 using cell_type = grid_type::cell_type;
20 using iterator = grid_type::iterator;
21 using const_iterator = grid_type::const_iterator;
22
23 ~row_column_layout() = default;
24 constexpr row_column_layout() noexcept = default;
25 constexpr row_column_layout(row_column_layout const&) noexcept = default;
26 constexpr row_column_layout(row_column_layout&&) noexcept = default;
27 constexpr row_column_layout& operator=(row_column_layout const&) noexcept = default;
28 constexpr row_column_layout& operator=(row_column_layout&&) noexcept = default;
29 [[nodiscard]] constexpr friend bool operator==(row_column_layout const&, row_column_layout const&) noexcept = default;
30
31 [[nodiscard]] constexpr bool empty() const noexcept
32 {
33 return _grid.empty();
34 }
35
36 [[nodiscard]] constexpr size_t size() const noexcept
37 {
38 return _grid.size();
39 }
40
41 [[nodiscard]] constexpr iterator begin() noexcept
42 {
43 return _grid.begin();
44 }
45
46 [[nodiscard]] constexpr const_iterator begin() const noexcept
47 {
48 return _grid.begin();
49 }
50
51 [[nodiscard]] constexpr const_iterator cbegin() const noexcept
52 {
53 return _grid.cbegin();
54 }
55
56 [[nodiscard]] constexpr iterator end() noexcept
57 {
58 return _grid.end();
59 }
60
61 [[nodiscard]] constexpr const_iterator end() const noexcept
62 {
63 return _grid.end();
64 }
65
66 [[nodiscard]] constexpr const_iterator cend() const noexcept
67 {
68 return _grid.cend();
69 }
70
71 [[nodiscard]] constexpr cell_type& operator[](size_t index) noexcept
72 {
73 // Grids in a cell are ordered by row_nr.
74 return _grid[index];
75 }
76
77 [[nodiscard]] constexpr cell_type const& operator[](size_t index) const noexcept
78 {
79 // Grids in a cell are ordered by row_nr.
80 return _grid[index];
81 }
82
83 cell_type& insert(const_iterator pos, std::convertible_to<T> auto&& value) noexcept
84 {
85 hilet index = std::distance(cbegin(), pos);
86
87 for (auto it = begin() + index; it != end(); ++it) {
88 if constexpr (Axis == axis::x) {
89 ++(it->first_column);
90 ++(it->last_column);
91 } else {
92 ++(it->first_row);
93 ++(it->last_row);
94 }
95 }
96
97 if constexpr (Axis == axis::x) {
98 return _grid.add_cell(index, 0, hi_forward(value));
99 } else {
100 return _grid.add_cell(0, index, hi_forward(value));
101 }
102 }
103
104 cell_type& push_front(std::convertible_to<T> auto&& value) noexcept
105 {
106 return insert(cbegin(), hi_forward(value));
107 }
108
109 cell_type& push_back(std::convertible_to<T> auto&& value) noexcept
110 {
111 return insert(cend(), hi_forward(value));
112 }
113
114 void clear() noexcept
115 {
116 return _grid.clear();
117 }
118
119 [[nodiscard]] box_constraints constraints(bool left_to_right) const noexcept
120 {
121 return _grid.constraints(left_to_right);
122 }
123
124 void set_layout(box_shape const &shape, float guideline) noexcept
125 {
126 return _grid.set_layout(shape, guideline);
127 }
128
129private:
130 grid_type _grid;
131};
132
133template<typename T>
135
136template<typename T>
138
139}} // namespace hi::v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
2D constraints.
Definition box_constraints.hpp:22
Definition box_shape.hpp:15
Definition row_column_layout.hpp:13
T distance(T... args)