8#include "../assert.hpp"
16namespace hi {
inline namespace v1 {
62 _num_cells =
std::max(_num_cells, last);
134 [[nodiscard]]
float margin_before() const noexcept
136 return _cells.
front().margin;
139 [[nodiscard]]
float margin_after() const noexcept
141 return _cells.
back().margin;
169 hi_axiom(first <= last);
170 hi_axiom(last <= _cells.
size());
215 return {position, position + size};
231 for (
auto i = first; i != last; ++i) {
232 if (_cells[i].baseline) {
233 return _cells[i].baseline;
239 [[nodiscard]] widget_baseline get_baseline(
std::size_t index)
const noexcept
241 return get_baseline(index, index + 1);
245 struct constraint_type {
253 widget_baseline baseline;
255 [[nodiscard]]
bool is_single_cell() const noexcept
257 return first == last - 1;
260 [[nodiscard]]
bool is_span() const noexcept
262 return not is_single_cell();
289 widget_baseline baseline;
291 cell_type() noexcept :
292 size(0.0f), margin(0.0f), minimum(0.0f), preferred(0.0f), maximum(
std::numeric_limits<
float>::infinity()), baseline()
296 void fix_constraint() noexcept
298 inplace_max(maximum, minimum);
299 inplace_clamp(preferred, minimum, maximum);
302 void set_constraint(constraint_type
const& constraint)
noexcept
304 inplace_max(minimum, constraint.minimum);
305 inplace_max(preferred, constraint.preferred);
306 inplace_min(maximum, constraint.maximum);
309 [[nodiscard]]
bool holds_invariant() const noexcept
311 return minimum <= preferred and preferred <= maximum;
317 using cell_iterator = cell_vector_type::iterator;
318 using cell_const_iterator = cell_vector_type::const_iterator;
321 float _minimum = 0.0f;
322 float _preferred = 0.0f;
323 float _maximum = 0.0f;
324 contraint_vector_type _constraints;
325 cell_vector_type _cells;
333 [[nodiscard]]
float get_position(cell_const_iterator begin, cell_const_iterator first)
const noexcept
336 auto position = 0.0f;
337 while (it != first) {
338 position += it->size;
340 position += it->margin;
351 [[nodiscard]]
static float get_size(cell_const_iterator first, cell_const_iterator last)
noexcept
358 auto size = it->size;
360 for (; it != last; ++it) {
367 void constrain_cells_by_singles() noexcept;
368 void constrain_cells_by_spans(
std::function<
float(constraint_type const&)> const& predicate) noexcept;
369 [[nodiscard]]
bool holds_invariant() const noexcept;
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Grid layout is used to layout widgets along an axis.
Definition grid_layout.hpp:23
float get_size(std::size_t index) const noexcept
Get size of the cell.
Definition grid_layout.hpp:179
void add_constraint(std::size_t first, std::size_t last, float minimum, float preferred, float maximum, float margin_before, float margin_after, widget_baseline baseline=widget_baseline{}) noexcept
Add a constraint for a widget.
Definition grid_layout.hpp:52
void commit_constraints() noexcept
Commit all the constraints.
float maximum() const noexcept
The minimum size of the total grid_layout.
Definition grid_layout.hpp:129
std::pair< float, float > get_position_and_size(std::size_t index) const noexcept
Get the position and size of cell.
Definition grid_layout.hpp:200
void clear() noexcept
Clear the list of widgets in the layout.
Definition grid_layout.hpp:34
void layout(float size) noexcept
Layout the cells based on the total size.
std::pair< float, float > get_positions(std::size_t index) const noexcept
Get the start and end position of a cell.
Definition grid_layout.hpp:224
void add_constraint(std::size_t index, float minimum, float preferred, float maximum, float margin_before, float margin_after, widget_baseline baseline=widget_baseline{}) noexcept
Add a constraint for a widget.
Definition grid_layout.hpp:76
std::pair< float, float > get_position_and_size(std::size_t first, std::size_t last) const noexcept
Get the position and size of a cell-span.
Definition grid_layout.hpp:190
std::pair< float, float > get_positions(std::size_t first, std::size_t last) const noexcept
Get the start and end position of the cells.
Definition grid_layout.hpp:211
float get_size(std::size_t first, std::size_t last) const noexcept
Get size of the cells.
Definition grid_layout.hpp:167
float get_position(std::size_t index) const noexcept
Get position of cell.
Definition grid_layout.hpp:155
float preferred() const noexcept
The minimum size of the total grid_layout.
Definition grid_layout.hpp:120
float minimum() const noexcept
The minimum size of the total grid_layout.
Definition grid_layout.hpp:111
std::size_t num_cells() const noexcept
The number of cells of the grid_layout.
Definition grid_layout.hpp:102
The base-line of a widget on which to set the text and graphics.
Definition widget_baseline.hpp:19
T emplace_back(T... args)