49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <RmlUi/Core/Context.h>
|
|
#include <RmlUi/Core/DataModelHandle.h>
|
|
#include <RmlUi/Core/Element.h>
|
|
#include <RmlUi/Core/ElementDocument.h>
|
|
#include <RmlUi/Core/Factory.h>
|
|
#include <string>
|
|
|
|
class App;
|
|
|
|
class PageBase
|
|
{
|
|
public:
|
|
PageBase(std::string pageName, App* app) : pageName(std::move(pageName)), app(app) {}
|
|
virtual ~PageBase() = default;
|
|
|
|
const std::string& GetName() const { return pageName; }
|
|
bool TryLoadRmlPage(std::string path = "");
|
|
|
|
virtual void SetupDataModel(Rml::DataModelConstructor constructor) {}
|
|
virtual void OnEnter(Rml::Element *root) {}
|
|
virtual void OnExit() {}
|
|
|
|
protected:
|
|
App* GetApp() const {return app;}
|
|
void RegisterListener(Rml::Element* element, std::unique_ptr<Rml::EventListener> listener) {
|
|
if (element && listener) {
|
|
element->AddEventListener(Rml::EventId::Click, listener.get());
|
|
pageListeners.push_back(std::move(listener));
|
|
}
|
|
}
|
|
|
|
void DirtyVariable(const std::string& name) {
|
|
if (hasModel) model.DirtyVariable(name);
|
|
}
|
|
|
|
private:
|
|
friend class App;
|
|
|
|
std::string pageName;
|
|
App *app;
|
|
|
|
std::vector<std::unique_ptr<Rml::EventListener>> pageListeners;
|
|
|
|
Rml::Element *root = nullptr;
|
|
Rml::DataModelHandle model;
|
|
bool hasModel = false;
|
|
}; |