LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

length of text displayed in string control

I'm trying to roll my own custom scrollbar, since LabVIEW does not have a native way to set colors, transparency, or width of scrollbars. I'm going to try it with a picture control!

 

To set the size of the bar to the percentage of text displayed, I need to know how long the text in a string control is and how much of that is visible in the string control. This is not the same as counting lines (EOLs). What is needed is thelumber of lines displayed taking into account word wrap and text size.

 

I can see that the scrollbar position value of a sting, which is readable even if the scrollbar is not visible, gives the line number of the topmost displayed line in the string, but this does not appear to be enough information for my custom scrollbar.

 

Thoughts?

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 1 of 16
(4,923 Views)
My thoughts are that you will end throwing a lot of code at this for very little benefit.

Why do you feel that you need uber-customized scrollbars? Why not just use system themed controls and call it done?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 16
(4,878 Views)

I largely agree with Mike.  As it turns out, setting the width of a Control or Indicator to match a String Width is not at all an easy proposition -- NI has (so far) not provided properties or methods to easily accomplish this.  I have managed to do it, but it was much more effort than I expected (and a bit messy).

 

Bob Schor

0 Kudos
Message 3 of 16
(4,846 Views)

Oh I love custom 2D picture control psudo controls.  But they tend to not be worth it.  If you do end up getting something to work be sure and post it.

 

As for the string size.  You can use the Get Text Rect.vi (on the Picture Functions palette).  Given a string, and font settings it will tell you the 4 points in space it takes to draw it (left, right, bottom, and top).  You can read the font settings on the string control, but be aware that each character could have different font settings.  But to make life much much easier you can try to just make an assumption that the font settings on the string control are the same for all characters.

Message 4 of 16
(4,822 Views)

What I'm asking for is how to calculate the amount of text displayed in a string control, not the size of a control required to display the string.

 

By convention, since Apple introduced it in like 1996, the legth of the scrollbar is proportional to the amount of the text or page shown. I'm trying to figure out how to do that.

 

As for what's worth the effort, that's a matter of taste and style.  LV does not have a way to customize scrollbars. I'm entertaining myself by trying to do it on my own. 🙂  I've probably wasted a lot of effort trying to acheive UI goals, but it's fun!

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 5 of 16
(4,808 Views)

Okay well how about this.  You can use the function I mentioned to get the total size of the string, or rather how large the string control needs to be to show all of it.  You can then get the size of the control using other property nodes.  Then you can know the ratio between the total string size, and the amount that is currently shown...of course this does have one major issue that I can't think of an elegant way to fix, the wrapping text.

 

You will likely have a control with a bunch of text that wraps down to other lines.  The Pict Rect function I gave before doesn't know about the string control size it is going into and you'd either have to get creative, or insert returns where they are needed, based on the string size and control size.  All very ugly.  If it were me, I'd count the number of lines, and use that as the needed scrollbar size.  It wouldn't be as elegant but would take a little less time to implement.

Message 6 of 16
(4,794 Views)

! We've reached the crux of the matter. You said I need to count lines. This is exactly what I'm asking for. How many lines are displayed in the string control, and how many lines are required to accomodate a given string, taking into account font, size, and wrapping? This is what I can seem to figure out. And yet, the scroll positon of the string *is* number of lines above the currently displayed text. So LV knows. But isn't telling me? I must be missing something.

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 7 of 16
(4,749 Views)

LabVIEW String Controls are tricky, and don't have all of the properties that we might hope them to have.

 

When you lay down a String Control, the size of the Control determines how much text can be shown.  If you have the Wrapping property off, then text will scroll off the left end, while if the wrapping property is on, text will "jump up" out of the current Text space when the String gets too long.  There is a String Method, "Size to Text", that will change (when invoked) the vertical size of a text box (if wrapping is enabled) to show the wrapped string.

 

All of the logic for when/how/if to wrap is hidden within the String Control -- as far as I know, there are no Properties or Methods that facilitate the User easily specifying this.  You can, of course, "write your own Editor" and worry about Fonts, sizes, etc., but (a) it is a lot of work, (b) it is not guaranteed to work, and (c) you almost surely have more productive uses of your time.

 

See if there is another way to achieve the functionality that you want.  How about changing that to "the functionality that you need"?

 

Bob Schor 

0 Kudos
Message 8 of 16
(4,713 Views)

P.S. -- your last sentence is correct -- LabVIEW (or NI) Knows (about String Size, Wrapping Rules, required Control Heights and Widths), and Isn't Telling Us.

 

BS

0 Kudos
Message 9 of 16
(4,711 Views)

Thanks Bob, the difference betwen want and need is no fine line. Thank you for your sensible input.

 

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 10 of 16
(4,631 Views)