How to calculate text pixel width to position multiple drawtext?

Forums ProRealTime English forum ProBuilder support How to calculate text pixel width to position multiple drawtext?

Viewing 2 posts - 1 through 2 (of 2 total)
  • #253830

    Hi,

    let’s say I want to draw two text labels at the far right of the screen. In some situations, they may overlap. To avoid this, I would like to draw the first label (‘text1’) at a given x-position, and then draw the second label (‘text2’) at x + the pixel width of ‘text1’.

    How can I calculate the pixel length (width) of a text string so that I can use this value with the drawtext function (if this is possible)?

    #253853

    Hi,
    There is currently no native function in ProBuilder to calculate the pixel width or length of a text string dynamically. The rendering metrics (how much space a font takes up on the screen) are not accessible via the code.
    However, since you are drawing labels at the far right of the screen, the best way to prevent overlapping without knowing the exact text width is to use the ANCHOR instruction with XSHIFT and YSHIFT (which uses pixels instead of bar index/price).

    2 users thanked author for this post.
Viewing 2 posts - 1 through 2 (of 2 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login