A little help on text alignment

In lua, it seems I can't get an alignment right. I have a simple compass showing a direction (N, E, W or S). The W is wider than the other letters and ends up not in the center. I tried a few options mentioned in the doc but can't seem to make them work the way I want...

Here are some screenshots
image
image
image

I would like to have the letters always in the center of the surrounding circle.

Here is a simplified version of the code:

local pd <const> = playdate
local gfx <const> = pd.graphics

class("Compass").extends(gfx.sprite)

function Compass:init()
    Compass.super.init(self)

    self:moveTo(390, 182)
    self:add()
end

function Compass:updateDisplay(strDirection)
    local imgCompass = gfx.image.new(20, 20)
    
    gfx.pushContext(imgCompass)
        gfx.drawText(strDirection, 0, 0)
    gfx.popContext()

    self:setImage(imgCompass)
end

Any help will be appreciated! Thank you

For those interesed, and based on our replies on the forum, I found that using the following gave much better results. Please let me know if there is a better way of doing this:

gfx.drawTextAligned(strDirection, self.width /2, 0, kTextAlignment.center)

I am leaving the question and answer for the anyone passing by!

1 Like