12#include "../macros.hpp"
14namespace hi {
inline namespace v1 {
36 hi_axiom(loop::main().on_thread());
37 hi_assert_not_null(
parent);
42 _content_width_cbt = content_width.subscribe([&](
auto...) {
43 ++global_counter<
"scroll_aperture_widget:content_width:relayout">;
46 _content_height_cbt = content_height.subscribe([&](
auto...) {
47 ++global_counter<
"scroll_aperture_widget:content_height:relayout">;
50 _aperture_width_cbt = aperture_width.subscribe([&](
auto...) {
51 ++global_counter<
"scroll_aperture_widget:aperture_width:relayout">;
54 _aperture_height_cbt = aperture_height.subscribe([&](
auto...) {
55 ++global_counter<
"scroll_aperture_widget:aperture_height:relayout">;
58 _offset_x_cbt = offset_x.subscribe([&](
auto...) {
59 ++global_counter<
"scroll_aperture_widget:offset_x:relayout">;
62 _offset_y_cbt = offset_y.subscribe([&](
auto...) {
63 ++global_counter<
"scroll_aperture_widget:offset_y:relayout">;
66 _minimum_cbt =
minimum.subscribe([&](
auto...) {
67 ++global_counter<
"scroll_aperture_widget:minimum:reconstrain">;
75 hi_axiom(loop::main().on_thread());
76 hi_axiom(_content ==
nullptr);
78 auto tmp = std::make_unique<Widget>(
this, std::forward<Args>(args)...);
84 [[
nodiscard]]
bool x_axis_scrolls()
const noexcept
86 return *content_width > *aperture_width;
89 [[
nodiscard]]
bool y_axis_scrolls()
const noexcept
91 return *content_height > *aperture_height;
103 _content_constraints = _content->update_constraints();
115 aperture_width =
context.
width() - _content_constraints.margins.left() - _content_constraints.margins.right();
116 aperture_height =
context.height() - _content_constraints.margins.bottom() - _content_constraints.margins.top();
120 content_width = *aperture_width < _content_constraints.preferred.
width() ? _content_constraints.preferred.
width() :
122 content_height = *aperture_height < _content_constraints.preferred.
height() ?
123 _content_constraints.preferred.
height() :
136 _content_constraints,
138 -*offset_x + _content_constraints.margins.left(),
139 -*offset_y + _content_constraints.margins.bottom(),
142 theme().baseline_adjustment()};
146 _content->set_layout(
context.transform(_content_shape, 1.0f,
context.rectangle()));
156 [[
nodiscard]] hitbox hitbox_test(point2 position)
const noexcept override
158 hi_axiom(loop::main().on_thread());
161 auto r = _content->hitbox_test_from_parent(position);
163 if (
layout().contains(position)) {
164 r =
std::max(r, hitbox{
id, _layout.elevation});
175 hi_axiom(loop::main().on_thread());
177 if (
event == gui_event_type::mouse_wheel) {
185 ++global_counter<
"scroll_aperture_widget:mouse_wheel:relayout">;
196 auto safe_rectangle = intersect(_layout.rectangle(), _layout.clipping_rectangle);
237 decltype(content_width)::callback_token _content_width_cbt;
238 decltype(content_height)::callback_token _content_height_cbt;
239 decltype(aperture_width)::callback_token _aperture_width_cbt;
240 decltype(aperture_height)::callback_token _aperture_height_cbt;
241 decltype(offset_x)::callback_token _offset_x_cbt;
242 decltype(offset_y)::callback_token _offset_y_cbt;
243 decltype(
minimum)::callback_token _minimum_cbt;
@ window_relayout
Request that widgets get laid out on the next frame.
@ window_reconstrain
Request that widget get constraint on the next frame.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:56
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A high-level geometric extent.
Definition extent2.hpp:29
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:104
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:115
Definition translate2.hpp:14
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:208
A user interface event.
Definition gui_event.hpp:75
widget_id id
The numeric identifier of a widget.
Definition widget_intf.hpp:23
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
virtual void scroll_to_show(hi::aarectangle rectangle) noexcept=0
Scroll to show the given rectangle on the window.
The layout of a widget.
Definition widget_layout.hpp:38
2D constraints.
Definition box_constraints.hpp:25
Definition box_shape.hpp:18
A scroll aperture widget.
Definition scroll_aperture_widget.hpp:23
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget_layout const & layout() const noexcept override
Get the current layout for this widget.
Definition widget.hpp:169
int semantic_layer
The draw layer of the widget.
Definition widget.hpp:66
observer< extent2 > minimum
The minimum size this widget is allowed to be.
Definition widget.hpp:79
void scroll_to_show() noexcept
Scroll to show the important part of the widget.
Definition widget_intf.hpp:196
widget(widget *parent) noexcept
Definition widget.hpp:87
bool process_event(gui_event const &event) const noexcept override
Send a event to the window.
Definition widget.hpp:178
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition widget.hpp:198
observer< extent2 > maximum
The maximum size this widget is allowed to be.
Definition widget.hpp:83