Possible text misplacement in TextEditor?


#1

juce_TextEditor.cpp:

if (isMultiLine()) { g.drawText (textToShowWhenEmpty, 0, 0, getWidth(), getHeight(), Justification::centred, true); } else { g.drawText (textToShowWhenEmpty, leftIndent, topIndent, viewport->getWidth() - leftIndent, viewport->getHeight() - topIndent, [b]Justification::centredLeft[/b], true); }

I noticed the textToShowWhenEmpty appears slightly lower than the normal text.
Setting the bold line to Justification::topLeft fixed it.


#2

Well… I think my intention was that the text would go in the centre of the component. E.g. if it’s a multi-line component, the message would be in the middle rather than at the top.


#3

When you’re drawing the normal text you use setOrigin(leftIndent, topIndent) - for single lined text editors this looks funny in the best case and cut out in the worst one.


#4

Actually, looking at that snippet again, I think that what I probably meant to write was this:

g.drawText (textToShowWhenEmpty, leftIndent, 0, viewport->getWidth() - leftIndent, getHeight(), Justification::centredLeft, true);

…does that sort it out? I don’t think the justification setting was wrong, but it looks like I got the bounding box slightly off…


#5

[quote=“jules”]Actually, looking at that snippet again, I think that what I probably meant to write was this:

g.drawText (textToShowWhenEmpty, leftIndent, 0, viewport->getWidth() - leftIndent, getHeight(), Justification::centredLeft, true);

…does that sort it out? I don’t think the justification setting was wrong, but it looks like I got the bounding box slightly off…[/quote]

Yup, seems like it hit the spot, thanks…