local gui
local font
local events = import("events", "local")
local function render(layer)
    if layer ~= math.huge then return end
    local x = font:area(("%.0f fps"):format(gui.timer.framesPerSecond), 20)
    font:draw(("%.0f fps"):format(gui.timer.framesPerSecond), gui.width - x - 2, 2, 0xffffffff, 20)
end
local active = false
return function(toggle)
    if toggle then
        if not active then
            gui = gui or require("gui")
            font = font or gui.make_font("Verdana")
            events.render += render
            active = true
        end
    else
        if active then
            events.render -= render
            active = false
        end
    end
end