\ No newline at end of file
diff --git a/assets/pages/home.rml b/assets/pages/home.rml
new file mode 100644
index 0000000..032f7eb
--- /dev/null
+++ b/assets/pages/home.rml
@@ -0,0 +1,14 @@
+
+
Home
+
This is an RmlUi template project with some nice built in features such as:
+
+
- Lua and SVG plugins enabled
+
- A shell + page loading system with scoped stylesheets and lua functionality
+
- Hot reload when pressing F5
+
- Basic application state management
+
- A basic stylesheet for common elements
+
- Easy custom controls system
+
- Optional Raylib context
+
- Nix flake for easy development/building
+
+
\ No newline at end of file
diff --git a/assets/pages/lua-test.rml b/assets/pages/lua-test.rml
index f9e728c..a89e916 100644
--- a/assets/pages/lua-test.rml
+++ b/assets/pages/lua-test.rml
@@ -1,8 +1,10 @@
Lua test page
-
This button uses NavigateTo('about') lua code instead of a registered C++ event
+
This button uses NavigateTo('about') lua code instead of being harcoded in a C++ PageBase class:
+
If you have a .lua file with the same name as the page in the pages directory, it will be loaded at runtime so you can add functionality to a page like this:
+
This button calls LuaTest.Test() from the scoped `lua-test.lua` file
diff --git a/assets/pages/test-page.rcss b/assets/pages/test-page.rcss
new file mode 100644
index 0000000..8903548
--- /dev/null
+++ b/assets/pages/test-page.rcss
@@ -0,0 +1,3 @@
+#page-root h1 {
+ color: red;
+}
\ No newline at end of file
diff --git a/assets/pages/test-page.rml b/assets/pages/test-page.rml
new file mode 100644
index 0000000..6d7c007
--- /dev/null
+++ b/assets/pages/test-page.rml
@@ -0,0 +1,7 @@
+
+
Test page
+
{{greeting}}
+
+
+
If you have a .rcss file with the same name as the page in the pages directory, it will be loaded at runtime so you can add custom styling to a page, which is why the header is red on this page only.
+
\ No newline at end of file
diff --git a/assets/pages/testPage.rml b/assets/pages/testPage.rml
deleted file mode 100644
index 0843462..0000000
--- a/assets/pages/testPage.rml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
Test page
-
{{greeting}}
-
-
\ No newline at end of file
diff --git a/src/app.cpp b/src/app.cpp
index 25a9b95..bcb3346 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -2,6 +2,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -98,6 +99,17 @@ bool App::NavigateTo(const std::string &pageName) {
} else {
std::cout << "[WARN] failed to create data model for page '" << pageName << "'\n";
}
+
+ std::string rcssPath = GetAssetsPath() + "/pages/" + pageName + ".rcss";
+ if (std::filesystem::exists(rcssPath)) {
+ auto pageStyleSheet = Rml::Factory::InstanceStyleSheetFile(rcssPath);
+ if (pageStyleSheet && baseStyleSheet) {
+ auto combined = baseStyleSheet->CombineStyleSheetContainer(*pageStyleSheet);
+ doc->SetStyleSheetContainer(combined);
+ }
+ } else if (doc && baseStyleSheet) {
+ doc->SetStyleSheetContainer(baseStyleSheet);
+ }
pageOutlet->SetInnerRML(content);
@@ -125,6 +137,8 @@ bool App::LoadUi() {
std::cout << "[WARN] main.rml has no element with id=\"page-content\"\n";
}
+ baseStyleSheet = Rml::Factory::InstanceStyleSheetFile(GetAssetsPath() + "/styles/main.rcss");
+
listeners.clear();
if (onBindListeners) {
onBindListeners(doc);
diff --git a/src/app.hpp b/src/app.hpp
index 24d381e..3b6f1f4 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -42,6 +42,8 @@ private:
Rml::ElementDocument* doc;
Rml::Element* pageOutlet = nullptr;
+ Rml::SharedPtr baseStyleSheet;
+
std::vector> listeners;
std::function onBindListeners;
diff --git a/src/main.cpp b/src/main.cpp
index b3085da..96e7747 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -96,18 +96,18 @@ int main() {
std::cout << "Loading UI...\n";
- app->RegisterPage("testPage");
+ app->RegisterPage("test-page");
app->SetupListeners([](Rml::ElementDocument *doc) {
if (auto *btn = doc->GetElementById("nav-test")) {
app->RegisterListener(btn, std::make_unique([](Rml::Event&){
- app->NavigateTo("testPage");
+ app->NavigateTo("test-page");
}));
}
- if (auto *btn = doc->GetElementById("nav-about")) {
+ if (auto *btn = doc->GetElementById("nav-home")) {
app->RegisterListener(btn, std::make_unique([](Rml::Event&){
- app->NavigateTo("about");
+ app->NavigateTo("home");
}));
}
});