lcd.sizeText() is not accurate
Is there an existing issue for this problem?
- [X] I have searched the existing issues
What part of EdgeTX is the focus of this bug?
Transmitter firmware
Current Behavior
background:
I am trying to write a widget (re-write the BattAnalog), in a way that it will be fully adaptive to different widget zone This way we could use it also in different TX resolutions placing the text while trying to maximize the usage of the widget real estate is a hard task, I am using the lcd.sizeText(), but it must be accurate to achieve a good results.
the issue:
lcd.sizeText() is too conservative, it take a lot of spares
Expected Behavior
lcd.sizeText() should return the exact size of the text given
Steps To Reproduce
sample widgets: WIDGETS.ZIP
Version
2.10.4
Transmitter
RadioMaster TX16S / TX16SMK2
Operating System (OS)
Windows
OS Version
win11
Anything else?
No response
lcd.sizeText() calculates the width of the string passed; but always returns the height of the largest character in the font (not the string parameter).
that is exactly the bug :-) the function does request my string, and it does calculate the width based on my string I do expect it to calculate the height as well based on my string
this is issue exist both on LCD version as well as on LVGL
LCD
LVGL
First, not a bug since this is per design: it allows to concatenate text in efficient way, by giving a 'next' point given your current exact text, and a height that will allow this, or text to come to fit
Ok, So can I get another function, or an additional flag In such a way the function will calculate the size based on the string I send it(!), and not based on theoretical string that will never come?
I like to build a dynamic widget, that will not assume any predefined size. and we do not have css tools, So I like to have that can help me achieve my goal.
Unlikely - text is fixed height in LVGL (which is used for both cases). There is no facility provided to get the pixel height of an individual character.
tough one :-( Lets try from other directions, I notice that all the A-Z a-z are the same height as a typical "A" height. Why the special characters are different height? Is changing the font, only on the special characters, is an option?
The character heights are determined by the font source used to create the lvgl fonts. You also need to remember that the fonts contain characters for non-english translations which are taller.
I like the getTextSize to calculate the size based on the given text, and not on a text that maybe. It should not be static on the height, the same it is not static for width
@philmoz Since there is still no implementation of lvgl.textSize() Can it be implemented as new function, but this time accurate to the suppled string?
As I've already explained, the height of the font is a fixed value which is already returned correctly by the lcd.getTextSize function.