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()) {
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()) {
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)));
224 return static_cast<Widget&
>(
push_front(std::make_unique<Widget>(
this, std::forward<Args>(
args)...)));
240 return static_cast<Widget&
>(
push_back(std::make_unique<Widget>(
this, std::forward<Args>(
args)...)));
255 return static_cast<Widget&
>(
push_top(std::make_unique<Widget>(
this, std::forward<Args>(
args)...)));
269 return static_cast<Widget&
>(
push_bottom(std::make_unique<Widget>(
this, std::forward<Args>(
args)...)));
282 for (
auto const&
cell : _grid) {
283 co_yield *
cell.value;
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) {
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);
@ 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_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
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.
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
Definition not_null.hpp:22
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
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
grid_widget(not_null< widget_intf const * > parent) noexcept
Constructs an empty grid widget.
Definition grid_widget.hpp:53
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(widget_intf const *parent) noexcept
Definition widget.hpp:49
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:124