Trait that adds mouse-wheel and raw mouse-button callbacks to any Core object.
More...
#include <Scrollable.h>
|
| void | onMouseMoved (std::function< void()> callback) |
| | Register a no-argument callback invoked whenever the mouse moves anywhere in the window.
|
| void | onMouseMoved (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked whenever the mouse moves anywhere in the window, receiving the raw SFML event.
|
| void | onMousePressed (std::function< void()> callback) |
| | Register a no-argument callback invoked when a mouse button is pressed anywhere in the window.
|
| void | onMousePressed (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when a mouse button is pressed, receiving the raw SFML event.
|
| void | onMouseReleased (std::function< void()> callback) |
| | Register a no-argument callback invoked when a mouse button is released anywhere in the window.
|
| void | onMouseReleased (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when a mouse button is released, receiving the raw SFML event.
|
| void | onScroll (std::function< void()> callback) |
| | Register a no-argument callback invoked when the mouse wheel is scrolled while the cursor is over this component.
|
| void | onScroll (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when the mouse wheel is scrolled while the cursor is over this component, receiving the SFML event.
|
| 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.
|
Trait that adds mouse-wheel and raw mouse-button callbacks to any Core object.
Scrollable is automatically inherited by every ml::Core object. It exposes four event hooks covering the mouse wheel and the low-level mouse button press/release cycle (before click logic is applied):
| Callback | Fires when |
onScroll | Mouse wheel is scrolled while the cursor is over this component |
onMouseMoved | Mouse moves anywhere in the window (all components receive this) |
onMousePressed | Mouse button is pressed (raw — before click logic) |
onMouseReleased | Mouse button is released (raw — before click logic) |
Usage
listView.onScroll([&](const std::optional<sf::Event>& e){
offset -= w->delta * scrollSpeed;
});
handle.onMousePressed([]{ dragging = true; });
handle.onMouseReleased([]{ dragging = false; });
To unsubscribe:
@ SCROLL
Mouse wheel scrolled over component.
@ MOUSE_MOVED
Mouse moved anywhere in window.
- See also
- Clickable, Draggable, ml::Event::SCROLL, ml::Event::MOUSE_MOVED, ml::Event::MOUSE_PRESSED, ml::Event::MOUSE_RELEASED, Unsubscribable
Definition at line 50 of file Scrollable.h.
◆ onMouseMoved() [1/2]
| void ml::Scrollable::onMouseMoved |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked whenever the mouse moves anywhere in the window.
Unlike onHover, this fires for every component regardless of whether the cursor is over it.
- Parameters
-
| callback | Function invoked with no arguments on mouse move. |
◆ onMouseMoved() [2/2]
| void ml::Scrollable::onMouseMoved |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked whenever the mouse moves anywhere in the window, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event on mouse move. |
◆ onMousePressed() [1/2]
| void ml::Scrollable::onMousePressed |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when a mouse button is pressed anywhere in the window.
This fires before click logic is evaluated. Prefer onClick for standard click handling.
- Parameters
-
| callback | Function invoked with no arguments on mouse press. |
◆ onMousePressed() [2/2]
| void ml::Scrollable::onMousePressed |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when a mouse button is pressed, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event on mouse press. |
◆ onMouseReleased() [1/2]
| void ml::Scrollable::onMouseReleased |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when a mouse button is released anywhere in the window.
This fires before click logic is evaluated. Prefer onClick for standard click handling.
- Parameters
-
| callback | Function invoked with no arguments on mouse release. |
◆ onMouseReleased() [2/2]
| void ml::Scrollable::onMouseReleased |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when a mouse button is released, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event on mouse release. |
◆ onScroll() [1/2]
| void ml::Scrollable::onScroll |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when the mouse wheel is scrolled while the cursor is over this component.
- Parameters
-
| callback | Function invoked with no arguments on scroll. |
◆ onScroll() [2/2]
| void ml::Scrollable::onScroll |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when the mouse wheel is scrolled while the cursor is over this component, receiving the SFML event.
- Parameters
-
| callback | Function invoked with the SFML event on scroll. |
◆ 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. |
The documentation for this class was generated from the following file: