Trait that adds per-frame update and window lifecycle callbacks to any Core object.
More...
#include <Updatable.h>
|
| void | onUpdate (std::function< void()> callback) |
| | Register a no-argument callback invoked every frame.
|
| void | onUpdate (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked every frame, receiving the SFML event.
|
| void | onWindowFocusGained (std::function< void()> callback) |
| | Register a no-argument callback invoked when the application window gains OS focus.
|
| void | onWindowFocusGained (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.
|
| void | onWindowFocusLost (std::function< void()> callback) |
| | Register a no-argument callback invoked when the application window loses OS focus.
|
| void | onWindowFocusLost (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.
|
| void | onWindowResized (std::function< void()> callback) |
| | Register a no-argument callback invoked when the application window is resized.
|
| void | onWindowResized (std::function< void(const std::optional< sf::Event > &)> callback) |
| | Register a callback invoked when the application window is resized, receiving the raw 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.
|
Trait that adds per-frame update and window lifecycle callbacks to any Core object.
Updatable is automatically inherited by every ml::Core object. It provides onUpdate for per-frame logic, and three window-level event hooks that fire when the application window changes state.
| Callback | Fires when |
onUpdate | Every frame, before drawing |
onWindowResized | The application window is resized |
onWindowFocusGained | The application window gains OS focus |
onWindowFocusLost | The application window loses OS focus |
Usage
mySprite.onUpdate([&]{
angle += rotationSpeed;
mySprite.setRotation(angle);
});
myPanel.onWindowResized([&](const std::optional<sf::Event>& e){
myPanel.setSize({float(r->size.x), float(r->size.y)});
});
To unsubscribe:
@ UPDATE
Every frame, before drawing.
@ WINDOW_RESIZED
Application window was resized.
- See also
- ml::Event::UPDATE, ml::Event::WINDOW_RESIZED, ml::Event::WINDOW_FOCUS_GAINED, ml::Event::WINDOW_FOCUS_LOST, UIController::onUpdate, Unsubscribable
Definition at line 56 of file Updatable.h.
◆ onUpdate() [1/2]
| void ml::Updatable::onUpdate |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked every frame.
The callback fires once per frame before the draw pass. All active components receive this regardless of hover or focus state.
- Parameters
-
| callback | Function invoked with no arguments each frame. |
◆ onUpdate() [2/2]
| void ml::Updatable::onUpdate |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked every frame, receiving the SFML event.
For frame events the std::optional<sf::Event> is always std::nullopt — use the no-argument overload unless you specifically need the optional parameter in your callback signature.
- Parameters
-
| callback | Function invoked with the SFML event (always nullopt) each frame. |
◆ onWindowFocusGained() [1/2]
| void ml::Updatable::onWindowFocusGained |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when the application window gains OS focus.
- Parameters
-
| callback | Function invoked with no arguments when focus is gained. |
◆ onWindowFocusGained() [2/2]
| void ml::Updatable::onWindowFocusGained |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when the application window gains OS focus, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event when focus is gained. |
◆ onWindowFocusLost() [1/2]
| void ml::Updatable::onWindowFocusLost |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when the application window loses OS focus.
- Parameters
-
| callback | Function invoked with no arguments when focus is lost. |
◆ onWindowFocusLost() [2/2]
| void ml::Updatable::onWindowFocusLost |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when the application window loses OS focus, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event when focus is lost. |
◆ onWindowResized() [1/2]
| void ml::Updatable::onWindowResized |
( |
std::function< void()> | callback | ) |
|
Register a no-argument callback invoked when the application window is resized.
- Parameters
-
| callback | Function invoked with no arguments on window resize. |
◆ onWindowResized() [2/2]
| void ml::Updatable::onWindowResized |
( |
std::function< void(const std::optional< sf::Event > &)> | callback | ) |
|
Register a callback invoked when the application window is resized, receiving the raw SFML event.
- Parameters
-
| callback | Function invoked with the SFML event on window resize. |
◆ 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
-
| key | String key identifying the event. |
| event | SFML 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
-
- Parameters
-
| eventName | The enum value identifying the event. |
| event | SFML event forwarded to each callback. |
The documentation for this class was generated from the following file: