11#include "../GUI/module.hpp"
14#include "../geometry/module.hpp"
15#include "../layout/grid_layout.hpp"
17namespace hi {
inline namespace v1 {
45template<
axis Axis = axis::both, fixed_string Name =
"">
49 constexpr static auto prefix = Name /
"scroll";
71 auto aperture = std::make_unique<aperture_type>(
this);
72 auto horizontal_bar = std::make_unique<horizontal_bar_type>(
73 this, aperture->content_width, aperture->aperture_width, aperture->offset_x);
74 auto vertical_bar = std::make_unique<vertical_bar_type>(
75 this, aperture->content_height, aperture->aperture_height, aperture->offset_y);
77 if (to_bool(
axis & axis::horizontal)) {
83 if (to_bool(
axis & axis::vertical)) {
89 _aperture = aperture.get();
90 _horizontal_bar = horizontal_bar.get();
91 _vertical_bar = vertical_bar.get();
93 _grid.add_cell(0, 0,
std::move(aperture));
94 _grid.add_cell(1, 0,
std::move(vertical_bar));
95 _grid.add_cell(0, 1,
std::move(horizontal_bar));
107 template<
typename Widget,
typename... Args>
110 return _aperture->make_widget<Widget>(std::forward<Args>(args)...);
114 [[nodiscard]] generator<widget const&> children(
bool include_invisible)
const noexcept override
117 co_yield *_vertical_bar;
118 co_yield *_horizontal_bar;
123 for (
auto& cell : _grid) {
124 cell.set_constraints(cell.value->update_constraints());
126 auto grid_constraints = _grid.constraints(os_settings::left_to_right());
130 void set_layout(widget_layout
const& context)
noexcept override
133 _grid.set_layout(context.shape, theme<prefix>.cap_height(
this));
136 for (
hilet& cell : _grid) {
137 auto shape = cell.shape;
139 if (cell.value.get() == _aperture) {
143 if (not _vertical_bar->visible()) {
144 shape.rectangle = aarectanglei{0, shape.y(), layout.width(), shape.height()};
146 if (not _horizontal_bar->visible()) {
147 shape.rectangle = aarectanglei{shape.x(), 0, shape.width(), layout.height()};
151 cell.value->set_layout(context.transform(shape, 0.0f));
155 void draw(widget_draw_context
const& context)
noexcept override
158 for (
hilet& cell : _grid) {
159 cell.value->draw(context);
164 [[nodiscard]] hitbox hitbox_test(point2i position)
const noexcept override
184 grid_layout<std::unique_ptr<widget>> _grid;
186 aperture_type *_aperture;
187 horizontal_bar_type *_horizontal_bar;
188 vertical_bar_type *_vertical_bar;
198template<fixed_string Name =
"">
208template<fixed_string Name =
"">
Defines scroll_bar_widget.
Defines scroll_aperture_widget.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:238
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:18
@ partial
A widget is partially enabled.
@ collapse
The widget is collapsed.
@ 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_id id
The numeric identifier of a widget.
Definition widget.hpp:35
observer< extent2i > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:89
observer< extent2i > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:93
widget * parent
Pointer to the parent widget.
Definition widget.hpp:40
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:53
size_t semantic_layer
The draw layer of the widget.
Definition widget.hpp:85
virtual hitbox hitbox_test_from_parent(point2i position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:149
constexpr bool contains(point3i mouse_position) const noexcept
Check if the mouse position is inside the widget.
Definition widget_layout.hpp:126
float elevation
The elevation of the widget above the window.
Definition widget_layout.hpp:72
2D constraints.
Definition box_constraints.hpp:22
A scroll aperture widget.
Definition scroll_aperture_widget.hpp:23
Scroll bar widget This widget is used in a pair of a vertical and horizontal scrollbar as a child of ...
Definition scroll_bar_widget.hpp:33
The scroll widget allows a content widget to be shown in less space than is required.
Definition scroll_widget.hpp:46
Widget & make_widget(Args &&...args) noexcept
Add a content widget directly to this scroll widget.
Definition scroll_widget.hpp:108
scroll_widget(widget *parent) noexcept
Constructs an empty scroll widget.
Definition scroll_widget.hpp:63