Added :onSelect to Tables
This commit is contained in:
@@ -159,6 +159,7 @@ function BasaltProgram:resume(event, ...)
|
||||
if errorCallback then
|
||||
local trace = debug.traceback(self.coroutine, result)
|
||||
trace = trace == nil and "" or trace
|
||||
result = result or "Unknown error"
|
||||
local _result = errorCallback(self.program, result, trace:gsub(result, ""))
|
||||
if(_result==false)then
|
||||
self.filter = nil
|
||||
|
||||
@@ -144,13 +144,19 @@ function Table:mouse_click(button, x, y)
|
||||
if relY > 1 then
|
||||
local rowIndex = relY - 2 + self.get("scrollOffset")
|
||||
if rowIndex >= 0 and rowIndex < #self.get("data") then
|
||||
self.set("selectedRow", rowIndex + 1)
|
||||
local newIndex = rowIndex + 1
|
||||
self.set("selectedRow", newIndex)
|
||||
self:fireEvent("select", newIndex, self.get("data")[newIndex])
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function Table:onSelect(callback)
|
||||
self:registerCallback("select", callback)
|
||||
return self
|
||||
end
|
||||
|
||||
--- @shortDescription Handles scrolling through the table data
|
||||
--- @param direction number The scroll direction (-1 up, 1 down)
|
||||
--- @param x number The x position of the scroll
|
||||
|
||||
Reference in New Issue
Block a user