summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2018-05-24 06:13:49 -0500
committerDavid McMackins II <contact@mcmackins.org>2018-05-24 06:13:49 -0500
commit04812b5a154ff2702820c8f77213b0380ed1e027 (patch)
tree994f8e1484985a537caf951ef40fdd964b26c257
parent1ed25a355bc2c0c168943eea1a6a1332cc710209 (diff)
Add function for getting a generic component's font
-rw-r--r--gui.lua16
1 files 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')