From a603847d18ac5279e5d190ac2eebdf87297590d4 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 29 May 2022 16:37:31 -0700 Subject: [PATCH] go through App in a couple more places --- app.lua | 8 ++++---- drawing.lua | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app.lua b/app.lua index 3ed3aa8..56cd244 100644 --- a/app.lua +++ b/app.lua @@ -163,6 +163,10 @@ function App.newText(font, s) return {type='text', data=s, text=love.graphics.newText(font, s)} end +function App.width(text) + return text.text:getWidth() +end + function App.screen.draw(obj, x,y) if type(obj) == 'userdata' then -- ignore most things as graphics the test harness can't handle @@ -192,10 +196,6 @@ function App.run_after_mousepress(x,y, button) App.draw() end -function App.width(text) - return text.text:getWidth() -end - function App.screen.check(y, expected_contents, msg) --? print('checking for "'..expected_contents..'" at y '..tostring(y)) local screen_row = 'y'..tostring(y) diff --git a/drawing.lua b/drawing.lua index 5575904..677cab3 100644 --- a/drawing.lua +++ b/drawing.lua @@ -56,11 +56,11 @@ function Drawing.draw(line) local name_text -- TODO: avoid computing name width on every repaint if p.name == '' then - name_text = love.graphics.newText(love.graphics.getFont(), 'm') -- 1em + name_text = App.newText(love.graphics.getFont(), 'm') -- 1em else - name_text = love.graphics.newText(love.graphics.getFont(), p.name) + name_text = App.newText(love.graphics.getFont(), p.name) end - love.graphics.rectangle('fill', x,y, math.floor(name_text:getWidth()*Zoom), math.floor(15*Zoom)) + love.graphics.rectangle('fill', x,y, math.floor(App.width(name_text)*Zoom), math.floor(15*Zoom)) end end end