TextEditor and Label (mis)alignment

Is there any way to predict where a single-line TextEditor will draw its text? I have editable Labels with centered alignment, and I’ve always had to adjust the editor’s border and indents to make it match its Label. What’s really bad is that every couple of months this seems to change: I had working values that are useless now, and I have no idea how to deduce from the editor’s drawing code what’s the actual area where the text will be drawn and justified.

i haven’t tried this myself yet but i once scrolled through the docs and saw this method. it might be just what you need:

https://docs.juce.com/master/classFont.html#aadc076ad44f50a63dc7d8c5a3ca54899

cause if i understand it correctly it returns the width needed to draw some string with the font selected, so you’d just do that with the font of your labels and texteditors and maybe add some little absolute value to that for head room and it should give you a width that works for the individual text of a label

It’s not really a problem with the text itself, it’s a problem with what TextEditor does around it. Anyway I’ve kind of solved it for now. The horizontal alignment is ok, for centred it needs a compensation for the 2 pixels of rightEdgeSpace kept for the caret. There seems to be a mismatch between how TextEditor::Iterator and GlyphArrangement::justifyGlyphs deal with vertical alignment, they give different results for centred. So I’m using top alignment and a fixed top border.

I would also expect that the text aligns with the same bounds for both types.

Once the correspodence between Label and TextEditor is established, I believe it would be a good idea to add some unit test to JUCE to easily verify if future changes introduce regressions.

I’ve had the same problems and have had to tweak indents and borders and other things to get the text to not jump around when being edited. And it does change from time to time. I wish this was fixed.