add icons and navigation
This commit is contained in:
@@ -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 .. ")")
|
||||
|
||||
Reference in New Issue
Block a user