-1

I'm having trouble to place a text element at a certain position. According to this issue, changing the font after adding a text element makes positioning a bit harder.

Seems to me like positioning would be correct if I could set the font before calling draw.text().

Can I do that? How?

Thanks in advance.

Update: I realized some weird stuff when I was creating a CodeSandBox to improve my question. Check it out:

Edit mz01p10xp9

I created a rectangle as big as the image, another rectangle 20px smaller on each edge and placed it inside the other, and a text element moved 20px down.

It should align with the inner rect. However, by inspecting it, it can be seen that it moved less than 20px down. The weird thing is that, when the x parameter of move is changed, it moves vertically and snaps to the correct position! However, when the preview is reloaded, the y position reverts to the wrong position.

None the less, it gave me an idea...

GuiRitter
  • 697
  • 1
  • 11
  • 20

1 Answers1

0

I've found a workaround, but I'm not certain if it's reliable.

draw.text('Hello, World!')
    .font({ family: 'font-print', size: 20 })
    .move(0, 0).dy(20).dx(60);

It doesn't work in the CodeSandBox I've shared, but it works in the actual project I'm working on. For now, at least.

GuiRitter
  • 697
  • 1
  • 11
  • 20