Adding template project and correct name
This commit is contained in:
49
src/page.hpp
Normal file
49
src/page.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user