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);
70 this, aperture->content_width, aperture->aperture_width, aperture->offset_x);
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();
90 _grid.add_cell(0, 0,
std::move(aperture));
107 return _aperture->emplace<
Widget>(std::forward<Args>(
args)...);
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());
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) {
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});
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.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
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.
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
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
Definition not_null.hpp:22
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(not_null< 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:83
widget(widget_intf const *parent) noexcept
Definition widget.hpp:49
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:45