Loading...
Searching...
No Matches
Keyable.h
Go to the documentation of this file.
1//
2// Keyable.h
3//
4
5#pragma once
9
10namespace ml
11{
50 class Keyable : public EventReceiver
51 {
52 public:
53 // ── Key press ─────────────────────────────────────────────────────────
54
61 void onKeypress(std::function<void()> callback);
62
69 void onKeypress(std::function<void(const std::optional<sf::Event>&)> callback);
70
71 // ── Key release ───────────────────────────────────────────────────────
72
79 void onKeyRelease(std::function<void()> callback);
80
87 void onKeyRelease(std::function<void(const std::optional<sf::Event>&)> callback);
88
89 // ── Text entered (unicode) ────────────────────────────────────────────
90
101 void onTextEntered(std::function<void()> callback);
102
109 void onTextEntered(std::function<void(const std::optional<sf::Event>&)> callback);
110 };
111
113
119 class KeyableDispatcher : public EventDispatcher
120 {
121 public:
122 bool occurred(const std::optional<sf::Event>& event) override;
123 bool filter(const std::optional<sf::Event>& event, Core* component) override;
124 void fire(const std::optional<sf::Event>& event) override;
125 };
127
128} // namespace ml
129
130ML_EXPORT(KeyableDispatcher)
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:38
Virtual base class for all Malena framework objects.
Definition Core.h:67
Base class for all per-event dispatchers in the Malena event system.
Base class for all event-receiving traits.
Trait that adds keyboard-input callbacks to any Core object.
Definition Keyable.h:51
void onTextEntered(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when a unicode character is entered while this component has focus,...
void onKeyRelease(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when a key is released while this component has focus,...
void onKeypress(std::function< void(const std::optional< sf::Event > &)> callback)
Register a callback invoked when a key is pressed while this component has focus, receiving the raw S...
void onKeyRelease(std::function< void()> callback)
Register a no-argument callback invoked when a key is released while this component has focus.
void onKeypress(std::function< void()> callback)
Register a no-argument callback invoked when a key is pressed while this component has focus.
void onTextEntered(std::function< void()> callback)
Register a no-argument callback invoked when a unicode character is entered while this component has ...
Definition Component.h:18