14#include "../geometry/geometry.hpp"
15#include "../layout/layout.hpp"
16#include "../macros.hpp"
19hi_export_module(hikogui.widgets.scroll_widget);
21hi_export
namespace hi {
50template<axis Axis = axis::both>
67 hi_axiom(loop::main().on_thread());
69 auto aperture = std::make_unique<scroll_aperture_widget>();
70 aperture->set_parent(
this);
72 auto horizontal_scroll_bar =
73 std::make_unique<horizontal_scroll_bar_type>(aperture->content_width, aperture->aperture_width, aperture->offset_x);
74 horizontal_scroll_bar->set_parent(
this);
76 auto vertical_scroll_bar =
77 std::make_unique<vertical_scroll_bar_type>(aperture->content_height, aperture->aperture_height, aperture->offset_y);
78 vertical_scroll_bar->set_parent(
this);
80 if (to_bool(axis & axis::horizontal)) {
86 if (to_bool(axis & axis::vertical)) {
92 _aperture = aperture.get();
93 _horizontal_scroll_bar = horizontal_scroll_bar.get();
94 _vertical_scroll_bar = vertical_scroll_bar.get();
96 _grid.add_cell(0, 0,
std::move(aperture));
97 _grid.add_cell(1, 0,
std::move(vertical_scroll_bar));
98 _grid.add_cell(0, 1,
std::move(horizontal_scroll_bar));
110 template<
typename Widget,
typename... Args>
117 [[nodiscard]] generator<widget_intf&> children(
bool include_invisible)
noexcept override
120 co_yield *_vertical_scroll_bar;
121 co_yield *_horizontal_scroll_bar;
128 for (
auto& cell : _grid) {
129 cell.set_constraints(cell.value->update_constraints());
131 auto grid_constraints = _grid.constraints(os_settings::left_to_right());
135 void set_layout(widget_layout
const& context)
noexcept override
138 _grid.set_layout(context.shape, theme().baseline_adjustment());
141 for (
auto const& cell : _grid) {
142 auto shape = cell.shape;
144 if (cell.value.get() == _aperture) {
148 if (not _vertical_scroll_bar->visible()) {
149 shape.rectangle = aarectangle{0, shape.y(), _layout.width(), shape.height()};
151 if (not _horizontal_scroll_bar->visible()) {
152 shape.rectangle = aarectangle{shape.x(), 0, shape.width(), _layout.height()};
160 void draw(draw_context
const& context)
noexcept override
163 for (
auto const& cell : _grid) {
164 cell.value->draw(context);
169 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
171 hi_axiom(loop::main().on_thread());
174 auto r = _aperture->hitbox_test_from_parent(position);
175 r = _horizontal_scroll_bar->hitbox_test_from_parent(position, r);
176 r = _vertical_scroll_bar->hitbox_test_from_parent(position, r);
178 if (
layout().contains(position)) {
179 r =
std::max(r, hitbox{
id, _layout.elevation});
189 grid_layout<std::unique_ptr<widget>> _grid;
191 scroll_aperture_widget* _aperture;
192 horizontal_scroll_bar_type* _horizontal_scroll_bar;
193 vertical_scroll_bar_type* _vertical_scroll_bar;
Defines scroll_aperture_widget.
Defines scroll_bar_widget.
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:24
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
@ collapse
The widget is collapsed.
Definition widget_state.hpp:34
@ invisible
The widget is invisible.
Definition widget_state.hpp:41
scroll_widget< axis::horizontal > horizontal_scroll_widget
Horizontal scroll widget.
Definition scroll_widget.hpp:212
scroll_widget< axis::vertical > vertical_scroll_widget
Vertical scroll widget.
Definition scroll_widget.hpp:203
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
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.
Definition widget_layout.hpp:26
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:31
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:241
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:38
The scroll widget allows a content widget to be shown in less space than is required.
Definition scroll_widget.hpp:51
scroll_widget() noexcept
Constructs an empty scroll widget.
Definition scroll_widget.hpp:65
Widget & emplace(Args &&... args) noexcept
Add a content widget directly to this scroll widget.
Definition scroll_widget.hpp:111
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:42
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:50
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:110
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:46