Txt_add(): précisions needed

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
JackZ
Posts: 2267
Joined: Mon Feb 22, 2016 1:02 pm

Txt_add(): précisions needed

#1 Post by JackZ »

Hello to all

I always encounter some difficulties using properly the txt_add() Lua function.
I would like some feedback about the way the text box is displayed with regard of the position tag, i.e. "LEFT", "RIGHT", "CENTER".

I guess it is also related to the font size, but especially when using the Center or Right tag, I rely mainly on a painfull "trial and error" which is not very productive.

Any hint or help appreciated.

JacquesZ
Last edited by JackZ on Fri Mar 24, 2017 9:17 am, edited 2 times in total.
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: 7927
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Text_add(): précisions needed

#2 Post by Ralph »

I think that in the future we will develop an 'instrument creator', that lets you add, drag, etc... various items (text, images, sound, etc) and then you can add code to it. But that won't be soon.

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

Re: Txt_add(): précisions needed

#3 Post by JackZ »

I guess the style tags are far from straightforward.
And especially the -fx-text-alignment:right;"
I understand it is related to the CSS format, but the link to the JavaFX CSS reference guide provided in the Wiki is ...somewhat cryptic to say the least.

Could you elaborate a bit on that Ralph?
Thanks in advance.

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: 7927
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Txt_add(): précisions needed

#4 Post by Ralph »

The JavaFX format is going to disappear with 3.0. We will try to make a better documentation when the new styling is implemented.
There is some documentation provided by Java, but not everything works. http://docs.oracle.com/cd/E17802_01/jav ... ssref.html

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

Re: Txt_add(): précisions needed

#5 Post by JackZ »

That reference guide is the one I qualified of "cryptic"! :geek:
Thanks for trying anyway, Ralph. Back to trial and errors.

Talking about that, I have an idea.

When developing in the create mode, the good thing would be to:
- Add a pixel grid overlay to the instrument, to help in positioning graphic items and more importantly, text boxes.
- add a temporary surrounding box to the graphic items, with a cross in the center of the box. Specially useful for text boxes.

That would be a perfect use of the graphic library!
I'll let you informed of my trials. If it is valuable, that could be a nice addition to the create tab IMHO (and easy to implement) in a future version?.

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

jml79
Posts: 87
Joined: Wed Jan 06, 2016 4:33 am

Re: Txt_add(): précisions needed

#6 Post by jml79 »

Jack, I'm not sure I understand your question completely but I will try to answer. When you make a text box, you define its width and height. I often use the box dimensions from skinman. For this explanation let's say the box is big, 250 pixels wide by 30 high. Very long but narrow box. you only need to put 4 numbers in that huge box. The numbers aren't going to fill the box. So. If you use align-Center it will put your numbers in the middle of the box. Align-right will put them at the right edge.

When I'm making a digital 7 segment readout, I find it looks most realistic to use align-right. I also make sure to use a var_round on the number to set the decimal point (0 is a valid var_rnd so use it to get rid of decimals) and also very important is to use a true monoblock or mono space font. I have a nice open source 7 segment monoblock font.

If you use align-Center or a normal font the numbers move left and right as they change which doesn't look right.

I hope this helps some.

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

Re: Txt_add(): précisions needed

#7 Post by JackZ »

Thanks jml

I finally bit the bullet and put to use the graphic library I designed last year.

I created a test intrument to test strings and fonts and most of all to know the exact boundary box of a test string. As usual, I went more further than I planned... :twisted:
I just have to change the test string, the font used, font size and properties to have the exact size. It's just a matter of manually counting the size in pixels of the string using the overlayed grid and then set the boundary box accordingly to get the exact dimensions and position to be used in the code. No more trials and errors!
Capture.PNG
While using it I noticed a few things:

- Each character is positioned to its upmost and leftmost postion with regard of an UPPERCASE LETTER
- If the letter is in lowercase, the position is slightly (a few pixels) below the insertion point. The number of pixels is dependant of the actual font size
- the "boundary box" width for a line of text is dependant of the font size. To take into account the lower cases letters with a "leg" (don't know the term in English), such as j,g,q or p one has to add approximately 4 pixels down.
- the -fx-text-alignment: JUSTIFY; function doesnt work (see line 7), it acts as if it were LEFT
- the -fx-text-origin: top function doesnt work
Capture.PNG
By the way, I added two more functions to the graphic library since it was needed:
the box function (straightforward)
and the grid and grid2 functions.

For the latter two functions, their purpose is to be used that way
As long as you have the graphic library installed in the instrument's folder you are working on, you can generate an "overlay grid" over your instrument in ONE easy step in order to help you positioning items.
it takes only a line of code, such as : grid(0,0,500,500,10,10,"black","red")
I advise you to add it at the very end of your code, so it will be displayed last (overlayed), and can be easily removed later
Capture.PNG
Capture.PNG
I will update the dedicated post with the 1.30 version of the graphic library for those willing to try it.

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: 7927
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Txt_add(): précisions needed

#8 Post by Ralph »

I'll see if I can use some of these items to add to the wiki. The styling is going to change, but not for another few months, so it's still worth it to add this documentation.

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

Re: Txt_add(): précisions needed

#9 Post by JackZ »

Yep
Could you tell me why the justify option and the vertical position of text doesn't seem to work?

I can publish my test instrument for you to try if you wish

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

Post Reply