Trait that adds mouse-wheel and raw mouse-button callbacks to any Core object.
More...
#include <Malena/Traits/Interaction/Scrollable.h>
|
| void | onMouseMoved (std::function< void()> callback, bool overwrite=true) |
| | 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, bool overwrite=true) |
| | Register a callback invoked whenever the mouse moves anywhere in the window, receiving the raw SFML event.
|
| void | onMousePressed (std::function< void()> callback, bool overwrite=true) |
| | 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, bool overwrite=true) |
| | Register a callback invoked when a mouse button is pressed, receiving the raw SFML event.
|
| void | onMouseReleased (std::function< void()> callback, bool overwrite=true) |
| | 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, bool overwrite=true) |
| | Register a callback invoked when a mouse button is released, receiving the raw SFML event.
|
| void | onScroll (std::function< void()> callback, bool overwrite=true) |
| | 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, bool overwrite=true) |
| | 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 54 of file Scrollable.h.
◆ onMouseMoved() [1/2]
| void ml::Scrollable::onMouseMoved |
( |
std::function< void()> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onMouseMoved() [2/2]
| void ml::Scrollable::onMouseMoved |
( |
std::function< void(const std::optional< sf::Event > &)> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onMousePressed() [1/2]
| void ml::Scrollable::onMousePressed |
( |
std::function< void()> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onMousePressed() [2/2]
| void ml::Scrollable::onMousePressed |
( |
std::function< void(const std::optional< sf::Event > &)> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onMouseReleased() [1/2]
| void ml::Scrollable::onMouseReleased |
( |
std::function< void()> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onMouseReleased() [2/2]
| void ml::Scrollable::onMouseReleased |
( |
std::function< void(const std::optional< sf::Event > &)> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onScroll() [1/2]
| void ml::Scrollable::onScroll |
( |
std::function< void()> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ onScroll() [2/2]
| void ml::Scrollable::onScroll |
( |
std::function< void(const std::optional< sf::Event > &)> | callback, |
|
|
bool | overwrite = true ) |
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. |
| overwrite | When true, replaces any existing callback; when false, appends an additional one. |
◆ 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. |
◆ _selfCore
| Core* ml::EventReceiver::_selfCore = nullptr |
|
inherited |
The owning Core, stamped by Core's constructor.
Traits subscribe from inside their OWN constructors (ml::TextInput calls onFocus(), ComponentCore subscribes to CLICK/HOVER/DRAG), at which point the derived type does not exist yet. Recovering the Core by dynamic_cast there is undefined: Clang returns something usable, MSVC throws "Access violation - no RTTI data!" and aborts the process. Core sets this on every one of its EventReceiver subobjects before any derived constructor runs, so no RTTI is ever needed.
Definition at line 93 of file EventReceiver.h.
The documentation for this class was generated from the following file: