Added :onSelect to Tables

This commit is contained in:
Robert Jelic
2025-06-20 21:30:18 +02:00
parent a9458ea77d
commit 1b467c4d4a
2 changed files with 9 additions and 2 deletions

View File

@@ -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

View File

@@ -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