From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Bob_Schor

Auto-size String and Path Indicators to Text (Horizontal)

Status: New

I recently starting putting String Indicators in some of my programs that identified the Routine, along with its Version Number.  I have also created Dialog Boxes with one-line Messages, usually in large size, often Bold, sometimes colored and with a colored background.  I wanted to have the String indicator displaying these one-line messages "fit the text" (if the indicator was too short, the message would be truncated, and if too long, it "looked unprofessional" and wasted space).  I found code on the Forum that was awkward and didn't scale with fonts -- I found a work-around, got in touch with NI to inquire about filing a CAR to fix the specific flaw in their Get Text Rect function that I discovered, but was told they were not interested ("You just need to add a constant").

 

After more investigation, I found an even better solution to this problem, which I have posted to the LabVIEW Community here.  While this seems to work, I would like to propose that NI provide a simple Method or Property that could be used to scale the horizontal size of the contents of both the String and Path controls to just fit the content to be displayed in these controls.  This Method or Property should work regardless of the other properties, such as Font Size or Font Attribute (Bold, Italic, etc.).  It should also work regardless of the "family" of the control (Silver, Modern, Classic, or System).   I do note that System Strings might be a problem, but I could get my code to work with the System 2.0 String indicators available on the LabVIEW Tools Network.

 

The figures show a Front Panel with "too small" indicators truncating the display of their (variable, and run-time-dependent) content, plus the same Front Panel after I run my "Size-to-Text" code on the indicators.  I'm suggesting that NI provide a Method/Property to do the "dirty work" for me.

Strings_and_Paths_2.png

Notice truncation of Text and Paths

Strings_and_Paths.png

After programmatic adjustment of Indicators to "fit" their content.

 

Bob Schor

7 Comments
AristosQueue (NI)
NI Employee (retired)

Bob: I do exactly this kind of resizing for string controls in the General Error Handler dialog. Have you taken a look at that code? The specific subVI where the computations are done is "vi.lib\Utility\error.llb\Details Display Dialog.vi".

 

It doesn't answer this request directly but it might help your situation.

Bob_Schor
Knight of NI

AQ,

 

     Now I can say "Yes, I have seen that code" (as of about 5 minutes ago).  I think I see where you are manipulating the text, but you seem to be doing mostly Size to Text, which does vertical sizing.

 

     Did you follow the link to my posting in Community?  There's a 7-page PDF with a (more) complete discussion of this issue and the two ways I found to solve it, including my preferred one that uses the new-to-me Get Nth Line Method to decide if the length is adequate.  There is also some non-intuitive code that "solves the problem".

 

     It seems to me (naively) that, "under the hood", LabVIEW should be able to determine, at run-time, the horizontal extent of a String and "export" this as a Method (certainly if I can do it "after the fact", NI should be able to do so, probably faster and better).  That's my Big Idea -- create a Method and provide us with the Width output.  Note I'd be equally happy with a "Size to Text (Horizontal)" that just "does it" for me.

 

BS

AristosQueue (NI)
NI Employee (retired)

Oh, I understood your idea here. It's a good idea. I was offering another possible approach in the meantime, if it was helpful.

Intaris
Proven Zealot

You can use the functions on the Graphics (2D) palette.  If you know the font and size and then pass the text in to the function to get the size of a text field.  I haven't tested recently, but this delivers some very reliable values.

Bob_Schor
Knight of NI

If you are referring to Get Text Rect, that was the solution I found in the Forum, discovered that it returned a "too-small" value, brought this to NI's attention (by filing a Service Request, sending my code, and sending my "fix"), and was told that a CAR for this "too small" error "wasn't necessary -- I just needed to add a constant" (I think they said 7).  Of course, this does not scale with Font, boldness, etc.

 

In my post, I refer to a 7-page description of this problem and my two solutions to it, the first involving Get Text Rect.  I put a link in my original Idea Exchange submission, but when I just now tested it, it didn't work, so I'll try again.  The link is https://decibel.ni.com/content/docs/DOC-43744.  It contains a long PDF and the complete set of VIs for both of my solutions, as well as test routines that let you "play" with this to see that it scales properly.

 

I'm sorry about the broken link ...

 

Bob Schor

J-M
Active Participant
Active Participant

I know, Unicode is not supported, but Bob's solution works with Unicode string. It will be great, if LabVIEW implement this idea for Unicode string too...

iannicholson
Member

This is an old idea, and it seems Bob's link is broken now. I think this is where it used to point:

 

https://forums.ni.com/t5/Example-Code/Auto-size-to-Text-Horizontal-for-Strings-and-Paths/ta-p/352453...