Changing font size in string.format

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
dpaget21
Posts: 12
Joined: Thu Sep 24, 2020 9:05 am

Changing font size in string.format

#1 Post by dpaget21 »

Is there any way to change the txt size in a txt_set string format?

function gps_wp_callback (WPnextID, DISnextWP)
txt_set(txt_next_WP, WPnextID)
DISnextWP = DISnextWP/1852
txt_set(txt_Dis_NM, string.format("%.1fNM", DISnextWP))
end

I am building the GI 275 and would like to make the "NM" smaller like it is on the real instrument

User avatar
Corjan
Posts: 2939
Joined: Thu Nov 19, 2015 9:04 am

Re: Changing font size in string.format

#2 Post by Corjan »


JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Changing font size in string.format

#3 Post by JackZ »

I understand you want TWO different text sizes in the same string (ie XXX Nm, where the XXX number is bigger than Nm?

I think this is not possible right now in AM, since the same text_style applies to all the characters of a string (color, size), so my advice is to use two different strings side by side, one for the number itself, the other for the “Nm” text. In the text_add() you will be then able to choose whatever color/size you want for both parts.

If visibility is a concern, simply create a group out of the two text_add() and then turn the visibility of the group on/off with one instruction.

That’s what I did for the A320 MCDU, where each character of a line is put in an individual text_add() for complete control. Each character assembled into a line is organised in an array of characters for ease of access.
(See the bottom multicolored line below)
71CC3655-A0B3-49EC-A0AA-AEA39BCA1BD7.jpeg
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Ralph
Posts: 7923
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Changing font size in string.format

#4 Post by Ralph »

The solution from JackZ is the easiest. Another, more difficult solution, and I'm not 100% if it'll work, is to make a custom font with bigger and smaller sized characters.
I usually use FontForge if fonts need to be customized. https://fontforge.org/en-US/

User avatar
Keith Baxter
Posts: 4685
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Changing font size in string.format

#5 Post by Keith Baxter »

Hi,

AM and lua is very powerful when using tables.

Having worked on the Gi 275, Tables are the route IMHO. As Corjan said. Use txt_style to change the format.
Create a table with your styles and call options from your table and concatenate.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Changing font size in string.format

#6 Post by JackZ »

@Keith Baxter
I don't understand how you can concatenate different style in the same string, as txt_styles applies to the whole text string if I'm not mistaken?
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Changing font size in string.format

#7 Post by JackZ »

here's a simple code based on yours for you to try

Notice the use of halign here

Code: Select all

txt_next_WP=txt_add("XXXXX", "font:arimo_regular.ttf; size:50; color: red;valign:bottom;", 50, 50, 300, 50)
txt_Dis_NM=txt_add("XXX", "font:arimo_regular.ttf; size:50; color: red; valign:bottom; halign:right;", 50, 100, 95, 50)
txt_Dis_NM_legend=txt_add("Nm", "font:arimo_regular.ttf; size:30; color: blue; valign:bottom; halign:left;", 145, 100, 100, 45)
DME_grp=group_add(txt_Dis_NM,txt_Dis_NM_legend)

visible(DME_grp,true)

function gps_wp_callback (WPnextID, DISnextWP)
txt_set(txt_next_WP, WPnextID)
DISnextWP = DISnextWP/1852
txt_set(txt_Dis_NM, string.format("%0.1f", DISnextWP))
end

gps_wp_callback('WAYPOINT',852)
txt_style(txt_Dis_NM,"color: green;")
image.png
image.png (7.69 KiB) Viewed 875 times
Last edited by JackZ on Thu Jun 09, 2022 4:56 pm, edited 4 times in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

dpaget21
Posts: 12
Joined: Thu Sep 24, 2020 9:05 am

Re: Changing font size in string.format

#8 Post by dpaget21 »

JackZ wrote: Thu Jun 09, 2022 4:37 pm here's a simple code based on yours for you to try

Notice the use of halign here

Code: Select all

txt_next_WP=txt_add("XXXXX", "font:arimo_regular.ttf; size:50; color: red;valign:bottom;", 50, 50, 300, 50)
txt_Dis_NM=txt_add("XXX", "font:arimo_regular.ttf; size:50; color: red; valign:bottom; halign:right;", 50, 100, 95, 50)
txt_Dis_NM_legend=txt_add("Nm", "font:arimo_regular.ttf; size:30; color: blue; valign:bottom; halign:left;", 145, 100, 100, 45)
DME_grp=group_add(txt_Dis_NM,txt_Dis_NM_legend)

visible(DME_grp,true)

function gps_wp_callback (WPnextID, DISnextWP)
txt_set(txt_next_WP, WPnextID)
DISnextWP = DISnextWP/1852
txt_set(txt_Dis_NM, string.format("%0.1f", DISnextWP))
end

gps_wp_callback('WAYPOINT',852)
txt_style(txt_Dis_NM,"color: green;")
image.png
So simple using halign, don't know why I didn't think of that, maybe it was too late in the evening.

The HSI is nearly complete now onto teaching myself multi-page instruments

JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Re: Changing font size in string.format

#9 Post by JackZ »

You're welcome....
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

Post Reply