diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-04-01 14:48:59 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-04-01 16:12:55 -0700 |
commit | 4ab901c92e11f47828bc7f5f16d8d2250812d53f (patch) | |
tree | 288dcf758b377c9b8586a9fc4bd7706d3a91e1f4 /app.lua | |
parent | fd2e5acb464c439325455acb63683d4fa316497c (diff) | |
download | lines.love-4ab901c92e11f47828bc7f5f16d8d2250812d53f.tar.gz |
get rid of to_text
I've been misunderstanding what Text objects are. They can render a lot of text with a given line height, word wrap, colors in various places. And I've been creating one for every word :facepalm: Unwinding this will take some time. This is just a first baby step for ad hoc text objects. Turns out I don't need to convert to Text to get something's rendered width, just the Font can do that. Thanks to the LÖVE Discord for educating me: https://discord.com/channels/329400828920070144/330089431379869708/1091535487333826580
Diffstat (limited to 'app.lua')
-rw-r--r-- | app.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/app.lua b/app.lua index 59dff31..816c9af 100644 --- a/app.lua +++ b/app.lua @@ -219,6 +219,9 @@ function App.newText(font, s) end function App.width(text) + if type(text) == 'string' then + return love.graphics.getFont():getWidth(text) + end return text.text:getWidth() end @@ -425,7 +428,12 @@ function App.disable_tests() App.screen.print = love.graphics.print App.newText = love.graphics.newText App.screen.draw = love.graphics.draw - App.width = function(text) return text:getWidth() end + App.width = function(text) + if type(text) == 'string' then + return love.graphics.getFont():getWidth(text) + end + return text:getWidth() + end if Current_app == nil or Current_app == 'run' then App.open_for_reading = function(filename) return io.open(filename, 'r') end App.open_for_writing = function(filename) return io.open(filename, 'w') end |