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">;
95 for (
auto &cell: _grid) {
113 auto it =
std::max_element(_grid.begin(), _grid.end(), [](
auto const &a,
auto const &b) {
114 return a.last_column < b.last_column;
117 if (it == _grid.end()) {
120 return insert(it->last_column, 0, it->last_column + 1, 1,
std::move(
widget));
134 for (
auto &cell: _grid) {
150 auto it =
std::max_element(_grid.begin(), _grid.end(), [](
auto const &a,
auto const &b) {
151 return a.last_row < b.last_row;
154 if (it == _grid.end()) {
157 return insert(0, it->last_row, 1, it->last_row + 1,
std::move(
widget));
171 template<
typename Widget,
typename... Args>
175 hi_axiom(first_column < last_column);
176 hi_axiom(first_row < last_row);
177 auto tmp = std::make_unique<Widget>(
this, std::forward<Args>(args)...);
178 return static_cast<Widget&
>(insert(first_column, first_row, last_column, last_row,
std::move(tmp)));
189 template<
typename Widget,
typename... Args>
192 return emplace<Widget>(column, row, column + 1, row + 1, std::forward<Args>(args)...);
203 template<
typename Widget,
typename... Args>
204 Widget&
emplace(std::string_view address, Args&&...args)
206 auto const[column_first, row_first, column_last, row_last] = parse_spreadsheet_range(address);
207 return emplace<Widget>(column_first, row_first, column_last, row_last, std::forward<Args>(args)...);
221 template<
typename Widget,
typename... Args>
224 return static_cast<Widget&
>(
push_front(std::make_unique<Widget>(
this, std::forward<Args>(args)...)));
237 template<
typename Widget,
typename... Args>
240 return static_cast<Widget&
>(
push_back(std::make_unique<Widget>(
this, std::forward<Args>(args)...)));
252 template<
typename Widget,
typename... Args>
255 return static_cast<Widget&
>(
push_top(std::make_unique<Widget>(
this, std::forward<Args>(args)...)));
266 template<
typename Widget,
typename... Args>
269 return static_cast<Widget&
>(
push_bottom(std::make_unique<Widget>(
this, std::forward<Args>(args)...)));
280 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
noexcept override
282 for (
auto const& cell : _grid) {
283 co_yield *cell.value;
287 [[nodiscard]] box_constraints update_constraints() noexcept
override
291 for (
auto& cell : _grid) {
292 cell.set_constraints(cell.value->update_constraints());
295 return _grid.constraints(os_settings::left_to_right());
298 void set_layout(widget_layout
const& context)
noexcept override
301 _grid.set_layout(context.shape, theme().baseline_adjustment());
304 for (
auto const& cell : _grid) {
309 void draw(draw_context
const& context)
noexcept override
312 for (
auto const& cell : _grid) {
313 cell.value->draw(context);
318 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
320 hi_axiom(loop::main().on_thread());
324 for (
auto const& cell : _grid) {
325 r = cell.value->hitbox_test_from_parent(position, r);
334 grid_layout<std::unique_ptr<widget>> _grid;
@ window_reconstrain
Request that widget get constraint on the next frame.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
The HikoGUI namespace.
Definition array_generic.hpp:20
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.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition widget_intf.hpp:24
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:43
widget & push_back(std::unique_ptr< widget > widget) noexcept
Insert a widget to the back of the grid.
Definition grid_widget.hpp:111
Widget & emplace(std::size_t column, std::size_t row, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:190
Widget & emplace_bottom(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:267
grid_widget(widget_intf const *parent) noexcept
Constructs an empty grid widget.
Definition grid_widget.hpp:53
Widget & emplace(std::string_view address, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:204
widget & push_bottom(std::unique_ptr< widget > widget) noexcept
Insert a widget to the bottom of the grid.
Definition grid_widget.hpp:148
Widget & emplace_back(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:238
widget & push_top(std::unique_ptr< widget > widget) noexcept
Insert a widget to the top of the grid.
Definition grid_widget.hpp:132
void clear() noexcept
Remove all child widgets.
Definition grid_widget.hpp:274
widget & push_front(std::unique_ptr< widget > widget) noexcept
Insert a widget to the front of the grid.
Definition grid_widget.hpp:93
Widget & emplace_top(Args &&...args)
Emplace a widget to the back.
Definition grid_widget.hpp:253
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:173
Widget & emplace_front(Args &&...args)
Emplace a widget to the front.
Definition grid_widget.hpp:222
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:130