guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::Scrollable Class Reference

How far the content of an entity is scrolled, how large that content is, and how fast the mouse wheel scrolls it. More...

#include <headers/guillaume/components/scrollable.hpp>

Inheritance diagram for guillaume::components::Scrollable:
Collaboration diagram for guillaume::components::Scrollable:

Public Member Functions

 Scrollable (void)=default
 Construct a component scrolled to the origin, with an empty content and a scroll step of 1 on both axes.
 ~Scrollable (void)=default
 Default destructor.
utility::math::Vector2F getContentOffset (void) const
 Get how far the content is scrolled.
Scrollable & setContentOffset (const utility::math::Vector2F &offset)
 Scroll the content to an offset.
utility::math::Vector2F getContentSize (void) const
 Get the full size of the scrollable content.
Scrollable & setContentSize (const utility::math::Vector2F &size)
 Set the full size of the scrollable content.
utility::math::Vector2F getScrollStep (void) const
 Get how much one unit of wheel movement scrolls.
Scrollable & setScrollStep (const utility::math::Vector2F &step)
 Set how much one unit of wheel movement scrolls.
utility::math::Vector2F getMaxOffset (const utility::graphic::SizeF &viewport) const
 Get the largest offset that still shows content, for a viewport size.
Scrollable & clampOffset (const utility::graphic::SizeF &viewport)
 Bring the offset back between 0 and getMaxOffset().
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

How far the content of an entity is scrolled, how large that content is, and how fast the mouse wheel scrolls it.

The entity's Bound is the viewport: the visible window onto content that may be larger. The owner of the content sets the content size. systems::Scroll writes the offset in the Event phase: on each mouse wheel event it adds the wheel offset times the scroll step, then clamps the result between 0 and contentSize - viewportSize on each axis.

registry.addComponent<components::Scrollable>(identifier)
.setContentSize(utility::math::Vector2F({ 320.0f, 1200.0f }))
.setScrollStep(utility::math::Vector2F({ 0.0f, 24.0f }));
How far the content of an entity is scrolled, how large that content is, and how fast the mouse wheel...
Scrollable & setScrollStep(const utility::math::Vector2F &step)
Set how much one unit of wheel movement scrolls.
Scrollable & setContentSize(const utility::math::Vector2F &size)
Set the full size of the scrollable content.

This component only holds the offset: no system of the library moves the children by it, the code that places the content reads getContentOffset(). Sizes and offsets are in dp, like Bound. The setters store what they are given and always mark the component changed; only clampOffset() keeps the offset in range.

See also
systems::Scroll, Bound

Definition at line 57 of file scrollable.hpp.

Member Function Documentation

◆ clampOffset()

Scrollable & guillaume::components::Scrollable::clampOffset ( const utility::graphic::SizeF & viewport)

Bring the offset back between 0 and getMaxOffset().

Always marks the component changed, even when the offset was already in range.

Parameters
viewportThe size of the visible window, in dp; usually the entity's Bound.
Returns
This component, to chain calls.

Definition at line 74 of file scrollable.cpp.

Here is the call graph for this function:

◆ getContentOffset()

utility::math::Vector2F guillaume::components::Scrollable::getContentOffset ( void ) const

Get how far the content is scrolled.

Returns
The offset from the top-left of the content, in dp; (0, 0) when not scrolled.

Definition at line 29 of file scrollable.cpp.

◆ getContentSize()

utility::math::Vector2F guillaume::components::Scrollable::getContentSize ( void ) const

Get the full size of the scrollable content.

Returns
The content size, in dp.

Definition at line 42 of file scrollable.cpp.

◆ getMaxOffset()

utility::math::Vector2F guillaume::components::Scrollable::getMaxOffset ( const utility::graphic::SizeF & viewport) const

Get the largest offset that still shows content, for a viewport size.

Parameters
viewportThe size of the visible window, in dp; usually the entity's Bound.
Returns
contentSize - viewport on each axis, or 0 on an axis where the content fits in the viewport.

Definition at line 67 of file scrollable.cpp.

Here is the caller graph for this function:

◆ getScrollStep()

utility::math::Vector2F guillaume::components::Scrollable::getScrollStep ( void ) const

Get how much one unit of wheel movement scrolls.

Returns
The factor applied to the wheel offset, per axis.

Definition at line 54 of file scrollable.cpp.

◆ setContentOffset()

Scrollable & guillaume::components::Scrollable::setContentOffset ( const utility::math::Vector2F & offset)

Scroll the content to an offset.

The value is stored as given: call clampOffset() afterwards to keep it in range. Always marks the component changed.

Parameters
offsetThe offset from the top-left of the content, in dp.
Returns
This component, to chain calls.

Definition at line 35 of file scrollable.cpp.

Here is the call graph for this function:

◆ setContentSize()

Scrollable & guillaume::components::Scrollable::setContentSize ( const utility::math::Vector2F & size)

Set the full size of the scrollable content.

The offset is not clamped again. Always marks the component changed.

Parameters
sizeThe content size, in dp. A content smaller than the viewport cannot scroll.
Returns
This component, to chain calls.

Definition at line 47 of file scrollable.cpp.

Here is the call graph for this function:

◆ setScrollStep()

Scrollable & guillaume::components::Scrollable::setScrollStep ( const utility::math::Vector2F & step)

Set how much one unit of wheel movement scrolls.

Always marks the component changed.

Parameters
stepThe factor applied to the wheel offset, per axis: 0 locks an axis, a negative value reverses it.
Returns
This component, to chain calls.

Definition at line 59 of file scrollable.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: