91 lines
2.1 KiB
Lua
91 lines
2.1 KiB
Lua
-- Navigation System for Virtual Smartphone
|
|
-- Handles screen transitions and state management
|
|
|
|
-- Screen registry - maps screen names to RML file paths
|
|
local screens = {
|
|
home = "demo.rml",
|
|
lock = "screens/lock.rml",
|
|
dialer = "screens/dialer.rml",
|
|
contacts = "screens/contacts.rml",
|
|
messages = "screens/messages.rml",
|
|
settings = "screens/settings.rml",
|
|
browser = "screens/browser.rml"
|
|
}
|
|
|
|
-- Navigation history stack
|
|
local history = {}
|
|
|
|
-- Current screen name
|
|
local current_screen = "home"
|
|
|
|
-- Navigate to a screen by name
|
|
function navigateTo(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
|
|
|
|
-- Load the new screen using C++ function
|
|
local success = loadScreen(path)
|
|
if success then
|
|
print("Navigated to: " .. screen_name)
|
|
else
|
|
-- Restore previous state on failure
|
|
current_screen = table.remove(history)
|
|
print("Failed to navigate to: " .. screen_name)
|
|
end
|
|
return success
|
|
else
|
|
print("Unknown screen: " .. screen_name)
|
|
return false
|
|
end
|
|
end
|
|
|
|
-- Go back to previous screen
|
|
function goBack()
|
|
if #history > 0 then
|
|
local previous = table.remove(history)
|
|
local path = screens[previous]
|
|
if path then
|
|
current_screen = previous
|
|
loadScreen(path)
|
|
print("Back to: " .. previous)
|
|
return true
|
|
end
|
|
else
|
|
print("No history to go back to")
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- Go to home screen (clear history)
|
|
function goHome()
|
|
history = {}
|
|
current_screen = "home"
|
|
loadScreen(screens.home)
|
|
print("Navigated to home")
|
|
end
|
|
|
|
-- Get current screen name
|
|
function getCurrentScreen()
|
|
return current_screen
|
|
end
|
|
|
|
-- Check if we can go back
|
|
function canGoBack()
|
|
return #history > 0
|
|
end
|
|
|
|
-- Clear navigation history
|
|
function clearHistory()
|
|
history = {}
|
|
end
|
|
|
|
-- Get history depth
|
|
function getHistoryDepth()
|
|
return #history
|
|
end
|
|
|
|
print("Navigation system initialized")
|