Loading...
Searching...
No Matches
Keyable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Keyable.h
6//
7
8#pragma once
13#include <optional>
14namespace ml
15{
55 {
56 public:
57 // ── Key press ─────────────────────────────────────────────────────────
58
65 void onKeypress(std::function<void()> callback);
66
73 void onKeypress(std::function<void(const std::optional<sf::Event>&)> callback);
74
75 // ── Key release ───────────────────────────────────────────────────────
76
83 void onKeyRelease(std::function<void()> callback);
84
91 void onKeyRelease(std::function<void(const std::optional<sf::Event>&)> callback);
92
93 // ── Text entered (unicode) ────────────────────────────────────────────
94
105 void onTextEntered(std::function<void()> callback);
106
113 void onTextEntered(std::function<void(const std::optional<sf::Event>&)> callback);
114 };
115
117
123 class MALENA_API KeyableDispatcher : public EventDispatcher
124 {
125 public:
126 bool occurred(const std::optional<sf::Event>& event) override;
127 bool filter(const std::optional<sf::Event>& event, Core* component) override;
128 void fire(const std::optional<sf::Event>& event) override;
129 };
131
132} // namespace ml
133
134ML_EXPORT(KeyableDispatcher)
#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:69
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:55
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 ...
#define MALENA_API
Definition Component.h:22