11#include "../GUI/module.hpp"
12#include "../layout/grid_layout.hpp"
16namespace hi {
inline namespace v1 {
40template<fixed_string Name =
"">
44 constexpr static auto prefix = Name /
"grid";
71 template<
typename Widget,
typename... Args>
75 hi_axiom(first_column < last_column);
77 auto tmp = std::make_unique<Widget>(
this, std::forward<Args>(args)...);
78 return static_cast<Widget&
>(add_widget(first_column, first_row, last_column, last_row,
std::move(tmp)));
89 template<
typename Widget,
typename... Args>
92 return make_widget<Widget>(column, row, column + 1, row + 1, std::forward<Args>(args)...);
103 template<
typename Widget,
typename... Args>
106 hilet[column_first, row_first, column_last, row_last] = parse_spreadsheet_range(address);
107 return make_widget<Widget>(column_first, row_first, column_last, row_last, std::forward<Args>(args)...);
111 [[nodiscard]] generator<widget const&> children(
bool include_invisible)
const noexcept override
113 for (
hilet& cell : _grid) {
114 co_yield *cell.value;
118 [[nodiscard]] box_constraints update_constraints() noexcept
override
120 for (
auto& cell : _grid) {
121 cell.set_constraints(cell.value->update_constraints());
124 return _grid.constraints(os_settings::left_to_right());
127 void set_layout(widget_layout
const& context)
noexcept override
130 _grid.set_layout(context.shape, theme<prefix>.cap_height(
this));
133 for (
hilet& cell : _grid) {
134 cell.value->set_layout(context.transform(cell.shape, 0.0f));
138 void draw(widget_draw_context& context)
noexcept override
142 for (
hilet& cell : _grid) {
143 cell.value->draw(context);
148 [[nodiscard]] hitbox hitbox_test(point2i position)
const noexcept override
154 for (
hilet& cell : _grid) {
155 r = cell.value->hitbox_test_from_parent(position, r);
165 grid_layout<std::unique_ptr<widget>> _grid;
177 hi_axiom(first_column < last_column);
180 if (_grid.cell_in_use(first_column, first_row, last_column, last_row)) {
181 hi_log_fatal(
"cell ({},{}) of grid_widget is already in use", first_column, first_row);
184 auto&
ref = *child_widget;
185 _grid.add_cell(first_column, first_row, last_column, last_row,
std::move(child_widget));
186 hi_log_info(
"grid_widget::add_widget({}, {}, {}, {})", first_column, first_row, last_column, last_row);
188 ++global_counter<
"grid_widget:add_widget:constrain">;
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ window_reconstrain
Request that widget get constraint on the next frame.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
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
widget * parent
Pointer to the parent widget.
Definition widget.hpp:40
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:49
size_t semantic_layer
The draw layer of the widget.
Definition widget.hpp:81
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:41
Widget & make_widget(std::size_t first_column, std::size_t first_row, std::size_t last_column, std::size_t last_row, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:73
Widget & make_widget(std::size_t column, std::size_t row, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:90
Widget & make_widget(std::string_view address, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:104
grid_widget(widget *parent) noexcept
Constructs an empty grid widget.
Definition grid_widget.hpp:52