guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
drag_interaction.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26
27#include <utility/math/vector.hpp>
28
29#include "guillaume/ecs/component.hpp"
30
32{
33
63 {
64 public:
66 std::function<void(void)>;
67 using DragHandler = std::function<void(
68 const utility::math::Vector2F &)>;
70 std::function<void(void)>;
71
72 private:
73 bool _dragging { false };
74 utility::math::Vector2F _lastPosition {
75 0.0f, 0.0f
76 };
77 utility::math::Vector2F _delta {
78 0.0f, 0.0f
79 };
80 DragStartHandler _onDragStart {};
81 DragHandler _onDrag {};
82 DragEndHandler _onDragEnd {};
83
84 public:
89 DragInteraction(void) = default;
90
94 ~DragInteraction(void) = default;
95
100 bool isDragging(void) const;
101
111 DragInteraction &setDragging(bool dragging);
112
119 utility::math::Vector2F getLastPosition(void) const;
120
131 setLastPosition(const utility::math::Vector2F &position);
132
140 utility::math::Vector2F getDelta(void) const;
141
153 DragInteraction &setDelta(const utility::math::Vector2F &delta);
154
164
170
182
187 DragHandler getOnDragHandler(void) const;
188
198
204 };
205
206} // namespace guillaume::components
DragEndHandler getOnDragEndHandler(void) const
Get the callback run when a drag ends.
DragHandler getOnDragHandler(void) const
Get the callback run on each move of a drag.
std::function< void( const utility::math::Vector2F &)> DragHandler
Called on each move.
DragInteraction & setOnDragStartHandler(const DragStartHandler &handler)
Store the callback run when a drag starts.
DragInteraction & setOnDragEndHandler(const DragEndHandler &handler)
Store the callback run when a drag ends.
DragInteraction(void)=default
Construct a component with no drag in progress and no handler.
DragInteraction & setLastPosition(const utility::math::Vector2F &position)
Record the pointer position the next delta is measured from.
DragStartHandler getOnDragStartHandler(void) const
Get the callback run when a drag starts.
bool isDragging(void) const
Check whether a drag is in progress.
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.
std::function< void(void)> DragStartHandler
Callback run when a drag starts.
utility::math::Vector2F getLastPosition(void) const
Get the pointer position at the last motion event of the drag.
DragInteraction & setOnDragHandler(const DragHandler &handler)
Store the callback run on each move of a drag.
~DragInteraction(void)=default
Default destructor.
DragInteraction & setDragging(bool dragging)
Record whether a drag is in progress.
std::function< void(void)> DragEndHandler
Callback run when a drag ends.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.