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

State of a drag gesture on an entity: whether it is in progress, how far the pointer moved since the previous motion event, and the callbacks for its start, its moves and its end. More...

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

Inheritance diagram for guillaume::components::DragInteraction:
Collaboration diagram for guillaume::components::DragInteraction:

Public Types

using DragStartHandler
 Callback run when a drag starts.
using DragHandler
 Called on each move.
using DragEndHandler
 Callback run when a drag ends.

Public Member Functions

 DragInteraction (void)=default
 Construct a component with no drag in progress and no handler.
 ~DragInteraction (void)=default
 Default destructor.
bool isDragging (void) const
 Check whether a drag is in progress.
DragInteraction & setDragging (bool dragging)
 Record whether a drag is in progress.
utility::math::Vector2F getLastPosition (void) const
 Get the pointer position at the last motion event of the drag.
DragInteraction & setLastPosition (const utility::math::Vector2F &position)
 Record the pointer position the next delta is measured from.
utility::math::Vector2F getDelta (void) const
 Get the movement of the pointer between the two last motion events of the drag.
DragInteraction & setDelta (const utility::math::Vector2F &delta)
 Record the movement of the pointer since the previous motion event.
DragInteraction & setOnDragStartHandler (const DragStartHandler &handler)
 Store the callback run when a drag starts.
DragStartHandler getOnDragStartHandler (void) const
 Get the callback run when a drag starts.
DragInteraction & setOnDragHandler (const DragHandler &handler)
 Store the callback run on each move of a drag.
DragHandler getOnDragHandler (void) const
 Get the callback run on each move of a drag.
DragInteraction & setOnDragEndHandler (const DragEndHandler &handler)
 Store the callback run when a drag ends.
DragEndHandler getOnDragEndHandler (void) const
 Get the callback run when a drag ends.
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

State of a drag gesture on an entity: whether it is in progress, how far the pointer moved since the previous motion event, and the callbacks for its start, its moves and its end.

systems::Drag writes it in the Event phase, on the entities that have a DragInteraction, a Transform, a Bound, a MouseButtonInteraction and a HandButtonInteraction. A drag starts on the first mouse motion event received while the primary button (left mouse button or hand button A) is held on the entity, continues on every following motion event, and ends on the first motion event received after the button was released or the entity was disabled. systems::StyleState copies the dragging flag into StyleState::isDragged.

registry.addComponent<components::DragInteraction>(identifier)
.setOnDragHandler([](const utility::math::Vector2F &delta) {
moveThumb(delta.x);
});
State of a drag gesture on an entity: whether it is in progress, how far the pointer moved since the ...
DragInteraction & setOnDragHandler(const DragHandler &handler)
Store the callback run on each move of a drag.

Positions and deltas are in the coordinates of the mouse motion event (view coordinates), not in dp. The delta is the movement between the two last motion events, not the distance since the start of the drag. Nothing happens in a frame without mouse motion event.

See also
systems::Drag, MouseButtonInteraction, StyleState

Definition at line 62 of file drag_interaction.hpp.

Member Typedef Documentation

◆ DragEndHandler

Initial value:
std::function<void(void)>

Callback run when a drag ends.

Definition at line 69 of file drag_interaction.hpp.

◆ DragHandler

Initial value:
std::function<void(
const utility::math::Vector2F &)>

Called on each move.

Definition at line 67 of file drag_interaction.hpp.

◆ DragStartHandler

Initial value:
std::function<void(void)>

Callback run when a drag starts.

Definition at line 65 of file drag_interaction.hpp.

Member Function Documentation

◆ getDelta()

utility::math::Vector2F guillaume::components::DragInteraction::getDelta ( void ) const

Get the movement of the pointer between the two last motion events of the drag.

Returns
The delta, in the coordinates of the mouse motion event. It keeps its last value after the drag ended; (0, 0) before the first move.

Definition at line 54 of file drag_interaction.cpp.

