HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
grid_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
11#include "widget.hpp"
12#include "../layout/grid_layout.hpp"
13#include <memory>
14
15namespace hi { inline namespace v1 {
16
39class grid_widget : public widget {
40public:
41 using super = widget;
42
44
50
61 template<typename Widget, typename... Args>
62 Widget&
63 make_widget(std::size_t first_column, std::size_t first_row, std::size_t last_column, std::size_t last_row, Args&&...args)
64 {
65 hi_axiom(first_column < last_column);
66 hi_axiom(first_row < last_row);
67 auto tmp = std::make_unique<Widget>(this, std::forward<Args>(args)...);
68 return static_cast<Widget&>(add_widget(first_column, first_row, last_column, last_row, std::move(tmp)));
69 }
70
79 template<typename Widget, typename... Args>
80 Widget& make_widget(std::size_t column, std::size_t row, Args&&...args)
81 {
82 return make_widget<Widget>(column, row, column + 1, row + 1, std::forward<Args>(args)...);
83 }
84
93 template<typename Widget, typename... Args>
94 Widget& make_widget(std::string_view address, Args&&...args)
95 {
96 hilet[column_first, row_first, column_last, row_last] = parse_spreadsheet_range(address);
97 return make_widget<Widget>(column_first, row_first, column_last, row_last, std::forward<Args>(args)...);
98 }
99
101 [[nodiscard]] generator<widget const &> children(bool include_invisible) const noexcept override
102 {
103 for (hilet& cell : _grid) {
104 co_yield *cell.value;
105 }
106 }
107
108 [[nodiscard]] box_constraints update_constraints() noexcept override;
109 void set_layout(widget_layout const& context) noexcept override;
110 void draw(draw_context const& context) noexcept override;
111 [[nodiscard]] hitbox hitbox_test(point2i position) const noexcept override;
113private:
114 grid_layout<std::unique_ptr<widget>> _grid;
115
116 /* Add a widget to the grid.
117 */
118 widget& add_widget(
119 std::size_t first_column,
120 std::size_t first_row,
121 std::size_t last_column,
122 std::size_t last_row,
123 std::unique_ptr<widget> child_widget) noexcept;
124};
125
126}} // namespace hi::v1
Defines widget.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A GUI widget that lays out child-widgets in a grid with variable sized cells.
Definition grid_widget.hpp:39
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:63
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:80
Widget & make_widget(std::string_view address, Args &&...args)
Add a widget directly to this grid-widget.
Definition grid_widget.hpp:94
grid_widget(widget *parent) noexcept
Constructs an empty grid widget.
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
T move(T... args)