Loading...
Searching...
No Matches
ml::Scrollable Class Reference

Trait that adds mouse-wheel and raw mouse-button callbacks to any Core object. More...

#include <Scrollable.h>

Inheritance diagram for ml::Scrollable:

Public Member Functions

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.

Detailed Description

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

// Scroll a list view on wheel
listView.onScroll([&](const std::optional<sf::Event>& e){
if (auto* w = e->getIf<sf::Event::MouseWheelScrolled>())
offset -= w->delta * scrollSpeed;
});
// Track raw press/release for custom drag logic
handle.onMousePressed([]{ dragging = true; });
handle.onMouseReleased([]{ dragging = false; });

To unsubscribe:

myComp.unsubscribe(ml::Event::SCROLL);
myComp.unsubscribe(ml::Event::MOUSE_MOVED);
@ SCROLL
Mouse wheel scrolled over component.
Definition Event.h:45
@ MOUSE_MOVED
Mouse moved anywhere in window.
Definition Event.h:41
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.

Member Function Documentation

◆ 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
callbackFunction 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
keyString key identifying the event.
eventSFML 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
ENUM_TYPEAny enum type.
Parameters
eventNameThe enum value identifying the event.
eventSFML event forwarded to each callback.

The documentation for this class was generated from the following file: