Receiver trait that adds mouse-drag behavior to any Component.
More...
#include <Malena/Traits/Interaction/Draggable.h>
|
| | Draggable ()=default |
| virtual | ~Draggable ()=default |
| void | clearDragBounds () |
| | Remove any previously set drag bounds.
|
| std::enable_if_t<!std::is_void_v< T >, T > | getState () const |
| | Return the current state value.
|
| std::enable_if_t<!std::is_void_v< T >, bool > | isState (T state) const |
| | Return true if currently in state.
|
| std::enable_if_t<!std::is_void_v< T > > | onStateEnter (std::function< void(T)> callback) |
| | Register a callback invoked after each state transition.
|
| std::enable_if_t<!std::is_void_v< T > > | onStateExit (std::function< void(T)> callback) |
| | Register a callback invoked before each state transition.
|
| virtual void | process (const std::string &key, const std::optional< sf::Event > &event) |
| | Invoke all callbacks registered for key.
|
| template<typename ENUM_TYPE> |
| void | process (ENUM_TYPE eventName, const std::optional< sf::Event > &event) |
| | Invoke all callbacks registered for eventName.
|
| void | setDragBounds (const sf::FloatRect &bounds) |
| | Constrain drag movement to an axis-aligned bounding rectangle.
|
| std::enable_if_t<!std::is_void_v< T > > | setState (T newState) |
| | Transition to a new state.
|
Receiver trait that adds mouse-drag behavior to any Component.
Dragging is disabled by default. Enable via:
@ DRAGGABLE
Enables drag handling in ComponentCore.
Axis locking
myComponent.setState(ml::Draggable::State::LOCK_X);
myComponent.setState(ml::Draggable::State::LOCK_Y);
myComponent.setState(ml::Draggable::State::FREE);
Drag bounds
myComponent.setDragBounds(
sf::FloatRect{{50.f, 50.f}, {400.f, 300.f}});
myComponent.clearDragBounds();
- See also
- DraggableManifest, DraggableDispatcher
Definition at line 69 of file Draggable.h.
◆ Flag
◆ manifest_type
◆ State
◆ Draggable()
| ml::Draggable::Draggable |
( |
| ) |
|
|
default |
◆ ~Draggable()
| virtual ml::Draggable::~Draggable |
( |
| ) |
|
|
virtualdefault |
◆ clearDragBounds()
| void ml::Draggable::clearDragBounds |
( |
| ) |
|
Remove any previously set drag bounds.
After this call the component can be dragged freely across the window with no position clamping. Has no effect if no bounds were set.
◆ getState()
Return the current state value.
- Returns
- The active
StateEnum value.
◆ isState()
Return true if currently in state.
- Parameters
-
| state | The state value to compare against. |
- Returns
true if the current state equals state.
◆ onStateEnter()
Register a callback invoked after each state transition.
The callback receives the newly entered state. Only one enter callback is active at a time; calling this again replaces it.
- Parameters
-
| callback | Function called with the new state after each transition. |
◆ onStateExit()
Register a callback invoked before each state transition.
The callback receives the state being left. Only one exit callback is active at a time; calling this again replaces it.
- Parameters
-
| callback | Function called with the old state before each transition. |
◆ process() [1/2]
| virtual void ml::EventReceiver::process |
( |
const std::string & | key, |
|
|
const std::optional< sf::Event > & | event ) |
|
virtualinherited |
Invoke all callbacks registered for key.
Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).
- Parameters
-
| key | String key identifying the event. |
| event | SFML event forwarded to each callback. |
◆ process() [2/2]
template<typename ENUM_TYPE>
| void ml::EventReceiver::process |
( |
ENUM_TYPE | eventName, |
|
|
const std::optional< sf::Event > & | event ) |
|
inherited |
Invoke all callbacks registered for eventName.
Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.
- Template Parameters
-
- Parameters
-
| eventName | The enum value identifying the event. |
| event | SFML event forwarded to each callback. |
◆ setDragBounds()
| void ml::Draggable::setDragBounds |
( |
const sf::FloatRect & | bounds | ) |
|
Constrain drag movement to an axis-aligned bounding rectangle.
While bounds are set, the component's position is clamped so that its top-left corner never moves outside bounds during a drag gesture. Bounds are applied in world coordinates.
Call clearDragBounds() to remove the constraint and allow free movement again.
- Parameters
-
| bounds | The world-space rectangle within which the component may be dragged. |
◆ setState()
Transition to a new state.
Fires the exit callback with the current state, updates the stored state to newState, then fires the enter callback with the new state. Either callback may be unset (nullptr), in which case it is skipped.
- Parameters
-
| newState | The state to transition into. |
◆ DraggableDispatcher
| friend class DraggableDispatcher |
|
friend |
The documentation for this class was generated from the following file: