2023-08-02 03:45 AM - edited 2023-08-02 03:47 AM
The position of the text containing only a dot on a Button with Label is wrong. Left picture is a screenshot from TouchGFX Designer, where the dot is well aligned. To the right a framebuffer-screenshot of the actual application running on target hardware. The dot is vertically aligned to the middle of a typical character height.
Sometimes already the Designer shows the wrong position of the dot. Not sure when this happens.
Versions are up-to-date (CubeMX, CubeIDE and TouchGFX)
Solved! Go to Solution.
2023-08-03 12:14 AM - edited 2023-08-03 12:23 AM
Hello
ButtonWtihLabel centers the text in vertical direrction based on the actual text height, as you noticed. Maybe use flexButton where you can set the text Y position ?
Other option is to modify file "/Middlewares/ST/touchgfx/framework/include/touchgfx/widgets/ButtonWithLabel.hpp" and set alternative calculation in function void updateTextPosition() line:
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s);
to for example:
if(s[0]=='.')
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s)-12;
else
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s);
(just idea,your implementation can be smarter :grinning_face_with_sweat:)
Br J.T
2023-08-03 12:14 AM - edited 2023-08-03 12:23 AM
Hello
ButtonWtihLabel centers the text in vertical direrction based on the actual text height, as you noticed. Maybe use flexButton where you can set the text Y position ?
Other option is to modify file "/Middlewares/ST/touchgfx/framework/include/touchgfx/widgets/ButtonWithLabel.hpp" and set alternative calculation in function void updateTextPosition() line:
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s);
to for example:
if(s[0]=='.')
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s)-12;
else
textHeightIncludingSpacing = f->getHeight() * f->getNumberOfLines(s) + f->getSpacingAbove(s);
(just idea,your implementation can be smarter :grinning_face_with_sweat:)
Br J.T
2023-08-03 02:14 AM
HI @JTP1, thanks for the hint. Undocumented feature of ButtonWithLabel... :face_with_rolling_eyes:
I changed the type of this button to a FlexButton and now the dot is shown at the correct position.