local window = require('window') local font = love.graphics.getFont() local m = {} function m.new(text, callback, x, y, width, height) local tw = font:getWidth(text) local th = font:getHeight(text) local btn = { text = text, x = x, y = y, width = width, height = height, tx = (width - tw) / 2, ty = (height - th) / 2 } btn.mousepressed = window.mousepressed(function(self, x, y, button) callback(x, y, button) end) btn.draw = window.draw(function(self) love.graphics.printf(self.text, self.tx, self.ty, self.width) window.draw_border(self.width, self.height) end) return btn end return m