Receiver trait that adds mouse-drag behavior to any Component.
More...
#include <Draggable.h>
Public Types | |
| using | Flag = DraggableManifest::Flag |
| using | manifest_type |
The manifest type, used by GatherFlags and GatherStates to locate this class's flag and state declarations. | |
| using | State = DraggableManifest::State |
Public Member Functions | |
| 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. | |
Friends | |
| class | DraggableDispatcher |
Receiver trait that adds mouse-drag behavior to any Component.
Dragging is disabled by default. Enable via:
Definition at line 65 of file Draggable.h.
Definition at line 69 of file Draggable.h.
|
inherited |
The manifest type, used by GatherFlags and GatherStates to locate this class's flag and state declarations.
Definition at line 64 of file Customizable.h.
Definition at line 70 of file Draggable.h.
|
default |
|
virtualdefault |
| 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.
|
inherited |
Return the current state value.
StateEnum value.
|
inherited |
Return true if currently in state.
| state | The state value to compare against. |
true if the current state equals state.
|
inherited |
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.
| callback | Function called with the new state after each transition. |
|
inherited |
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.
| callback | Function called with the old state before each transition. |
|
virtualinherited |
Invoke all callbacks registered for key.
Called by framework dispatchers. key is the string produced by EnumKey::get(eventEnum).
| key | String key identifying the event. |
| event | SFML event forwarded to each callback. |
|
inherited |
Invoke all callbacks registered for eventName.
Template overload that accepts any enum value directly, converting to a string key via EnumKey::get() internally.
| ENUM_TYPE | Any enum type. |
| eventName | The enum value identifying the event. |
| event | SFML event forwarded to each callback. |
| 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.
| bounds | The world-space rectangle within which the component may be dragged. |
|
inherited |
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.
| newState | The state to transition into. |
|
friend |
Definition at line 103 of file Draggable.h.