If you have a string indicator that displays continuously updating data, there is an easy way to keep the indicator scrolled to the latest data:
If you wire a value of +Inf to the Text.ScrollPos property of a string indicator, it will always scroll to the very end of the data displayed within the indicator.
Just add a U32 conversion and it's coercion free and still pretty and small. 🙂
Or the best solution yet... let Constant Folding run it's course. I remember one time a surprising benchmark from altenbach that proved in some cases coercion dots gave better run-time performance than explicit conversions.
And Darren, great nugget, thanks, as usual!
Good one Darren. I think I picked that one up on a forum some time ago.
I wish I could figure out a way to do this only if the scroll bar is at the bottom. Right now if you try to scroll up to see something from earlier, you lose it as soon as the next bit of data comes in. I've wished for this when watching a 1Hz GPS stream come in. I want to go back and look at what happened a few seconds ago. Of course you could do something where you have a control on the FP to turn on/off autoscrolling, but it would be more complicated to make the autoscrolling depend on whether you were clicking on the scroll bar, or whether the scrollbar was scrolled up. Hmm... it would be nice if autoscroll could be a built-in option for text boxes to automagically do all this.
Here's a quick solution for your use case. If the user manually scrolls the string, it turns off the auto scrolling. If he then clicks the "Resume Autoscroll" button, it starts auto scrolling again. This is the best I can do with what we have...we would need a "Maximum Scroll Position" property to be able to have it automatically start auto scrolling again when you scroll to the bottom.
Thanks Darren! Your code there is more useful than you may have realized. We actually (sort of) do have a Maximum Scroll Position Property, at least at the instant when we set the Scroll Position to +∞. My attached modification to your code seems to work. I think some additional logic would be needed to handle would be the case where the length of the string was shortened--I think you could get stuck with AutoScroll off.
If I'm missing something, please feel free to point it out. Thanks!
Yeah, when I first tried to solve this, I made that assumption too. But where it breaks down is that the max scroll position stored becomes stale once the string scrolls to more lines. You can see this by doing the following with your VI:
The reason it does this is that the max scroll position you stored (probably 5 or 6) is an old value...after 10 seconds, the string may have dozens of lines. So when you start scrolling down again, once you go past 5 or 6 lines, you exceed the old stored max scroll position value, and it starts auto scrolling again.
So again, the only solution I see for this (other than making your own enable scrolling button like I did) is to have a property you can read on the string that gives you the current maximum scroll position.