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 {
inline namespace v1 {
49template<axis Axis = axis::both>
66 hi_axiom(loop::main().on_thread());
68 auto aperture = std::make_unique<scroll_aperture_widget>(
this);
69 auto horizontal_scroll_bar = std::make_unique<horizontal_scroll_bar_type>(
70 this, aperture->content_width, aperture->aperture_width, aperture->offset_x);
71 auto vertical_scroll_bar = std::make_unique<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->emplace<Widget>(std::forward<Args>(args)...);
111 [[nodiscard]] generator<widget_intf &> children(
bool include_invisible)
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 (
auto const& cell : _grid) {
136 auto shape = cell.shape;
138 if (cell.value.get() == _aperture) {
142 if (not _vertical_scroll_bar->visible()) {
143 shape.rectangle = aarectangle{0, shape.y(), _layout.width(), shape.height()};
145 if (not _horizontal_scroll_bar->visible()) {
146 shape.rectangle = aarectangle{shape.x(), 0, shape.width(), _layout.height()};
154 void draw(draw_context
const& context)
noexcept override
157 for (
auto const& cell : _grid) {
158 cell.value->draw(context);
163 [[nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
165 hi_axiom(loop::main().on_thread());
172 if (
layout().contains(position)) {
173 r =
std::max(r, hitbox{
id, _layout.elevation});
183 grid_layout<std::unique_ptr<widget>> _grid;
185 scroll_aperture_widget *_aperture;
186 horizontal_scroll_bar_type *_horizontal_scroll_bar;
187 vertical_scroll_bar_type *_vertical_scroll_bar;
Defines scroll_bar_widget.
Defines scroll_aperture_widget.
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:24
@ partial
A widget is partially enabled.
@ collapse
The widget is collapsed.
@ invisible
The widget is invisible.
The HikoGUI namespace.
Definition array_generic.hpp:20
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.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition widget_intf.hpp:24
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:30
widget_layout const & layout() const noexcept
Get the current layout for this widget.
Definition widget_intf.hpp:206
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
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:50
scroll_widget(widget_intf const *parent) noexcept
Constructs an empty scroll widget.
Definition scroll_widget.hpp:64
Widget & emplace(Args &&...args) noexcept
Add a content widget directly to this scroll widget.
Definition scroll_widget.hpp:105
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:41
virtual hitbox hitbox_test_from_parent(point2 position) const noexcept
Call hitbox_test from a parent widget.
Definition widget.hpp:89
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:45