Loading...
Searching...
No Matches
Scrollable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// Scrollable.h
6//
7
8#pragma once
13
14namespace ml
15{
55 {
56 public:
57 // ── Mouse wheel ───────────────────────────────────────────────────────
58
66 void onScroll(std::function<void()> callback, bool overwrite = true);
67
75 void onScroll(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
76
77 // ── Mouse moved (fires for all components regardless of hover) ─────────
78
89 void onMouseMoved(std::function<void()> callback, bool overwrite = true);
90
98 void onMouseMoved(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
99
100 // ── Mouse button pressed (raw — before click logic) ───────────────────
101
112 void onMousePressed(std::function<void()> callback, bool overwrite = true);
113
121 void onMousePressed(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
122
123 // ── Mouse button released (raw — before click logic) ──────────────────
124
135 void onMouseReleased(std::function<void()> callback, bool overwrite = true);
136
144 void onMouseReleased(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
145 };
146
148
154 class MALENA_API ScrollableDispatcher : public EventDispatcher
155 {
156 public:
157 bool occurred(const std::optional<sf::Event>& event) override;
158 bool filter(const std::optional<sf::Event>& event, Core* component) override;
159 void fire(const std::optional<sf::Event>& event) override;
160 };
162
163} // namespace ml
164
165ML_EXPORT(ScrollableDispatcher)
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:43
Virtual base class for all Malena framework objects.
Definition Core.h:97
Base class for all per-event dispatchers in the Malena event system.
Base class for all event-receiving traits.
Trait that adds mouse-wheel and raw mouse-button callbacks to any Core object.
Definition Scrollable.h:55
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 onMouseMoved(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked whenever the mouse moves anywhere in the window.
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 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 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,...
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 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 e...
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 thi...
#define MALENA_API
Definition Component.h:22