Shell + page loading
And: - some basic stylesheet i found for basic html elements - a global lua method for navigating pages
This commit is contained in:
56
src/app.hpp
Normal file
56
src/app.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <RmlUi/Core/Context.h>
|
||||
#include <RmlUi/Core/ElementDocument.h>
|
||||
#include <RmlUi/Core/EventListener.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include "page.hpp"
|
||||
|
||||
struct ApplicationData {};
|
||||
|
||||
class App {
|
||||
public:
|
||||
App(Rml::Context* ctx, ApplicationData* appData);
|
||||
~App();
|
||||
|
||||
void SetupListeners(std::function<void(Rml::ElementDocument*)> bindCallback);
|
||||
void RegisterListener(Rml::Element* element, std::unique_ptr<Rml::EventListener> listener);
|
||||
|
||||
template <typename T = PageBase>
|
||||
void RegisterPage(const std::string &pageName) {
|
||||
static_assert(std::is_base_of<PageBase, T>::value, "T must derive from PageBase");
|
||||
pages[pageName] = std::make_unique<T>(pageName, this);
|
||||
}
|
||||
|
||||
bool NavigateTo(const std::string &pageName);
|
||||
|
||||
bool LoadUi();
|
||||
void Reload();
|
||||
|
||||
static std::string GetAssetsPath();
|
||||
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
ApplicationData *appData;
|
||||
Rml::Context* ctx;
|
||||
Rml::ElementDocument* doc;
|
||||
Rml::Element* pageOutlet = nullptr;
|
||||
|
||||
std::vector<std::unique_ptr<Rml::EventListener>> listeners;
|
||||
std::function<void(Rml::ElementDocument*)> onBindListeners;
|
||||
|
||||
std::unordered_map<std::string, std::unique_ptr<PageBase>> pages;
|
||||
PageBase* currentPage = nullptr;
|
||||
|
||||
PageBase* GetOrCreatePage(const std::string& pageName);
|
||||
static bool ReadFile(const std::string& path, std::string& outContent);
|
||||
void TeardownCurrentPage();
|
||||
|
||||
bool hasShutdown = false;
|
||||
};
|
||||
Reference in New Issue
Block a user