Loading...
Searching...
No Matches
Keyable.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// Keyable.h
6//
7
8#pragma once
13#include <optional>
14namespace ml
15{
55 {
56 public:
57 // ── Key press ─────────────────────────────────────────────────────────
58
66 void onKeypress(std::function<void()> callback, bool overwrite = true);
67
75 void onKeypress(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
76
77 // ── Key release ───────────────────────────────────────────────────────
78
86 void onKeyRelease(std::function<void()> callback, bool overwrite = true);
87
95 void onKeyRelease(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
96
97 // ── Text entered (unicode) ────────────────────────────────────────────
98
110 void onTextEntered(std::function<void()> callback, bool overwrite = true);
111
119 void onTextEntered(std::function<void(const std::optional<sf::Event>&)> callback, bool overwrite = true);
120 };
121
123
129 class MALENA_API KeyableDispatcher : public EventDispatcher
130 {
131 public:
132 bool occurred(const std::optional<sf::Event>& event) override;
133 bool filter(const std::optional<sf::Event>& event, Core* component) override;
134 void fire(const std::optional<sf::Event>& event) override;
135 };
137
138} // namespace ml
139
140ML_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:97
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 onKeypress(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=true)
Register a callback invoked when a key is pressed while this component has focus, receiving the raw S...
void onKeypress(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked when a key is pressed while this component has focus.
void onKeyRelease(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked when a key is released while this component has focus.
void onKeyRelease(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=true)
Register a callback invoked when a key is released while this component has focus,...
void onTextEntered(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked when a unicode character is entered while this component has ...
void onTextEntered(std::function< void(const std::optional< sf::Event > &)> callback, bool overwrite=true)
Register a callback invoked when a unicode character is entered while this component has focus,...
#define MALENA_API
Definition Component.h:22