LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wrapping Captions and String Position

Hi all,

 

Got a quick question which I'm hoping is easily resolved and not an oversight on my part as its starting to bug the hell out of me.

 

I have a cluster who's caption I want to edit at run-time (you can't edit the label at runtime) to display the appropriate header title that is specified at the start of test. This works, however I need to ensure that the text does not expand

past the width of the cluster itself as I have multiple clusters next to each other thus I want to be able to wrap the caption text like you can a normal string indicator. The text will always be multi-lined.

 

If you run the attached VI you can see that the caption is excellent as it shifts the text upwards when a new line is encountered, however there does not appear to be a direct property or invoke node to enable caption wrapping. On the other hand, the string indicator  (which I have made invisible to mimic the caption) shifts the new lines down which means the new lines are hidden behind the cluster (or in front depending on layering but whichever way unusable). The string indicator however allows for wrapping.

 

Is there a way to incorporate the wrapping functionality into a caption or a way to shift the text upwards in a string indicator?  

 

Cheers in advance

 

Mitch

0 Kudos
Message 1 of 15
(3,981 Views)

You can force the test to wrap by replacing a space with an EOL.  Here's a quick example.  Make sure your caption is set to Size To Text and you have no EOL characters in the text you want to use.

 

Wrap Text.png

 

This just searches through the string and replaces the first space character after the character number specified with an EOL then does it again starting after the replacement.  It will keep going until it reaches the end of the string.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 15
(3,938 Views)

Mitch,

 

Can you possibly include a string indicator as part of the cluster and write the "caption" text to the string? You have a lot of flexibility with string indicators.  If the text must be outside the cluster, you could still use a string indicator (not a part of the cluster) and Group it with the cluster so the relative positions remain constant.

 

Lynn

0 Kudos
Message 3 of 15
(3,927 Views)

Cheers for the replies, much appreciated.

 

Kelly, tried the code but it does not appear to work correctly. Correct me if I'm wrong but you have set an initial offset of 25, however your code is then searching for a space after this offset. The problem with this (I believe) is that the offset point is completely static and would change depending on the string input.

 

For instance, if I typed "HelloWorldNiceToSeeYouNiceWeather Sunny" then your string would not wrap until after the word Weather. This string is still way to long for my cluster width. I do like the concept though and it does work in the right scenario but my strings will be completely random and the code must be able to handle any string input.

 

I wonder if I can use the Position and Bounds property nodes to check the size of the string indicator, caption box or cluster then somehow use this as the offset specifiier or something similar. Not sure if this will work though.  

 

Lynn, unfortunately I can't include a string indicator in the cluster but also I think this would cause a similar problem as I would have to leave enough space in the cluster for any potential string wrapping issues. If I had the cluster set to accept two lines of text in the string indicator then the operator legitimately or accidentally enters a string which requires four lines then the cluster will either re-size automatically (not sure if this can't happen at run time or if strict type defined) or size the string indicator.

 

Regarding the string indicator outside of the cluster, I have already tried this which is what the Invisible Border indicator in the VI I attached was meant to represent but this is where the issue of shifting the text upwards begins. Like you say the string is more flexible but even when I lock the string indicator to the cluster the indicator shifts the text down so its either hidden behind the cluster or overlapping in front. Are you saying grouping the string indicator to the cluster should force the text up? If so could you send me a working example as this would be a godsend?

 

Cheers

 

Mitch

 

 

0 Kudos
Message 4 of 15
(3,911 Views)

I had assumed the caption would be readable so should be wrapped at a word break.  You can change the constant to whatever value you want to accomplish that.  After I posted that I made it into a subVI that will take in a text string and an I32 and output a text string that is wrapped.  I still want to do some work on it, like checking for EOLs etc.

 

If you don't care about breaking in the middle of a word it's easy to simply insert an EOL every X number of characters to make the string wrap.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 5 of 15
(3,894 Views)

Mitch,

 

I tried a few things to see if I could get something to work. I am not absolutely sure of what you want but this may help.

 

