-
C
+
-
-
B
+
-
@@ -117,10 +126,10 @@
diff --git a/assets/screens/lock.rml b/assets/screens/lock.rml
index 91a5f9e..967e298 100644
--- a/assets/screens/lock.rml
+++ b/assets/screens/lock.rml
@@ -1,5 +1,6 @@
+
@@ -168,8 +169,8 @@
diff --git a/assets/screens/messages.rml b/assets/screens/messages.rml
index c900e1c..dbfd303 100644
--- a/assets/screens/messages.rml
+++ b/assets/screens/messages.rml
@@ -1,5 +1,6 @@
+
@@ -131,9 +132,9 @@
@@ -218,6 +219,6 @@
-
+
+
diff --git a/assets/screens/settings.rml b/assets/screens/settings.rml
index 3eb0551..98e489d 100644
--- a/assets/screens/settings.rml
+++ b/assets/screens/settings.rml
@@ -1,5 +1,6 @@
+
@@ -149,9 +150,9 @@
diff --git a/assets/scripts/navigation.lua b/assets/scripts/navigation.lua
index a78460c..ade3c60 100644
--- a/assets/scripts/navigation.lua
+++ b/assets/scripts/navigation.lua
@@ -3,7 +3,7 @@
-- Screen registry - maps screen names to RML file paths
local screens = {
- home = "demo.rml",
+ home = "screens/home.rml",
lock = "screens/lock.rml",
dialer = "screens/dialer.rml",
contacts = "screens/contacts.rml",
@@ -12,27 +12,36 @@ local screens = {
browser = "screens/browser.rml"
}
--- Navigation history stack
-local history = {}
+-- Use global state to persist across document loads
+-- Initialize only if not already set
+if not _G.nav_state then
+ _G.nav_state = {
+ history = {},
+ current_screen = "home"
+ }
+end
--- Current screen name
-local current_screen = "home"
+-- Local references for convenience
+local history = _G.nav_state.history
+local function get_current() return _G.nav_state.current_screen end
+local function set_current(s) _G.nav_state.current_screen = s end
-- Navigate to a screen by name
function navigateTo(screen_name)
+ print("navigateTo called with: " .. tostring(screen_name))
local path = screens[screen_name]
if path then
-- Push current screen to history before navigating
- table.insert(history, current_screen)
- current_screen = screen_name
+ table.insert(history, get_current())
+ set_current(screen_name)
-- Load the new screen using C++ function
local success = loadScreen(path)
if success then
- print("Navigated to: " .. screen_name)
+ print("Navigated to: " .. screen_name .. " (history depth: " .. #history .. ")")
else
-- Restore previous state on failure
- current_screen = table.remove(history)
+ set_current(table.remove(history))
print("Failed to navigate to: " .. screen_name)
end
return success
@@ -44,11 +53,12 @@ end
-- Go back to previous screen
function goBack()
+ print("goBack called (history depth: " .. #history .. ")")
if #history > 0 then
local previous = table.remove(history)
local path = screens[previous]
if path then
- current_screen = previous
+ set_current(previous)
loadScreen(path)
print("Back to: " .. previous)
return true
@@ -61,15 +71,18 @@ end
-- Go to home screen (clear history)
function goHome()
- history = {}
- current_screen = "home"
+ -- Clear the history table
+ for i = #history, 1, -1 do
+ history[i] = nil
+ end
+ set_current("home")
loadScreen(screens.home)
print("Navigated to home")
end
-- Get current screen name
function getCurrentScreen()
- return current_screen
+ return get_current()
end
-- Check if we can go back
@@ -79,7 +92,9 @@ end
-- Clear navigation history
function clearHistory()
- history = {}
+ for i = #history, 1, -1 do
+ history[i] = nil
+ end
end
-- Get history depth
@@ -87,4 +102,4 @@ function getHistoryDepth()
return #history
end
-print("Navigation system initialized")
+print("Navigation system initialized (current: " .. get_current() .. ", history: " .. #history .. ")")
diff --git a/assets/html.rcss b/assets/ui/html.rcss
similarity index 100%
rename from assets/html.rcss
rename to assets/ui/html.rcss
diff --git a/main.cpp b/main.cpp
index 523b44a..eab380a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -29,6 +29,86 @@ struct AppState {
std::filesystem::path assets_path;
} g_app;
+// Custom system interface to enable logging
+class LoggingSystemInterface : public Rml::SystemInterface {
+public:
+ LoggingSystemInterface(Rml::SystemInterface* backend) : backend_(backend) {}
+
+ double GetElapsedTime() override { return backend_->GetElapsedTime(); }
+
+ bool LogMessage(Rml::Log::Type type, const Rml::String& message) override {
+ const char* type_str = "";
+ switch (type) {
+ case Rml::Log::LT_ERROR: type_str = "ERROR"; break;
+ case Rml::Log::LT_WARNING: type_str = "WARNING"; break;
+ case Rml::Log::LT_INFO: type_str = "INFO"; break;
+ case Rml::Log::LT_DEBUG: type_str = "DEBUG"; break;
+ default: type_str = "LOG"; break;
+ }
+ std::println("[RmlUi {}] {}", type_str, message);
+ return true;
+ }
+
+ // Forward JoinPath to fix Windows path issues
+ void JoinPath(Rml::String& translated_path, const Rml::String& document_path, const Rml::String& path) override {
+ // Fix paths where colon was converted to pipe (D| -> D:)
+ std::string fixed_path = path;
+ if (fixed_path.length() >= 2 && fixed_path[1] == '|') {
+ fixed_path[1] = ':';
+ }
+
+ std::string fixed_doc = document_path;
+ if (fixed_doc.length() >= 2 && fixed_doc[1] == '|') {
+ fixed_doc[1] = ':';
+ }
+
+ // Use std::filesystem to join paths properly and normalize (resolve ..)
+ std::filesystem::path doc_dir = std::filesystem::path(fixed_doc).parent_path();
+ std::filesystem::path result = (doc_dir / fixed_path).lexically_normal();
+ translated_path = result.generic_string();
+ std::println("JoinPath: {} + {} -> {}", fixed_doc, fixed_path, translated_path);
+ }
+
+private:
+ Rml::SystemInterface* backend_;
+};
+
+static LoggingSystemInterface* g_logging_interface = nullptr;
+
+// Custom file interface to fix Windows path issues (D| -> D:)
+class WindowsFileInterface : public Rml::FileInterface {
+public:
+ Rml::FileHandle Open(const Rml::String& path) override {
+ // Fix paths where colon was converted to pipe (D| -> D:)
+ std::string fixed_path = path;
+ if (fixed_path.length() >= 2 && fixed_path[1] == '|') {
+ fixed_path[1] = ':';
+ }
+ std::println("FileInterface::Open: {} -> {}", path, fixed_path);
+
+ FILE* fp = fopen(fixed_path.c_str(), "rb");
+ return reinterpret_cast(fp);
+ }
+
+ void Close(Rml::FileHandle file) override {
+ fclose(reinterpret_cast(file));
+ }
+
+ size_t Read(void* buffer, size_t size, Rml::FileHandle file) override {
+ return fread(buffer, 1, size, reinterpret_cast(file));
+ }
+
+ bool Seek(Rml::FileHandle file, long offset, int origin) override {
+ return fseek(reinterpret_cast(file), offset, origin) == 0;
+ }
+
+ size_t Tell(Rml::FileHandle file) override {
+ return ftell(reinterpret_cast(file));
+ }
+};
+
+static WindowsFileInterface* g_file_interface = nullptr;
+
void load_fonts(const std::filesystem::path& dir)
{
for (const auto& file : std::filesystem::directory_iterator(dir))
@@ -44,13 +124,15 @@ void load_fonts(const std::filesystem::path& dir)
// Path is relative to assets folder
int lua_loadScreen(lua_State* L)
{
+ std::println("lua_loadScreen called!");
const char* path = luaL_checkstring(L, 1);
+ std::println("Loading: {}", path);
std::filesystem::path full_path = g_app.assets_path / path;
if (!std::filesystem::exists(full_path))
{
- std::println("Screen not found: {}", full_path.string());
+ std::println("Screen not found: {}", full_path.generic_string());
lua_pushboolean(L, false);
return 1;
}
@@ -62,8 +144,10 @@ int lua_loadScreen(lua_State* L)
g_app.document = nullptr;
}
- // Load new document
- g_app.document = g_app.context->LoadDocument(full_path.string());
+ // Load new document with absolute path
+ std::string full_path_str = full_path.generic_string();
+ std::println("Full path: {}", full_path_str);
+ g_app.document = g_app.context->LoadDocument(full_path_str);
if (g_app.document)
{
g_app.document->Show();
@@ -233,10 +317,15 @@ int main(const int argc, const char* argv[])
return EXIT_FAILURE;
}
- Rml::SetSystemInterface(Backend::GetSystemInterface());
+ // Use custom interfaces
+ g_logging_interface = new LoggingSystemInterface(Backend::GetSystemInterface());
+ g_file_interface = new WindowsFileInterface();
+ Rml::SetSystemInterface(g_logging_interface);
+ Rml::SetFileInterface(g_file_interface);
Rml::SetRenderInterface(Backend::GetRenderInterface());
Rml::Initialise();
Rml::Lua::Initialise();
+ std::println("RmlUi and Lua initialized");
g_app.context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
if (!g_app.context)
@@ -249,31 +338,46 @@ int main(const int argc, const char* argv[])
// Register custom Lua functions
registerLuaFunctions();
- // Find the assets folder by checking for fonts
+ // Find the assets folder by checking for fonts/ subdirectory
g_app.assets_path = std::filesystem::absolute(file.parent_path());
- // Walk up the directory tree to find a folder containing .ttf fonts
+ // Walk up the directory tree to find a folder containing a fonts/ subdirectory with .ttf files
+ std::filesystem::path fonts_path;
while (!g_app.assets_path.empty() && g_app.assets_path.has_parent_path())
{
- bool has_fonts = false;
- for (const auto& entry : std::filesystem::directory_iterator(g_app.assets_path))
+ fonts_path = g_app.assets_path / "fonts";
+ if (std::filesystem::exists(fonts_path) && std::filesystem::is_directory(fonts_path))
{
- if (entry.path().extension() == ".ttf")
+ bool has_fonts = false;
+ for (const auto& entry : std::filesystem::directory_iterator(fonts_path))
{
- has_fonts = true;
- break;
+ if (entry.path().extension() == ".ttf")
+ {
+ has_fonts = true;
+ break;
+ }
}
+ if (has_fonts) break;
}
- if (has_fonts) break;
g_app.assets_path = g_app.assets_path.parent_path();
}
- load_fonts(g_app.assets_path);
+ load_fonts(fonts_path);
- g_app.document = g_app.context->LoadDocument(file.string());
+ // Load document with absolute path
+ std::filesystem::path abs_file = std::filesystem::absolute(file);
+ std::string abs_file_str = abs_file.generic_string();
+ std::println("Loading document: {}", abs_file_str);
+ std::println("Assets path: {}", g_app.assets_path.generic_string());
+ g_app.document = g_app.context->LoadDocument(abs_file_str);
if (g_app.document)
{
g_app.document->Show();
+ std::println("Document loaded successfully");
+ }
+ else
+ {
+ std::println("Failed to load document!");
}
// Dump mode: render and capture screenshot
@@ -350,7 +454,7 @@ int main(const int argc, const char* argv[])
g_app.context->UnloadDocument(g_app.document);
g_app.context->Update();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
- g_app.document = g_app.context->LoadDocument(file.string());
+ g_app.document = g_app.context->LoadDocument(abs_file_str);
if (g_app.document)
{
g_app.document->ReloadStyleSheet();
diff --git a/run.bat b/run.bat
new file mode 100644
index 0000000..9993053
--- /dev/null
+++ b/run.bat
@@ -0,0 +1,6 @@
+@echo off
+cd /d "%~dp0"
+echo Current directory: %CD%
+echo Running: build_lua\Debug\mosis-designer.exe assets\screens\home.rml
+build_lua\Debug\mosis-designer.exe assets\screens\home.rml
+pause