12#include "../GUI/GUI.hpp"
13#include "../geometry/module.hpp"
14#include "../observer/module.hpp"
15#include "../utility/utility.hpp"
16#include "../macros.hpp"
25namespace hi {
inline namespace v1 {
52 widget(
parent), content(hi_forward(content)), aperture(hi_forward(aperture)), offset(hi_forward(offset))
54 _content_cbt = this->content.subscribe([&](
auto...) {
55 ++global_counter<
"scroll_bar_widget:content:relayout">;
58 _aperture_cbt = this->aperture.subscribe([&](
auto...) {
59 ++global_counter<
"scroll_bar_widget:aperture:relayout">;
62 _offset_cbt = this->offset.subscribe([&](
auto...) {
63 ++global_counter<
"scroll_bar_widget:offset:relayout">;
79 if constexpr (
axis == axis::vertical) {
81 extent2{theme().icon_size(), theme().size() * 4},
82 extent2{theme().icon_size(), theme().size() * 4},
86 extent2{theme().size() * 4, theme().icon_size()},
87 extent2{theme().size() * 4, theme().icon_size()},
97 _slider_rectangle = {};
103 if constexpr (
axis == axis::vertical) {
112 return *aperture < *content;
125 hi_axiom(loop::main().on_thread());
128 _slider_rectangle.
contains(position)) {
129 return {
id, _layout.elevation, hitbox_type::scroll_bar};
137 switch (
event.type()) {
138 case gui_event_type::mouse_down:
139 if (
event.mouse().cause.left_button) {
141 _offset_before_drag = *offset;
146 case gui_event_type::mouse_drag:
147 if (
event.mouse().cause.left_button) {
150 hilet
slider_movement =
axis == axis::vertical ?
event.drag_delta().y() :
event.drag_delta().x();
184 aarectangle _slider_rectangle;
186 float _offset_before_drag;
188 typename decltype(content)::callback_token _content_cbt;
189 typename decltype(aperture)::callback_token _aperture_cbt;
190 typename decltype(offset)::callback_token _offset_cbt;
204 hi_axiom(loop::main().on_thread());
210 hi_axiom(loop::main().on_thread());
213 if (*content == 0.0f) {
214 return rail_length();
216 return std::round(*aperture * rail_length() / *content);
227 hi_axiom(loop::main().on_thread());
228 return rail_length() - slider_length();
235 hi_axiom(loop::main().on_thread());
236 return *content - *aperture;
245 hi_axiom(loop::main().on_thread());
257 hi_axiom(loop::main().on_thread());
263 void draw_rails(draw_context
const&
context)
noexcept
270 void draw_slider(draw_context
const&
context)
noexcept
272 hilet corner_radii =
axis == axis::vertical ?
hi::corner_radii{_slider_rectangle.width() / 2.0f} :
276 layout(), translate_z(0.1f) * _slider_rectangle, foreground_color(), corner_radii);
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:19
@ window_relayout
Request that widgets get laid out on the next frame.
@ rectangle
The gui_event has rectangle data.
@ partial
A widget is partially enabled.
@ collapse
The widget is collapsed.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
This is a RGBA floating point color.
Definition color.hpp:45
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
constexpr bool contains(point2 const &rhs) const noexcept
Check if a 2D coordinate is inside the rectangle.
Definition aarectangle.hpp:264
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:19
A high-level geometric extent.
Definition extent2.hpp:29
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
The layout of a widget.
Definition widget_layout.hpp:38
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:37
hitbox hitbox_test(point2 position) const noexcept override
Find the widget that is under the mouse cursor.
Definition scroll_bar_widget.hpp:123
void draw(draw_context const &context) noexcept override
Draw the widget.
Definition scroll_bar_widget.hpp:115
bool handle_event(gui_event const &event) noexcept override
Handle command.
Definition scroll_bar_widget.hpp:135
void set_layout(widget_layout const &context) noexcept override
Update the internal layout of the widget.
Definition scroll_bar_widget.hpp:92
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition scroll_bar_widget.hpp:70
bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
Check if the widget will accept keyboard focus.
Definition scroll_bar_widget.hpp:164
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< bool > hover
Mouse cursor is hovering over the widget.
Definition widget.hpp:46
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