cancel
Showing results for 
Search instead for 
Did you mean: 

TextArea: how to align text vertically

ferro
Senior II

Hi,

TextArea allows to align text in horizontal direction. How to achieve the same alignment in vertical direction ?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Osman SOYKURT
ST Employee

Hello,

This subject was already treated here. This feature is not possible in TouchGFX Designer yet, but thanks for suggesting again, we could consider to add it in a future release if it's a big help for users.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

View solution in original post

9 REPLIES 9
Romain DIELEMAN
ST Employee

Hi,

Could you explain a bit more what you are trying to achieve ? I suppose you are trying to write something like in kanji/hanzi vertically and want to make sure they are aligned ? Or is it something else ?

/Romain

Hi @Romain DIELEMAN​ 

Sorry for slow reply.

"Could you explain a bit more what you are trying to achieve ?"

Yes, certainly.

When Text Area changes X dimesion text is aligned in the center automatically - horizontal alignment

0693W00000aHiuBQAS.png 

However, when Y dimension is changed text stays always at the top.

So I wonder how to achieve center and bottom text alignment - this is what I mean by "vertical alignment".

0693W00000aHiukQAC.png 

Thanks

awiernie
Senior II

I also wanted to use vertical allign. I have an error message which can be up to 3 lines large. If it is only 1 line large, it should be displayed at a lower position. As it seems not to be possible to make vertical align, I changed the vertical position by querying the size using calculateTextHeight().

"I changed the vertical position by querying the size using calculateTextHeight()"

Thanks for the hint @awiernie​ . It seems that getTextHeight () returns the same value ?

I experimented with setBaselineY () and realized that setBaselineY () is not changing text's Y position within TextArea::Drawable area but rather movig the whole Drawable.

So, with the following line, the text is not placed in the vertical center of the TextArea::Drawable but rather the whole TextArea is moved in coordinates of its parent.

TextArea::setBaselineY ( TextArea::getHeight () / 2 );

The difference is, that getTextHight() has no argument and it calculates the hight of the current text in the widget. With calculateTextHeight you give a text string and you get the height which would be needed to display it (taking into account line wraps). So you can decide in advance without setting the text.

"I changed the vertical position by querying the size using calculateTextHeight()."

I thought about a variation to your approach:

TextArea::resizeHeightToCurrentText ();
TextArea::centerY ();

Osman SOYKURT
ST Employee

Hello,

This subject was already treated here. This feature is not possible in TouchGFX Designer yet, but thanks for suggesting again, we could consider to add it in a future release if it's a big help for users.

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

Hi @Osman SOYKURT​ ,

"we could consider to add it in a future release if it's a big help for users"

Please do, thank you. Big help. I think it is a common feature (Qt::QLabel, emWin::GUI_SetTextAlign).

However, I found this very interesting comment from Martin KJELDSEN on why it was not implemented:

0693W00000aIvzaQAC.png 

And thank you for the link ! Here is collection of related posts I found:

How to make a Text to be align centered vertically ?

Text Area and alignment

It is unfortunate that they are not listed when searching the forum (with 'align' or 'alignment'):

0693W00000aIw4aQAC.png