Closed RodrigoDornelles closed 3 months ago
@rafael2k tem esse exemplo também, é simples mas bem útil para entender mais sobre o ginga.
Eh verdade, eh util mesmo!
local canvas = canvas
local event = event
local pairs = pairs
local table = table
local tostring = tostring
local w, h = canvas:attrSize ()
local console = {}
local count = 0
_ENV = nil
local function dump(tbl)
local result = {}
for k, v in pairs(tbl) do
table.insert(result, k .. "=" .. tostring(v))
end
return table.concat(result, ", ")
end
local function event_loop(evt)
count = count + 1
table.insert(console, {text=dump(evt), item=count})
if #console > (h/17) then
table.remove(console, 1)
end
end
local function fixed_loop()
canvas:attrColor (0, 0, 0, 0)
canvas:clear()
canvas:attrColor('white')
canvas:attrFont('sans', 12)
for i=1, #console do
local x, y = canvas:measureText(console[i].item)
canvas:drawText(w - x - 8, 16 * i, console[i].item)
canvas:drawText(8, 16 * i, console[i].text)
end
canvas:flush()
event.timer(500, fixed_loop)
end
event.register(event_loop)
event.timer(500, fixed_loop)
a basic utility for testing events such as pressing remote control buttons.