Loading...
Searching...
No Matches
ml::UIController Class Referenceabstract

Concrete Controller base with a per-frame update hook. More...

#include <UIController.h>

Inheritance diagram for ml::UIController:

Public Member Functions

 ~UIController () override=default
void initialization () override=0
 Create and register all components and resources.
void onUpdate (std::function< void()> f)
 Register a callback invoked every frame during the update tick.
void registerEvents () override=0
 Attach event callbacks to components and framework objects.

Detailed Description

Concrete Controller base with a per-frame update hook.

UIController extends Controller with two additions:

  • A CoreAdapter proxy that gives this controller a lightweight framework identity (position, flags, event subscriptions) without being a full drawable component. This proxy is what AppManager uses to fire the "update" event at the controller level.
  • onUpdate() — a convenience method for registering a per-frame callback directly on the controller, useful for logic that doesn't belong to any single component.

Typical subclassing

class MyController : public ml::UIController
{
public:
void initialization() override
{
_button.setSize({120.f, 40.f});
_button.setPosition({100.f, 100.f});
addComponent(_button);
}
void registerEvents() override
{
_button.onClick([]{ std::cout << "clicked\n"; });
onUpdate([this]{
// per-frame controller logic
});
}
private:
ml::Rectangle _button;
};
Concrete Controller base with a per-frame update hook.
void initialization() override=0
Create and register all components and resources.
void registerEvents() override=0
Attach event callbacks to components and framework objects.
void onUpdate(std::function< void()> f)
Register a callback invoked every frame during the update tick.

Standalone use (separate controller + runner)

UIController can be passed to the Application constructor that accepts a controller reference, keeping the application runner and the UI logic in separate objects:

MyController controller;
ml::Application app(sf::VideoMode({1280, 720}), "My App", controller);
app.run();
void run() override
Enter the main loop and run until the window is closed.
Primary entry point for Malena applications without a manifest.

For simpler programs, inherit from ml::Application directly — it already inherits UIController and AppManager together.

See also
Controller, Application, AppManager, CoreAdapter

Definition at line 66 of file UIController.h.

Constructor & Destructor Documentation

◆ ~UIController()

ml::UIController::~UIController ( )
overridedefault

Member Function Documentation

◆ initialization()

void ml::UIController::initialization ( )
overridepure virtual

Create and register all components and resources.

Implement this method to construct the objects your application needs and register them with the appropriate managers (e.g., via addComponent). This method runs before registerEvents(), so every object you plan to subscribe to will already exist by the time callbacks are attached.

Implements ml::Controller.

Implemented in ml::Application, and ml::ApplicationWith< Manifest >.

◆ onUpdate()

void ml::UIController::onUpdate ( std::function< void()> f)

Register a callback invoked every frame during the update tick.

Equivalent to calling onUpdate on a component, but scoped to the controller itself. Use this for frame-level logic that is not tied to a specific component — for example, polling game state, advancing a timer, or orchestrating scene transitions.

Parameters
fCallback with no arguments, invoked once per frame.

◆ registerEvents()

void ml::UIController::registerEvents ( )
overridepure virtual

Attach event callbacks to components and framework objects.

Implement this method to wire up onClick, onHover, onUpdate, onMessage, and any other subscriptions. Called immediately after initialization() by AppManager before the main loop begins.

Implements ml::Controller.

Implemented in ml::Application, and ml::ApplicationWith< Manifest >.


The documentation for this class was generated from the following file: