JUCE drawing text in wrong spot?

I’m doing this:

        auto r6 = r.removeFromLeft (w).reduced (3, 0);
        g.setColour (Colours::pink.withAlpha (0.3f));
        g.fillRect (r6);
        g.setColour (Colours::black);
        g.drawFittedText (assignment->feedback ? "true" : "false", r6, Justification::centredLeft, 1);

Shouldn’t the text appear inside the pink rectangle? But I get this:

image

In one case the text isn’t in the pink rectangle. Any idea what could be going wrong? My juce version is from Dec 13th, 2019 – any bugs like this been fixed since then?

Totally sure this is not your case BUT in my noob world - and very often almost always - when stuff in wrong places meets rectangle.removefromXYZ it’s me forgetting that the original rectagle is affected by the call so if I wanna keep an untouched reference I am better of creating first a copy of the original and then do the removefromXYZ from it.

There was a text-positioning bug fixed very recently: Text Alignment differences between JUCE 5.4.4 and 5.4.5 - #7 by t0m

This regards horizontal alignment and doesn’t seem to be related to the issue you have linked to. EDIT: an actual change has been made to the text rendering alignment so that may actually change something in your case too

Try making r6 const auto so that you’re sure it isn’t being changed, then perhaps use a different background color temporarily for it only, to make sure r6 actually covers the area that you expect it to

That’s a link to a specific post in the other thread that should address the horizontal misalignment.

1 Like

Ah my bad, I didn’t acknowledge that, I thought it only referenced the main subject of that topic. Apologies! (and amended my previous post)

Looks like that was the issue, updated juce and now it’s working fine.

2 Likes