Skip to content

fText: TableMaker: Examples: Clickable Tables

Damian Monogue edited this page Feb 7, 2021 · 1 revision

Clickable tables

Video

A short video showing the clickable cells. The code below is taken from this example.
YouTube Presentation

Setup

This next bit of code makes a MiniConsole to hold the table. We set autoClear and allowPopups so that we can add popup cells. Setting allowPopups automatically sets autoClear as well. It will also display the assembled table at the end.

-- make the container to hold things in
testCon = testCon or Geyser.MiniConsole:new({ x = 100, width = "69c", height = "9c"})
testCon:setFontSize(12)
testCon:resize("69c", "9c")

local TableMaker = require("MDK.ftext").TableMaker
testMaker3 = TableMaker:new({
  autoClear = true,
  allowPopups = true,
})
testMaker3:setAutoEchoConsole(testCon)
testMaker3:addColumn({name = "col1", width = 15, textColor = "<orange>"})
testMaker3:addColumn({name = "col2", width = 20, textColor = "<green>"})
testMaker3:addColumn({name = "col3", width = 30, textColor = "<purple>"})
testMaker3:addRow({"row 1 col 1", "row 1 col 2", "row 1 col 3"})
testMaker3:addRow({"row 2 col 1", "row 2 col 2", "row 2 col 3"})
testMaker3:addRow({"row 3 col 1", "row 3 col 2", "row 3 col 3"})
testMaker3:assemble()

Making clickable cells

To create a clickable cell, pass a table of parameters for either echoLink or echoPopup. It will detect which one to use based on whether the second parameter is a table or not. If it's a table then it assumes it is echoPopup, if it's a string it will use echoLink.

Therefore to create a clickable cell with tooltip, you could then do

testMaker3:setCell(1,1,{"Siddown", [[send("sit")]], "siddown!", false})

And if you wanted a right click menu, you might try

testMaker3:setCell(2,3,{"r2c3", {[[send("sit")]], [[send("stand")]]}, {"siddown!", "standup!"}})