grid sort event

This commit is contained in:
kepler155c@gmail.com 2018-11-30 04:53:59 -05:00
parent 880a81f655
commit beae4e6eaf
1 changed files with 18 additions and 10 deletions

View File

@ -1266,6 +1266,7 @@ UI.Grid.defaults = {
backgroundSelectedColor = colors.gray, backgroundSelectedColor = colors.gray,
headerBackgroundColor = colors.cyan, headerBackgroundColor = colors.cyan,
headerTextColor = colors.white, headerTextColor = colors.white,
headerSortColor = colors.yellow,
unfocusedTextSelectedColor = colors.white, unfocusedTextSelectedColor = colors.white,
unfocusedBackgroundSelectedColor = colors.gray, unfocusedBackgroundSelectedColor = colors.gray,
focusIndicator = '>', focusIndicator = '>',
@ -1482,7 +1483,7 @@ function UI.Grid:update()
end end
function UI.Grid:drawHeadings() function UI.Grid:drawHeadings()
local sb = UI.StringBuffer(self.width) local x = 1
for _,col in ipairs(self.columns) do for _,col in ipairs(self.columns) do
local ind = ' ' local ind = ' '
if col.key == self.sortColumn then if col.key == self.sortColumn then
@ -1492,9 +1493,13 @@ function UI.Grid:drawHeadings()
ind = self.sortIndicator ind = self.sortIndicator
end end
end end
sb:insert(ind .. col.heading, col.cw + 1) self:write(x,
1,
Util.widthify(ind .. col.heading, col.cw + 1),
self.headerBackgroundColor,
col.key == self.sortColumn and self.headerSortColor or self.headerTextColor)
x = x + col.cw + 1
end end
self:write(1, 1, sb:get(), self.headerBackgroundColor, self.headerTextColor)
end end
function UI.Grid:sortCompare(a, b) function UI.Grid:sortCompare(a, b)
@ -1636,13 +1641,12 @@ function UI.Grid:eventHandler(event)
local col = 2 local col = 2
for _,c in ipairs(self.columns) do for _,c in ipairs(self.columns) do
if event.x < col + c.cw then if event.x < col + c.cw then
if self.sortColumn == c.key then self:emit({
self:setInverseSort(not self.inverseSort) type = 'grid_sort',
else sortColumn = c.key,
self.sortColumn = c.key inverseSort = self.sortColumn == c.key and not self.inverseSort,
self:setInverseSort(false) element = self,
end })
self:draw()
break break
end end
col = col + c.cw + 1 col = col + c.cw + 1
@ -1665,6 +1669,10 @@ function UI.Grid:eventHandler(event)
end end
return false return false
elseif event.type == 'grid_sort' then
self.sortColumn = event.sortColumn
self:setInverseSort(event.inverseSort)
self:draw()
elseif event.type == 'scroll_down' then elseif event.type == 'scroll_down' then
self:setIndex(self.index + 1) self:setIndex(self.index + 1)
elseif event.type == 'scroll_up' then elseif event.type == 'scroll_up' then