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:
36
src/main.cpp
36
src/main.cpp
@@ -1,6 +1,8 @@
|
||||
#include "App.hpp"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <RmlUi/Core/ElementDocument.h>
|
||||
#include <RmlUi/Core/Event.h>
|
||||
#include <RmlUi/Debugger/Debugger.h>
|
||||
#include <RmlUi/Lua/Interpreter.h>
|
||||
#include <iostream>
|
||||
#include <RmlUi/Core/Context.h>
|
||||
#include <RmlUi/Core/Core.h>
|
||||
@@ -9,6 +11,11 @@
|
||||
#include <RmlUi_Backend.h>
|
||||
#include <RmlUi/Debugger.h>
|
||||
#include <RmlUi/Lua/Lua.h>
|
||||
#include <memory>
|
||||
#include "app.hpp"
|
||||
#include "test_page.hpp"
|
||||
#include "ButtonClickListener.hpp"
|
||||
#include "lui_app_api.hpp"
|
||||
|
||||
static bool is_initalized = false;
|
||||
static bool is_running = false;
|
||||
@@ -44,6 +51,10 @@ bool InitalizeApplication() {
|
||||
return false;
|
||||
}
|
||||
|
||||
lua_State* L = Rml::Lua::Interpreter::GetLuaState();
|
||||
AppLuaApi *lua_app_api = new AppLuaApi(app, L);
|
||||
lua_app_api->RegisterLuaBindings();
|
||||
|
||||
std::cout << "Application initalized...\n";
|
||||
|
||||
return true;
|
||||
@@ -55,7 +66,7 @@ bool f8_was_pressed = false;
|
||||
void handle_input() {
|
||||
GLFWwindow *window = glfwGetCurrentContext();
|
||||
if(window) {
|
||||
// Reload main page
|
||||
// Reload ui
|
||||
bool f5_state = glfwGetKey(window, GLFW_KEY_F5);
|
||||
if (f5_state == GLFW_PRESS && !f5_was_pressed) {
|
||||
f5_was_pressed = true;
|
||||
@@ -84,7 +95,25 @@ int main() {
|
||||
is_running = true;
|
||||
|
||||
std::cout << "Loading UI...\n";
|
||||
|
||||
app->RegisterPage<TestPagePage>("testPage");
|
||||
|
||||
app->SetupListeners([](Rml::ElementDocument *doc) {
|
||||
if (auto *btn = doc->GetElementById("nav-test")) {
|
||||
app->RegisterListener(btn, std::make_unique<ButtonClickListener>([](Rml::Event&){
|
||||
app->NavigateTo("testPage");
|
||||
}));
|
||||
}
|
||||
|
||||
if (auto *btn = doc->GetElementById("nav-about")) {
|
||||
app->RegisterListener(btn, std::make_unique<ButtonClickListener>([](Rml::Event&){
|
||||
app->NavigateTo("about");
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
app->LoadUi();
|
||||
app->NavigateTo("lua-test");
|
||||
std::cout << "UI Loaded\n";
|
||||
|
||||
while (is_running) {
|
||||
@@ -98,8 +127,9 @@ int main() {
|
||||
Backend::PresentFrame();
|
||||
}
|
||||
|
||||
delete app;
|
||||
app->Shutdown();
|
||||
Rml::Shutdown();
|
||||
delete app;
|
||||
Backend::Shutdown();
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user