From 04812b5a154ff2702820c8f77213b0380ed1e027 Mon Sep 17 00:00:00 2001 From: David McMackins II Date: Thu, 24 May 2018 06:13:49 -0500 Subject: Add function for getting a generic component's font --- gui.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gui.lua b/gui.lua index 72ea6e8..99a90d2 100644 --- a/gui.lua +++ b/gui.lua @@ -125,6 +125,15 @@ function GuiComponent:__init(x, y, w, h, bg, fg) self.visible = false end +function GuiComponent:font() + if not self._lasth or self:h() ~= self._lasth then + self._font = love.graphics.newFont(self:h() * 0.8) + self._lasth = self:h() + end + + return self._font +end + function GuiComponent:draw() if not self.visible then return false @@ -223,12 +232,7 @@ function Button:draw() self:drawbox() - if not self._lasth or self:h() ~= self._lasth then - self._font = love.graphics.newFont(self:h() * 0.8) - self._lasth = self:h() - end - - love.graphics.setFont(self._font) + love.graphics.setFont(self:font()) love.graphics.printf(self.text, self:x(), (self:y() + (self:h() / 2)) - self:_halfheight(), self:w(), 'center') -- cgit v1.2.3