Page 1 of 1
Dimentions of text rendered with Printf
Posted: Tue Nov 08, 2022 9:14 pm
by JayKyburzNew
Hi Folks,
I vaguely remember reading somewhere that it was possible to work out the dimensions of text that had been rendered by Printf so I could draw a box around it.
I quick scan of the docs and I didn't see anything.
Anybody know how?
Re: Dimentions of text rendered with Printf
Posted: Tue Nov 08, 2022 11:12 pm
by Koxinga
Not sure if that is what you are asking for but I use Font:getWidth() and Font:getHeight()
https://love2d.org/wiki/Font:getWidth
(you have to define a font first or use
https://love2d.org/wiki/love.graphics.getFont)
It's ok for text that doesn't wrap, but if it's displayed on multiple lines I suppose these won't match. I never had to deal with that case so I can't tell really.
Re: Dimentions of text rendered with Printf
Posted: Tue Nov 08, 2022 11:52 pm
by slime
You can use
Font:getWrap to get the width and number of lines, and then multiply the number of lines with Font:getHeight to get the total height.
Re: Dimentions of text rendered with Printf
Posted: Wed Nov 09, 2022 7:30 am
by JayKyburzNew
Thanks for the tips folks.