15#include "../layout/grid_layout.hpp"
17namespace hi {
inline namespace v1 {
45template<axis Axis = axis::both>
68 auto aperture = std::make_shared<scroll_aperture_widget>(
this);
69 auto horizontal_scroll_bar = std::make_shared<horizontal_scroll_bar_type>(
70 this, aperture->content_width, aperture->aperture_width, aperture->offset_x);
71 auto vertical_scroll_bar = std::make_shared<vertical_scroll_bar_type>(
72 this, aperture->content_height, aperture->aperture_height, aperture->offset_y);
74 if (to_bool(
axis & axis::horizontal)) {
80 if (to_bool(
axis & axis::vertical)) {
86 _aperture = aperture.get();
87 _horizontal_scroll_bar = horizontal_scroll_bar.get();
88 _vertical_scroll_bar = vertical_scroll_bar.get();
90 _grid.add_cell(0, 0,
std::move(aperture));
91 _grid.add_cell(1, 0,
std::move(vertical_scroll_bar));
92 _grid.add_cell(0, 1,
std::move(horizontal_scroll_bar));
104 template<
typename Widget,
typename... Args>
107 return _aperture->make_widget<Widget>(std::forward<Args>(args)...);
111 [[nodiscard]] generator<widget *> children() const noexcept
override
114 co_yield _vertical_scroll_bar;
115 co_yield _horizontal_scroll_bar;
122 for (
auto& cell : _grid) {
123 cell.set_constraints(cell.value->update_constraints());
125 auto grid_constraints = _grid.constraints(os_settings::left_to_right());
129 void set_layout(widget_layout
const& context)
noexcept override
132 _grid.set_layout(context.shape, theme().baseline_adjustment);
135 for (
hilet& cell : _grid) {
136 auto shape = cell.shape;
138 if (cell.value.get() == _aperture) {
142 if (not _vertical_scroll_bar->visible()) {
143 shape.rectangle = aarectanglei{0, shape.y(), _layout.width(), shape.height()};
145 if (not _horizontal_scroll_bar->visible()) {
146 shape.rectangle = aarectanglei{shape.x(), 0, shape.width(), _layout.height()};
150 cell.value->set_layout(context.transform(shape, 0.0f));
154 void draw(draw_context
const& context)
noexcept
157 for (
hilet& cell : _grid) {
158 cell.value->draw(context);
163 [[nodiscard]] hitbox hitbox_test(point2i position)
const noexcept override
172 if (
layout().contains(position)) {
173 r =
std::max(r, hitbox{
this, _layout.elevation});
183 grid_layout<std::shared_ptr<widget>> _grid;
185 scroll_aperture_widget *_aperture;
186 horizontal_scroll_bar_type *_horizontal_scroll_bar;
187 vertical_scroll_bar_type *_vertical_scroll_bar;
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:118
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Defines scroll_bar_widget.
Defines scroll_aperture_widget.
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:15
geometry/margins.hpp
Definition assert.hpp:18
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition utility.hpp:196
2D constraints.
Definition box_constraints.hpp:25
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:34
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:105
scroll_widget(widget *parent) noexcept
Constructs an empty scroll widget.
Definition scroll_widget.hpp:60
An interactive graphical object as part of the user-interface.
Definition widget.hpp:46
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget.hpp:194
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:86
observer< extent2i > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:99
widget(widget *parent) noexcept
observer< extent2i > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:103
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:62
virtual hitbox hitbox_test_from_parent(point2i position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:133