Compare commits

..

No commits in common. "b6597650af15eff6d9730a97d6a84e1708b89b4d" and "027edc1a276831e695c64bfd500a3197de49ccaf" have entirely different histories.

2 changed files with 14 additions and 74 deletions

View File

@ -12,7 +12,7 @@ local function adjustPositions(elements, vertical, from)
newDims = newDims + getDim(elements[i]) newDims = newDims + getDim(elements[i])
end end
local setDim = vertical and function(e, dim) e:setY(dim) end or function(e, dim) e:setX(dim) end local setDim = vertical and function(e, dim) e:setPos(1, dim) end or function(e, dim) e:setPos(dim, 1) end
for i=from,#elements do for i=from,#elements do
setDim(elements[i], newDims) setDim(elements[i], newDims)
newDims = newDims + getDim(elements[i]) newDims = newDims + getDim(elements[i])

View File

@ -70,57 +70,15 @@ local function loadState(fname, node)
return controller return controller
end 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 = { local bgColors = {
colors.gray, colors.gray,
colors.black colors.black
} }
local entryBudget = hBudget - tabLine:getHeight()
local entryStart = 1 + (state.tab - 1) * (entryBudget)
local entryEnd = math.min(state.tab * entryBudget, #groups)
local entries = {} local entries = {}
for i=entryStart,entryEnd do for i=1,#groups do
local group = groups[i] local group = groups[i]
local text = group:getDisplayName() local text = group:getDisplayName()
local count = tostring(group:getItemCount()) local count = tostring(group:getItemCount())
@ -161,29 +119,17 @@ local function itemList(groups, wBudget, hBudget, savedState, onClick, setPage)
table.insert(entries, list) table.insert(entries, list)
end end
local tabLinePad = Padding:new{
top = hBudget - (entryEnd - entryStart) - 1,
element = tabLine
}
table.insert(entries, tabLinePad)
return List:new{ return List:new{
children = entries, children = entries,
vertical = true vertical = true
}, state }
end end
local function updatePageRender(state, pages) local function updatePageRender(state, pages)
if state.nextPage ~= nil then if state.nextPage ~= nil then
local changingPage = state.nextPage ~= state.currentPage
state.currentPage = state.nextPage state.currentPage = state.nextPage
state.nextPage = nil state.nextPage = nil
if changingPage then
state.pageState = nil
end
state._pageRender = pages[state.currentPage](state) state._pageRender = pages[state.currentPage](state)
end end
end end
@ -217,20 +163,15 @@ local PAGES = {
table.sort(found, function(a, b) return a:getItemCount() > b:getItemCount() end) table.sort(found, function(a, b) return a:getItemCount() > b:getItemCount() end)
local listResult, pageState = itemList( local subset = {}
found, for i=1,math.min(13, #found) do
state.width, table.insert(subset, found[i])
state.height, end
state.pageState,
function(element, x, y, source, group) local listResult = itemList(subset, state.width, function(element, x, y, source, group)
print("Clicked: "..group:getDisplayName()) print("Clicked: "..group:getDisplayName())
return true return true
end, end)
function(page)
state.nextPage = page or state.currentPage
end
)
state.pageState = pageState
listResult:setParent(state.monitor) listResult:setParent(state.monitor)
return function() return function()
@ -260,8 +201,7 @@ local CONTROLLER_STATE = {
height = height, height = height,
monitor = monitor, monitor = monitor,
nextPage = "MAIN", nextPage = "MAIN",
exit = false, exit = false
pageState = {}
} }
os.queueEvent("dummy_event") os.queueEvent("dummy_event")