Vertical alignment in a single-line TextEditor

Hi,

We use an automatically computed layout in a few places, which causes some text editors to be slightly taller than others. If we use the default indents for the editors this causes the text to be vertically off-centre, which looks weird.

Is there support for vertically aligning text in a single-line text editor? Right now we can use the indents but then we need to keep the indent, font size and editor size in sync. Maybe we can add some automatic mode for the vertical inset which keeps the text centred.

–
Roeland

No explicit support for changing the Y position, but could be something we can add… Maybe suggest a change that does what you need?

This is a feature request that dates back to 2009, I think it is time to implement this already (mentioned at least here, there and there again

I think the most general approach would also be the simplest one: provide a setJustification() method in analogy with the one in Label

2 Likes

Bumping this thread as I just hit this issue again…

1 Like

…and once again.
The lack becomes obvious especially when you use it beside a label where you can set a “layout” property to “centred right” etc.

or did I miss something? Am on Projucer 5.3.1…

1 Like

Time for another bump of this issue.

4 Likes

Is that the problem I’ve got here?

Are those place holders?

Placeholders don’t have any justification settings, they default to Justification::centredLeft, this is particularly egregious when the actual text justification is set to something different, I had to fix my fork of JUCE to allow for setting the empty text justification.

Looking at your image though it seems like something funky has happened with the vertical alignment regardless, but looking at the commits for TextEditor vertical alignment was tackled some time ago.

Mmmm, i’ve added some indent for now which seems to have fixed it enough. But I still can’t explain why it’s bad. Maybe I’ve broken something in LookAndFeel somewhere…

No. This lack of vertical alignment is due to the font’s baseline being the only factor accounted for to align vertically. The font’s descent (and ascent, probably) should be used to line it up properly on a single line.

The issue with adding this is that it might break rendering larger fonts, whose descent will surpass the bottom of the area it’s being drawn into. The other issue is that it will likely break existing text layouts. Having it as an opt-in option would be nice to get around that.

1 Like