Page 1 of 1
Font Size Calculation
Posted: Tue Jul 15, 2025 4:48 pm
by oceanarts
I'm trying to find a way to adapt the font size to the display resolution.
I tried (and I'm just playing around here):
Code: Select all
Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT / 10)
DebugPrint(fontSize)
But it seems like division won't work, however multiplication does work.
Any tips?
Thanks!
Re: Font Size Calculation
Posted: Tue Jul 15, 2025 7:51 pm
by jPV
You have the division in the wrong place. You should first query the height attribute with the
GetAttribute(), and then divide it. If multiplying does work in the wrong way, you are probably getting some unintented value by luck.
So, like this:
Code: Select all
Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT) / 10
DebugPrint(fontSize)
Re: Font Size Calculation
Posted: Tue Jul 15, 2025 8:14 pm
by oceanarts
jPV wrote: ↑Tue Jul 15, 2025 7:51 pm
You have the division in the wrong place. You should first query the height attribute with the
GetAttribute(), and then divide it. If multiplying does work in the wrong way, you are probably getting some unintented value by luck.
So, like this:
Code: Select all
Local fontSize = GetAttribute(#DISPLAY, 1, #ATTRHEIGHT) / 10
DebugPrint(fontSize)
Can I blame the heat on this one?... Please?
Thanks, man,

Re: Font Size Calculation
Posted: Wed Jul 16, 2025 2:50 am
by oceanarts
Well, this was a dumb idea anyway. Couldn't be that simple.
Re: Font Size Calculation
Posted: Wed Jul 16, 2025 5:00 pm
by Bugala
@oceanarts what do you mean by dumb idea? The fixed version works. It takes the screenheight of display and divides it by ten, and then saves the result to the variable "fontsize".
Re: Font Size Calculation
Posted: Wed Jul 16, 2025 8:18 pm
by oceanarts
Bugala wrote: ↑Wed Jul 16, 2025 5:00 pm
@oceanarts what do you mean by dumb idea? The fixed version works. It takes the screenheight of display and divides it by ten, and then saves the result to the variable "fontsize".
If it came across as me calling anyone but myself and the initial idea "dumb" then I am truly sorry. That was not at all what I meant. Forgive me if that's the case.
It does indeed work, but the font ends up too big or too small in certain resolutions. It needs refinement, but that's going to be too complicated for me at this point.
Re: Font Size Calculation
Posted: Wed Jul 16, 2025 9:59 pm
by Bugala
Ah, no wonder you misunderstood my message wrong, since I misread the reply too. Somehow I read as jPV pointing the error and then instead of jPV also having posted the corrected code, I thought you posted the version of code based upon jPVs instructions.
Therefore I read as you posting a new version of the code (which was actually jPVs) and thought you meant by your "dumb idea" that "this is the code I tried, but it didnt work".
So no, didnt think you called anyone or anyones idea dumb, just thought you were calling your own working code a dumb idea, as in meaning - not working. So was just pointing out that the code actually works, in case you had erroneously thought it didnt.
One thing you need to take into consideration is also the width of the screen. Having 10 percent size of height for a 320x256 or 640x256, will look very different, and similarly 640x256 and 640x512 will look different, as the font size is both WIDTH and HEIGHT, hence in other case WIDTH will span double the amount, while height may stay the same.
Re: Font Size Calculation
Posted: Wed Jul 16, 2025 11:01 pm
by oceanarts
Yeah, there's a lot more to consider than what I initially thought. Right now it's just better to adjust the font manually for each display, but it'd be cool if i could find a method that works.
Re: Font Size Calculation
Posted: Thu Jul 17, 2025 3:09 pm
by Flinx
To give you something to experiment with, here are some of the first lines of the function I use to adjust the font size to window changes. Maybe it helps.
gConfig["DisplayHeight"] and so on are the default values from my configuration file.
Code: Select all
Const #MAXFONTSIZEFACTOR=0.15
Function p_AdaptToWindow()
p_RemoveAllMessages(0)
gDisplayHeight=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRHEIGHT)
gDisplayWidth=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRWIDTH)
gRightBorder=GetAttribute(#DISPLAY, gLRCdisplay, #ATTRBORDERRIGHT)
If gDisplayHeight<10 Then Return ; wenn zu klein, hat das keinen Sinn mehr
; Faktor für Schriftgrößenveränderung ermitteln
Local FontSizeFactor=Min(gDisplayHeight/ToNumber(gConfig["DisplayHeight"]),gDisplayWidth/ToNumber(gConfig["DisplayWidth"]))
Local maxFSize=Limit(gDisplayHeight*#MAXFONTSIZEFACTOR,1,1e9) ; maxFSize ist der Maximalwert
; neue Schriftgrößen festlegen
gLRCFontSize=Limit(FontSizeFactor*ToNumber(gConfig["LRCFontSize"]),1,maxFSize)
gTxtFontSize=Limit(FontSizeFactor*ToNumber(gConfig["TxtFontSize"]),1,maxFSize)
gTagFontSize=Limit(FontSizeFactor*ToNumber(gConfig["TagFontSize"]),1,maxFSize)
gMsgFontSize=Limit(FontSizeFactor*ToNumber(gConfig["MsgFontSize"]),1,maxFSize)
You can try out the effect by starting
LyricsJukebox with at least one music file with matching lyrics.
Re: Font Size Calculation
Posted: Tue Jul 22, 2025 8:11 am
by oceanarts
Thanks, I'll have a look. I'm trying to do a menu screen and make it as flexible as possible. But I have to worry about the placement of text elements and their sizes too. I wasn't prepared for the complexity of something as simple as a menu screen.