◆ getLastPosition()

utility::math::Vector2F guillaume::components::DragInteraction::getLastPosition ( void ) const

Get the pointer position at the last motion event of the drag.

Returns
The position, in the coordinates of the mouse motion event; (0, 0) before the first drag.

Definition at line 42 of file drag_interaction.cpp.

◆ getOnDragEndHandler()

DragInteraction::DragEndHandler guillaume::components::DragInteraction::getOnDragEndHandler ( void ) const

Get the callback run when a drag ends.

Returns
A copy of the handler; empty when none was set.

Definition at line 100 of file drag_interaction.cpp.

◆ getOnDragHandler()

DragInteraction::DragHandler guillaume::components::DragInteraction::getOnDragHandler ( void ) const

Get the callback run on each move of a drag.

Returns
A copy of the handler; empty when none was set.

Definition at line 87 of file drag_interaction.cpp.

◆ getOnDragStartHandler()

DragInteraction::DragStartHandler guillaume::components::DragInteraction::getOnDragStartHandler ( void ) const

Get the callback run when a drag starts.

Returns
A copy of the handler; empty when none was set.

Definition at line 75 of file drag_interaction.cpp.

◆ isDragging()

bool guillaume::components::DragInteraction::isDragging ( void ) const

Check whether a drag is in progress.

Returns
True from the start of the drag until its end.

Definition at line 27 of file drag_interaction.cpp.

◆ setDelta()

DragInteraction & guillaume::components::DragInteraction::setDelta ( const utility::math::Vector2F & delta)

Record the movement of the pointer since the previous motion event.

Called by systems::Drag, which then passes the same delta to the drag handler. Always marks the component changed.

Parameters
deltaThe movement, in the coordinates of the mouse motion event.
Returns
This component, to chain calls.

Definition at line 60 of file drag_interaction.cpp.

Here is the call graph for this function:

◆ setDragging()

DragInteraction & guillaume::components::DragInteraction::setDragging ( bool dragging)

Record whether a drag is in progress.

Called by systems::Drag; it calls no handler. Marks the component changed only when the flag differs.

Parameters
draggingTrue when a drag is in progress.
Returns
This component, to chain calls.

Definition at line 32 of file drag_interaction.cpp.

Here is the call graph for this function:

◆ setLastPosition()

DragInteraction & guillaume::components::DragInteraction::setLastPosition ( const utility::math::Vector2F & position)

Record the pointer position the next delta is measured from.

Called by systems::Drag. Does not mark the component changed.

Parameters
positionThe pointer position, in the coordinates of the mouse motion event.
Returns
This component, to chain calls.

Definition at line 47 of file drag_interaction.cpp.

Here is the call graph for this function:

◆ setOnDragEndHandler()

DragInteraction & guillaume::components::DragInteraction::setOnDragEndHandler ( const DragEndHandler & handler)

Store the callback run when a drag ends.

Does not mark the component changed.

Parameters
handlerThe callback, or nullptr to remove the current one.
Returns
This component, to chain calls.

Definition at line 93 of file drag_interaction.cpp.

◆ setOnDragHandler()

DragInteraction & guillaume::components::DragInteraction::setOnDragHandler ( const DragHandler & handler)

Store the callback run on each move of a drag.

It receives the movement since the previous motion event. It is not called for the motion event that starts the drag. Does not mark the component changed.

Parameters
handlerThe callback, or nullptr to remove the current one.
Returns
This component, to chain calls.

Definition at line 81 of file drag_interaction.cpp.

◆ setOnDragStartHandler()

DragInteraction & guillaume::components::DragInteraction::setOnDragStartHandler ( const DragStartHandler & handler)

Store the callback run when a drag starts.

Does not mark the component changed.

Parameters
handlerThe callback, or nullptr to remove the current one.
Returns
This component, to chain calls.

Definition at line 68 of file drag_interaction.cpp.


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