HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
grid_cell_impl.hpp
1
2
3#pragma once
4
5#include "grid_cell.hpp"
6
7namespace hi { inline namespace v1 {
8
9constexpr ~grid_cell::grid_cell()
10{
11 if (_grid) {
12 _grid->remove_cell(_id);
13 _grid->state |= grid_state::need_constrain;
14 }
15}
16
17constexpr grid_cell::grid_cell(grid_cell&& other) noexcept : _grid(other._grid), _id(other._id)
18{
19 other._grid = nullptr;
20}
21
22constexpr grid_cell& grid_cell::operator=(grid_cell&& other) noexcept
23{
24 if (_grid) {
25 _grid->remove_cell(_id);
26 _grid->state |= grid_state::need_constrain;
27 }
28
29 _grid = std::exchange(other._grid, nullptr);
30 _id = other._id;
31}
32
33constexpr grid_cell::grid_cell(grid const& grid) noexcept : _grid(std::addressof(grid)), _id(grid.add_cell())
34{
35 _grid->state |= grid_state::need_constrain;
36}
37
38[[nodiscard]] constexpr bool grid_cell::empty() const noexcept
39{
40 return _grid->at(_id).in_use == 0;
41}
42
43constexpr void grid_cell::clear() noexcept
44{
45 if (compare_store(_grid->at(_id).in_use, 0)) {
46 _grid->state |= grid_state::need_constrain;
47 }
48}
49
50constexpr void grid_cell::set_location(uint8_t col_begin, uint8_t row_begin, uint8_t col_end, uint8_t row_end) noexcept
51{
54 hi_axiom(col_begin < col_end);
55 hi_axiom(row_begin < row_end);
56
57 auto updated = false;
58 updated |= compare_store(_grid->at(_id).col_begin, col_begin);
59 updated |= compare_store(_grid->at(_id).row_begin, row_begin);
60 updated |= compare_store(_grid->at(_id).col_end, col_end);
61 updated |= compare_store(_grid->at(_id).row_end, row_end);
62 if (updated) {
63 _grid->state |= grid_state::need_constrain;
64 }
65}
66
67constexpr void grid_cell::set_parent(grid_cell const& parent) noexcept
68{
69 if (compare_store(_grid->at(_id).parent, parent._id)) {
70 _grid->state |= grid_state::need_constrain;
71 }
72}
73
74constexpr void grid_cell::unset_parent() noexcept
75{
76 if (compare_store((*_grid)[_id].parent, -1)) {
77 _grid->state |= grid_state::need_constrain;
78 }
79}
80
81constexpr void grid_cell::set_priority(int8_t width_priority, int8_t height_priority) noexcept
82{
83 auto updated = false;
84 updated |= compare_store((*_grid)[_id].width_priority, width_priority);
85 updated |= compare_store((*_grid)[_id].height_priority, height_priority);
86 if (updated) {
87 _grid->state |= grid_state::need_constrain;
88 }
89}
90
91constexpr void grid_cell::set_margin(hi::margins margin) noexcept
92{
93 auto updated = false;
94 updated |= compare_store((*_grid)[_id].margin_left, round_cast<int8_t>(margin.left()));
95 updated |= compare_store((*_grid)[_id].margin_bottom, round_cast<int8_t>(margin.bottom()));
96 updated |= compare_store((*_grid)[_id].margin_right, round_cast<int8_t>(margin.right()));
97 updated |= compare_store((*_grid)[_id].margin_top, round_cast<int8_t>(margin.top()));
98 if (updated) {
99 _grid->state |= grid_state::need_constrain;
100 }
101}
102
103constexpr void grid_cell::set_size(hi::extent size) noexcept
104{
105 hi_axiom((*_grid)[_id].parent == -1);
106 hi_axiom((*_grid)[_id].col_begin == 0);
107 hi_axiom((*_grid)[_id].row_begin == 0);
108 hi_axiom((*_grid)[_id].col_end == 1);
109 hi_axiom((*_grid)[_id].row_end == 1);
110
111 auto updated = false;
112 updated |= compare_store((*_grid)[_id].width, round_cast<int32_t>(size.width()));
113 updated |= compare_store((*_grid)[_id].height, round_cast<int32_t>(size.height()));
114 if (updated) {
115 _grid->state |= grid_state::need_layout;
116 }
117}
118
119[[nodiscard]] constexpr aarectangle grid_cell::rectangle() const noexcept
120{
121 _grid->layout();
122}
123
124}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition utility.hpp:212
A cell in a grid.
Definition grid_cell.hpp:141
constexpr void set_parent(grid_cell const &parent) noexcept
Set the parent for this child-cell.
Definition grid_cell_impl.hpp:67
constexpr bool empty() const noexcept
Check if this cell has a location.
Definition grid_cell_impl.hpp:38
constexpr void clear() noexcept
Clear the cell.
Definition grid_cell_impl.hpp:43
constexpr void unset_parent(grid_cell const &parent) noexcept
Remove the parent for this child-cell.
Definition grid_cell_impl.hpp:74
constexpr void set_location() noexcept
Set the location to the origin of the grid.
Definition grid_cell.hpp:215
T addressof(T... args)