Beijer Electronics (formerly QSI Corporation)
http://www.qsiforums.com/

Listbox Text Wrap?
http://www.qsiforums.com/viewtopic.php?f=6&t=4489
Page 1 of 1

Author:  TheKorean [ Thu Nov 15, 2012 6:21 am ]
Post subject:  Listbox Text Wrap?

I'm using the G70 and the listboxV2 add on by opto. I want to display a string table that's about 1000 characters wide and 150 lines long without having to scroll left and right. Is there a way to wrap the text that's off screen to the next line? Right now I've got it scrolling up and down fine, just some lines have text off the right side of the screen.

Author:  Ron L. [ Thu Nov 15, 2012 10:13 am ]
Post subject:  Re: Listbox Text Wrap?

The listbox doesn't support multi-line text, however with some modifications to that object (as a template), it should be possible. I've attached an example to get you started.

Attachments:
multi_line_listbox.zip [11.56 KiB]
Downloaded 219 times

Author:  TheKorean [ Thu Nov 15, 2012 7:52 pm ]
Post subject:  Re: Listbox Text Wrap?

Sorry i'm not very good with scripts. I'm doing my best using what literature i find online. I tried using the multi-line code in PacListBoxV2 in the 4 locations you used it in your template. My PacListBox is using a tag for a string table. With the 4 lines modified in the basic ListBox library it just cuts off the text on my PacListBox instead of continuing it onto the next line. Can your fix still work with what I'm doing?

Author:  Ron L. [ Fri Nov 16, 2012 8:59 am ]
Post subject:  Re: Listbox Text Wrap?

The PACListBox inherits from the ListBoxV2. Any changes you make should be to a template copy of the ListBoxV2.

Do NOT change any code in the libraries directly. You should be using Templates.

To create a template go to Edit->Add/Edit Templates->New Template->Copy the code of existing..

Author:  TheKorean [ Wed Nov 28, 2012 5:31 am ]
Post subject:  Re: Listbox Text Wrap?

It works! Thanks for the help Ron! I created a template of the basic ListBoxV2 then copied in your multiline code. Then i created a template of the PacListBox which extended that. What shows on the screen is limited to the minimum height. If I set the min height to 60 the G70 will display 5 rows worth of text from one line of the table. Which is great! However, the lines with only a few words then have 4 rows of blank space before the next set of text. Is there a way for the height to be automatic based on the length of the string table line? Ideally I'd like each line of the table to have one blank line between them when displayed. Thanks again for the assist!

Author:  Jeremy [ Wed Nov 28, 2012 7:46 am ]
Post subject:  Re: Listbox Text Wrap?

The listbox will probably never support variable height lines without a complete rewrite. The editbox based suggestion I made may be a better choice for what you are describing that you want.

Author:  TheKorean [ Thu Nov 29, 2012 5:30 am ]
Post subject:  Re: Listbox Text Wrap?

Jeremy, I tried implementing the edit box using the bit of code you provided. The text did wrap nicely, but each line from the string table wouldn't start on the next line of the display. Also, both options limit me to 250 elements from the tables when I really need close to double that.

Author:  Jeremy [ Thu Nov 29, 2012 8:05 am ]
Post subject:  Re: Listbox Text Wrap?

To insert a line between each element you would modify your loop like this
Code:
for i = 0 to max
    EditBox_1.appendText = _GetString(i, strings, indexes) + "\n"
next


This will insert a line after each element in the list.

As far as the 250 element limitation goes, that was a limitation in the communication protocol itself. This can be overcome, albeit with some difficulty by using two virtual variable objects, each bound to a different section of the table and a pair of global string variables. Imagine the following:

Code:
'Global Code here
dim tablePart1 as string
dim tablePart2 as string


Code:
' Event handler in the OptoVirtualVarible object which queries index 0-249
func QueryStringTableSucceeded(queryID as integer, strings as string, indexes[] as integer)
    'This approach is the easiest to demonstrate.  There are more efficient ways to tackle this
    'if performance becomes an issue.
    dim i as integer
    dim max as integer
    max = len(indexes)-1
    TablePart1=""
    for i = 0 to max
        TablePart1 = TablePart1 + _GetString(i, strings, indexes) + "\n"
    next

    EditBox_1.value = TablePart1 + TablePart2
endfunc


Code:
' Event handler in the OptoVirtualVarible object which queries index 250-499
func QueryStringTableSucceeded(queryID as integer, strings as string, indexes[] as integer)
    'This approach is the easiest to demonstrate.  There are more efficient ways to tackle this
    'if performance becomes an issue.
    dim i as integer
    dim max as integer
    max = len(indexes)-1
    TablePart2=""
    for i = 0 to max
        TablePart2 = TablePart2 + _GetString(i, strings, indexes) + "\n"
    next

    EditBox_1.value = TablePart1 + TablePart2
endfunc


Now, I will be honest that performance is something I am concerned about when we are dealing with 500 strings that are large enough to wrap lines on a full screen listbox. I hope that this table is not something that gets queried very often. The two performance bottlenecks are: The communication itself and then the repeated string appends may not be the most efficient possible.

Author:  TheKorean [ Thu Dec 06, 2012 3:43 am ]
Post subject:  Re: Listbox Text Wrap?

Jeremy, everything works great and performance is smooth still! The tables are only queried once when you select that particular display. However, the listbox and editbox when displaying a table default to either the first or last line. In my case those are either very old or blank. Can I set the display to focus on a specific line based on the index that was used to tell the text which line to write to?

Author:  Jeremy [ Thu Dec 06, 2012 7:38 am ]
Post subject:  Re: Listbox Text Wrap?

For the either the editbox or the listbox, use the firstvisrow property to adjust the scroll position.

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/