Add tab controls
This commit is contained in:
parent
ebf49b1df7
commit
b6597650af
@ -70,15 +70,57 @@ local function loadState(fname, node)
|
||||
return controller
|
||||
end
|
||||
|
||||
local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage)
|
||||
local state = savedState or {}
|
||||
state.tab = state.tab or 1
|
||||
|
||||
local pages = math.ceil(#groups / (hBudget - 1))
|
||||
|
||||
-- Tab controls
|
||||
local btnPrev = Text:new{
|
||||
text = " < ",
|
||||
bgColor = state.tab == 1 and colors.black or colors.gray,
|
||||
fgColor = state.tab == 1 and colors.red or colors.white,
|
||||
x = 1,
|
||||
onClick = function(e, x, y, s)
|
||||
if state.tab > 1 then
|
||||
state.tab = state.tab - 1
|
||||
setPage(nil)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local btnNext = Text:new{
|
||||
text = " > ",
|
||||
bgColor = state.tab == pages and colors.black or colors.gray,
|
||||
fgColor = state.tab == pages and colors.red or colors.white,
|
||||
x = wBudget - 3,
|
||||
onClick = function(e, x, y, s)
|
||||
if state.tab < pages then
|
||||
state.tab = state.tab + 1
|
||||
setPage(nil)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
local tabLine = List:new{
|
||||
children = {
|
||||
btnPrev,
|
||||
btnNext
|
||||
},
|
||||
vertical = false
|
||||
}
|
||||
|
||||
local function itemList(groups, wBudget, onClick)
|
||||
local bgColors = {
|
||||
colors.gray,
|
||||
colors.black
|
||||
}
|
||||
local entryBudget = hBudget - tabLine:getHeight()
|
||||
local entryStart = 1 + (state.tab - 1) * (entryBudget)
|
||||
local entryEnd = math.min(state.tab * entryBudget, #groups)
|
||||
local entries = {}
|
||||
|
||||
for i=1,#groups do
|
||||
for i=entryStart,entryEnd do
|
||||
local group = groups[i]
|
||||
local text = group:getDisplayName()
|
||||
local count = tostring(group:getItemCount())
|
||||
@ -119,17 +161,29 @@ local function itemList(groups, wBudget, onClick)
|
||||
table.insert(entries, list)
|
||||
end
|
||||
|
||||
local tabLinePad = Padding:new{
|
||||
top = hBudget - (entryEnd - entryStart) - 1,
|
||||
element = tabLine
|
||||
}
|
||||
|
||||
table.insert(entries, tabLinePad)
|
||||
|
||||
return List:new{
|
||||
children = entries,
|
||||
vertical = true
|
||||
}
|
||||
}, state
|
||||
end
|
||||
|
||||
local function updatePageRender(state, pages)
|
||||
if state.nextPage ~= nil then
|
||||
local changingPage = state.nextPage ~= state.currentPage
|
||||
state.currentPage = state.nextPage
|
||||
state.nextPage = nil
|
||||
|
||||
if changingPage then
|
||||
state.pageState = nil
|
||||
end
|
||||
|
||||
state._pageRender = pages[state.currentPage](state)
|
||||
end
|
||||
end
|
||||
@ -163,15 +217,20 @@ local PAGES = {
|
||||
|
||||
table.sort(found, function(a, b) return a:getItemCount() > b:getItemCount() end)
|
||||
|
||||
local subset = {}
|
||||
for i=1,math.min(13, #found) do
|
||||
table.insert(subset, found[i])
|
||||
end
|
||||
|
||||
local listResult = itemList(subset, state.width, function(element, x, y, source, group)
|
||||
print("Clicked: "..group:getDisplayName())
|
||||
return true
|
||||
end)
|
||||
local listResult, pageState = itemList(
|
||||
found,
|
||||
state.width,
|
||||
state.height,
|
||||
state.pageState,
|
||||
function(element, x, y, source, group)
|
||||
print("Clicked: "..group:getDisplayName())
|
||||
return true
|
||||
end,
|
||||
function(page)
|
||||
state.nextPage = page or state.currentPage
|
||||
end
|
||||
)
|
||||
state.pageState = pageState
|
||||
listResult:setParent(state.monitor)
|
||||
|
||||
return function()
|
||||
@ -201,7 +260,8 @@ local CONTROLLER_STATE = {
|
||||
height = height,
|
||||
monitor = monitor,
|
||||
nextPage = "MAIN",
|
||||
exit = false
|
||||
exit = false,
|
||||
pageState = {}
|
||||
}
|
||||
|
||||
os.queueEvent("dummy_event")
|
||||
|
Loading…
x
Reference in New Issue
Block a user