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