Create the cluster. Set the caption to visible (which creates the caption). Enter some text which will be as large or larger than the maximum amount of text you want to display at one time. Select the caption and manually size it to the maximum space you want it to occupy. Create a property node from the cluster and select Property = Caption.Text. Create another property and select Caption.ScrollPosition. Make both Write.

 

Wire the text you want to the Caption.Text property node. Set the Scroll Position property node to -1.

 

Does this do what you want?

 

Lynn

0 Kudos
Message 6 of 15
(3,879 Views)

So close . . . but no cigar

 

Kelly, I can see why you thought that, should have explained a little better. It’s one of those when a picture tells a thousand words. Unfortunately the caption will be whatever the test name requires so in essence you can see it when entering the test data but not in the normal sense. I could include some error checking code to ensure the entered text conforms to set parameters to ensure it fits which would alleviate this issue, however that’s putting a constraint on the operator and test which I don’t want to do.

 

Agreed I could easily see how many characters fit into the caption bounds then assert an EOL at this point every time. This would work but it’s not as fluid and dynamic as I would ideally like it. Need must thought . . .

 

Lynn, that solution almost works perfectly and I never considered to use the scroll position property, however the issue I now appear to face is that if you set the caption bounds (or string indicator for that matter) as big, if not bigger than you will ever need to ensure all the text is visible then when you write the text to the caption/string indicator the text jumps to the top. Changing the scroll position does nothing in this case as that property is only relevant when the text is hidden.

 

I probably should have explained a little better but as well as the caption wrapping (which now works) I need all the text to be flush with the top of the cluster for each cluster so visually they look correct, regardless of the number of lines. This is why I said I wanted to shift the text up, not down but I realise this was a little murky. Here is what I mean:

 

Text Position.PNG

 

I have attached a modified VI to show this in action. If you run it, you will see that the text in both the caption and string indicator jumps to the top and I cannot see how to force it to the bottom which is the final piece of the puzzle as it works fine apart from this little quirk. I have also noticed that re-initialising all values to default doesn’t change the caption text and position; it retains the last set of written properties regardless whereas the string does revert to default. I will need this to happen as I change tests on the fly so I may end up sticking with string indicators.

 

Any idea how I can force the text position to the bottom?

0 Kudos
Message 7 of 15
(3,852 Views)

I'm still trying to figure out what you want.  The only way I know of to make sure the caption will be bottom justified and still fit the entire string is to use Size To Text.  If you do that you will need to pragmatically add EOLs to make sure the caption doesn't exceed the width you want.  You need to figure out the constraints on adding EOLs.

 

  • If there is already an EOL do you leave it in or replace it with a space?
  • Do you add EOLs at spaces if possible?
  • If there is no space in a given number of characters do you just add an EOL there?
  • What is the maximum height the caption can be?
  • Do you want to limit the maximum length of the string?
  • Can the caption be slightly wider than the cluster or is the width of the cluster a firm boundary?
  • Do you want this to be dynamic so you don't have to know the width of the cluster at edit time?

These are just the questions I came up with on the spur of the moment.  All of these can be handled.  You would need to write a subVI to handle them that would take in a string, a width, and possibly a max length then output your wrapped string.  But, to do that, you need to know exactly what you want to accomplish.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 8 of 15
(3,834 Views)

Mitch,

 

Try prepending 9 linefeeds (number depends on how tall the caption box is and what font you are using). This forces the Caption text down by the number of linefeeds.

 

Lynn

 

Prepend linefeeds.png

Message 9 of 15
(3,825 Views)

The subVI Get Text Rect.vi might be useful for you.  You feed it a text string and it will tell you the size of the bounding rectangle.  You could use that on a word by word basis, or keep using more words per line to determine how many words can fit on a given line before it would need to wrap.

 

As mentioned earlier, it might be better to use a string indicator (you can color the background and its border transparent so it looks like a label or caption.)  Then if you enabled Word Wrap, you wouldn't have to worry about were to replaces spaces with linefeeds.

0 Kudos
Message 10 of 15
(3,817 Views)