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