12#include "../layout/layout.hpp"
13#include "../macros.hpp"
17hi_export_module(hikogui.widgets.grid_widget);
19hi_export
namespace hi {
inline namespace v1 {
66 hi_axiom(loop::main().on_thread());
67 hi_axiom(first_column < last_column);
68 hi_axiom(first_row < last_row);
70 if (_grid.cell_in_use(first_column, first_row, last_column, last_row)) {
71 hi_log_fatal(
"cell ({},{}) of grid_widget is already in use", first_column, first_row);
75 _grid.add_cell(first_column, first_row, last_column, last_row,
std::move(
widget));
76 hi_log_info(
"grid_widget::insert({}, {}, {}, {})", first_column, first_row, last_column, last_row);
78 ++global_counter<
"grid_widget:insert:constrain">;
94 for (
auto &cell: _grid) {
112 auto it =
std::max_element(_grid.begin(), _grid.end(), [](
auto const &a,
auto const &b) {
113 return a.last_column < b.last_column;
116 if (it == _grid.end()) {
133 for (
auto &cell: _grid) {
149 auto it =
std::max_element(_grid.begin(), _grid.end(), [](
auto const &a,
auto const &b) {
150 return a.last_row < b.last_row;
153 if (it == _grid.end()) {
170 template<
typename Widget,
typename... Args>
174 hi_axiom(first_column < last_column);
175 hi_axiom(first_row < last_row);
178 insert(first_column, first_row, last_column, last_row,
std::move(tmp));
190 template<
typename Widget,
typename... Args>
204 template<
typename Widget,
typename... Args>
205 Widget&
emplace(std::string_view address, Args&&...args)
207 auto const[column_first, row_first, column_last, row_last] = parse_spreadsheet_range(address);
222 template<
typename Widget,
typename... Args>
238 template<
typename Widget,
typename... Args>
253 template<
typename Widget,
typename... Args>
267 template<
typename Widget,
typename... Args>
284 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
286 for (
auto const& cell : _grid) {
287 co_yield *cell.value;
295 for (
auto& cell : _grid) {
296 cell.set_constraints(cell.value->update_constraints());
299 return _grid.constraints(os_settings::left_to_right());
302 void set_layout(widget_layout
const& context)
noexcept override
305 _grid.set_layout(context.shape, theme().baseline_adjustment());
308 for (
auto const& cell : _grid) {
313 void draw(draw_context
const& context)
noexcept override
316 for (
auto const& cell : _grid) {
317 cell.value->draw(context);
322 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
324 hi_axiom(loop::main().on_thread());
328 for (
auto const& cell : _grid) {
329 r = cell.value->hitbox_test_from_parent(position, r);
338 grid_layout<std::unique_ptr<widget>> _grid;
@ window_reconstrain
Request that widget get constraint on the next frame.
Definition gui_event_type.hpp:48
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
@ invisible
The widget is invisible.
Definition widget_state.hpp:41
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
@ level
The child widget stays at the same elevation and layer.
Definition widget_layout.hpp:26
virtual void set_parent(widget_intf *new_parent) noexcept
Set the parent widget.
Definition widget_intf.hpp:411
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:43
void push_top(std::unique_ptr< widget > widget) noexcept
Insert a widget to the top of the grid.
Definition grid_widget.hpp:131
Widget & emplace(std::size_t column, std::size_t row, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:191
grid_widget() noexcept
Constructs an empty grid widget.
Definition grid_widget.hpp:53
void push_front(std::unique_ptr< widget > widget) noexcept
Insert a widget to the front of the grid.
Definition grid_widget.hpp:92
Widget & emplace_bottom(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:268
Widget & emplace(std::string_view address, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:205
Widget & emplace_back(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:239
void push_back(std::unique_ptr< widget > widget) noexcept
Insert a widget to the back of the grid.
Definition grid_widget.hpp:110
void clear() noexcept
Remove all child widgets.
Definition grid_widget.hpp:278
Widget & emplace_top(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:254
Widget & emplace(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:172
Widget & emplace_front(Args &&...args)
Emplace a widget to the front.
Definition grid_widget.hpp:223
void push_bottom(std::unique_ptr< widget > widget) noexcept
Insert a widget to the bottom of the grid.
Definition grid_widget.hpp:147
An interactive graphical object as part of the user-interface.
Definition widget.hpp:38
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:50
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:110
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:125