An easier way to draw right-aligned or centered text

Issue #1326 new
hahawoo
created an issue

I think it would be nice if there was an easier way to draw unwrapped right-aligned or centered text from a specified point.

To draw right-aligned text for example one might currently do something like this:

love.graphics.printf(s, x - 10000, y, 10000, 'right')  -- 10000 selected to be large enough not to wrap text

or this:

local offset = love.graphics.getFont():getWidth(s)
love.graphics.print(s, x - offset, y)

Comments (3)

  1. hahawoo reporter

    Some possibilities...

    love.graphics.print(text, x, y, align [default is "left"], r, sx, sy, ox, oy, kx, ky)
    

    The align argument has a default value of "left".

    love.graphics.print(text, x, y, align [optional], r, sx, sy, ox, oy, kx, ky)
    

    The align argument is optional and uses "left" if left out (like how love.graphics.arc's arc type argument is optional and uses "pie" if left out).

    I like that one because it functions the same as love.graphics.print if the align argument is left out.

    love.graphics.printf(text, x, y, align, wraplimit, r, sx, sy, ox, oy, kx, ky)
    

    Like normal love.graphics.printf, except if the wrap limit is 0 (or -1 maybe) then the text aligns from the x/y point rather than within the wrap limit.

    love.graphics.printf(text, x, y, wraplimit [optional], align, r, sx, sy, ox, oy, kx, ky)
    

    Like normal love.graphics.printf, except the wraplimit and align arguments are swapped and the wrap limit is optional. If the wrap limit is left out then the text aligns from the x/y point rather than within the wrap limit. If 3 arguments are given it functions like love.graphics.print.

  2. hahawoo reporter

    Interesting! I'd be curious to know your thoughts on that.

    I guess I think it's nice to be able to draw text and know it's not going to wrap and overlap something else.

  3. Log in to comment