Implement basic page-switching
This commit is contained in:
parent
ffde1b2978
commit
df93ccf801
@ -210,26 +210,30 @@ local function updatePageRender(state, pages)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function renderDefault(state, rootElement)
|
local function renderDefault(state, rootElement)
|
||||||
local event = {os.pullEvent()}
|
return function()
|
||||||
local handled = rootElement:handleEvent(event)
|
local event = {os.pullEvent()}
|
||||||
if not handled and event[1] == "monitor_resize" then
|
local handled = rootElement:handleEvent(event)
|
||||||
local width, height = state.monitor.getSize()
|
if not handled and event[1] == "monitor_resize" then
|
||||||
if state.width ~= width or state.height ~= height then
|
local width, height = state.monitor.getSize()
|
||||||
state.width = width
|
if state.width ~= width or state.height ~= height then
|
||||||
state.height = height
|
state.width = width
|
||||||
|
state.height = height
|
||||||
|
|
||||||
-- Trigger re-render
|
-- Trigger re-render
|
||||||
rootElement:setDirty(true)
|
rootElement:setDirty(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if not handled and not Event.isClickEvent(event) then
|
if not handled and not Event.isClickEvent(event) then
|
||||||
os.queueEvent(table.unpack(event))
|
os.queueEvent(table.unpack(event))
|
||||||
end
|
end
|
||||||
|
|
||||||
rootElement:draw()
|
rootElement:draw()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function NOOP() end
|
||||||
|
|
||||||
local PAGES = {
|
local PAGES = {
|
||||||
MAIN = function(state)
|
MAIN = function(state)
|
||||||
local pageState = state:currentPageState({})
|
local pageState = state:currentPageState({})
|
||||||
@ -248,11 +252,15 @@ local PAGES = {
|
|||||||
state.height,
|
state.height,
|
||||||
pageState.listState,
|
pageState.listState,
|
||||||
function(element, x, y, source, group)
|
function(element, x, y, source, group)
|
||||||
print("Clicked: "..group:getSimpleName())
|
state:setPage("GROUP_DETAIL", group)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
function(page)
|
function(page)
|
||||||
state.nextPage = page or state.currentPage
|
if page == nil then
|
||||||
|
state:reloadPage()
|
||||||
|
else
|
||||||
|
state:setPage(page)
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
print("Importing...")
|
print("Importing...")
|
||||||
@ -267,19 +275,30 @@ local PAGES = {
|
|||||||
end)
|
end)
|
||||||
-- Force reload stacks
|
-- Force reload stacks
|
||||||
state:currentPageState({}).stacks = nil
|
state:currentPageState({}).stacks = nil
|
||||||
state.nextPage = state.currentPage
|
state:reloadPage()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
pageState.listState = listState
|
pageState.listState = listState
|
||||||
listResult:setParent(state.monitor)
|
listResult:setParent(state.monitor)
|
||||||
|
|
||||||
return function()
|
return renderDefault(state, listResult)
|
||||||
renderDefault(state, listResult)
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
GROUP_DETAIL = function(state, newPage)
|
GROUP_DETAIL = function(state, newPage)
|
||||||
|
local group = state:getExtra()
|
||||||
|
if group == nil then
|
||||||
|
state:setPage("MAIN")
|
||||||
|
return NOOP
|
||||||
|
end
|
||||||
|
local hello = Text:new{
|
||||||
|
text = "Detail: "..group:getSimpleName(),
|
||||||
|
parent = state.monitor,
|
||||||
|
onClick = function(e, x, y, s)
|
||||||
|
state:setPage("MAIN")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderDefault(state, hello)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
REQUEST = function(state, newPage)
|
REQUEST = function(state, newPage)
|
||||||
@ -317,6 +336,19 @@ function CONTROLLER_STATE:currentPageState(default)
|
|||||||
return self.pageState[self.currentPage]
|
return self.pageState[self.currentPage]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CONTROLLER_STATE:setPage(page, extra)
|
||||||
|
self.nextPage = page
|
||||||
|
self.extra = extra
|
||||||
|
end
|
||||||
|
|
||||||
|
function CONTROLLER_STATE:getExtra()
|
||||||
|
return self.extra
|
||||||
|
end
|
||||||
|
|
||||||
|
function CONTROLLER_STATE:reloadPage()
|
||||||
|
self.nextPage = self.currentPage
|
||||||
|
end
|
||||||
|
|
||||||
while not CONTROLLER_STATE.exit do
|
while not CONTROLLER_STATE.exit do
|
||||||
updatePageRender(CONTROLLER_STATE, PAGES)
|
updatePageRender(CONTROLLER_STATE, PAGES)
|
||||||
CONTROLLER_STATE._pageRender()
|
CONTROLLER_STATE._pageRender()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user