add lua navigation
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
-- Navigation System for Virtual Smartphone
|
||||
-- Handles screen transitions and state management
|
||||
|
||||
-- Screen registry
|
||||
-- Screen registry - maps screen names to RML file paths
|
||||
local screens = {
|
||||
home = "screens/home.rml",
|
||||
home = "demo.rml",
|
||||
lock = "screens/lock.rml",
|
||||
dialer = "screens/dialer.rml",
|
||||
contacts = "screens/contacts.rml",
|
||||
@@ -12,33 +12,59 @@ local screens = {
|
||||
browser = "screens/browser.rml"
|
||||
}
|
||||
|
||||
-- Current screen state
|
||||
local current_screen = "home"
|
||||
local screen_history = {}
|
||||
-- Navigation history stack
|
||||
local history = {}
|
||||
|
||||
-- Navigate to a screen
|
||||
-- Current screen name
|
||||
local current_screen = "home"
|
||||
|
||||
-- Navigate to a screen by name
|
||||
function navigateTo(screen_name)
|
||||
if screens[screen_name] then
|
||||
-- Add current screen to history
|
||||
table.insert(screen_history, current_screen)
|
||||
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 document
|
||||
-- Note: In RmlUi, we'd typically use document loading
|
||||
print("Navigating to: " .. 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 #screen_history > 0 then
|
||||
current_screen = table.remove(screen_history)
|
||||
print("Going back to: " .. current_screen)
|
||||
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
|
||||
@@ -46,9 +72,19 @@ function getCurrentScreen()
|
||||
return current_screen
|
||||
end
|
||||
|
||||
-- Check if we can go back
|
||||
function canGoBack()
|
||||
return #history > 0
|
||||
end
|
||||
|
||||
-- Clear navigation history
|
||||
function clearHistory()
|
||||
screen_history = {}
|
||||
history = {}
|
||||
end
|
||||
|
||||
-- Get history depth
|
||||
function getHistoryDepth()
|
||||
return #history
|
||||
end
|
||||
|
||||
print("Navigation system initialized")
|
||||
|
||||
Reference in New Issue
Block a user