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