2019-06-03 02:50 AM
Assuming the height of the drawable object is H (getHeight()), and the height of text is TH (getTextHeight()), how to figure out the correct y value of the text object ??
I tried (getHeight() - text.getTextHeight() - text.getTypedText().getFont->getSpacingAbove()) / 2 and (getHeight() - text.getTextHeight() ) / 2, neither of them is right.
2019-06-03 03:59 AM
Hi,
The calculation seems right to me. Can you show me, visually, what's wrong with your calculation?
/Martin
2019-06-03 04:01 AM
Can you debug and verify that the numbers are correct? (text height and spacing above)
/Martin
2019-06-03 04:30 AM
It is obviously that, the up padding is different from down padding,
and I figure the padding through (getHeight() - text.getTextHeight() - fontSpaceAbove) / 2
2019-06-03 04:41 AM
The value is wrong !!! value of the getHeight() is 44, while the textHeight() is 34 and the fontspaceabove is 5, thus, the padding is (44-34-5) / 2 = 2, it seems wrong!!!
2019-06-03 11:45 PM
Might be more effecient if you simply send me your project, if that's possible.
/Martin
2019-06-19 08:04 PM
It was fixed, the true height of the text is text.getTypedText().getFont->getSpacingAbove() + text.getTypedText().getFont()->getMaxTextHeight()
2019-07-29 08:52 AM
Will this work if the text in question is inside a textArea? I would like my text to center it vertically inside a textArea and there is no way to do this in the Designer (a horizontal centering is provided, I suggest adding vertial alignment capability to the Designer in future updates).
I am having issues gaining access the typedText of the textArea because it is "protected".
2019-08-05 06:08 AM
Hi @scottSD,
The text is always inside a TextArea. The original posters issue was centering the whole thing properly, vertically because getTextHeight() does not, in all cases, give you the height of the textarea itself.
2019-08-05 06:21 AM
Martin,
Thanks for the reply.
Is there away to minimize the height of the textArea so that it is very close to the height
of the actual text? When I turn Auto-size off and reduce the height of the textArea, it does reduce it, but brings the bottom edge up to the text and not the top edge. Reducing the height some more clips the bottom of the text and it is no longer vertically centered (all of this done using the Designer):
The reason I would like to do this is to reduce the invalidated rectangle as it is next to other items.
I assume this is because of a top spacing requirement in the font?