WebListBox - which rows are in view?

Is there any way of telling which cells can be seen by the user in a web list box after the user has scrolled?

I have been working on that for a while. As far as I know, there is not within Xojo, since WebListBox does not have ScrollPosition.

It should be possible in JavaScript to retrieve the scroll position of the HTML table that are in fact the WebListBox rows.

Thanks Michel,

I thought of creating my own list box with labels except I don’t know how to size them when the text is multiline.

It is very difficult to know which height a block of text will be on the web, even if you specify font and size, since you have no certainty the user may have changed text size or even fonts.

Techniques such as http://documentation.xojo.com/index.php/Graphics.StringHeight are also difficult to use or unreliable as soon as you install a web app on a regular server (not your own box) since most hosts do not install the UI, so there are no fonts to get information from.

You may want to approximate that by dividing the length of text by an average line length which extrapolates the probable height of it when wrapped.

Unfortunately approximations will result in clipping or bank lines for leeway.

No so much, if you use a font width table. See https://forum.xojo.com/18811-weblabel-wrap/0

Then you can do a wrap routine that will in fact produce the same as Xojo. The principle is that :

  • Cut a chunk of text the length of the line
  • If no space is there, the line stays as such
  • If there are spaces, the first from the right will be where you cut the line
  • Start from the cut to get a new chunk of text and do the process again

At that point, you will have very little approximation.

I have no idea what you are after, but introducing variable multiline in a grid looks pretty daunting. The Desktop Listbox, for instance, simply does not have it, which allows ScrollPosition. With variable multiline, it looks kind of impossible.

Michel, WebListBox cells already can display multiple lines when required and display single when not.
The solution you gave in the link looks good provided known fonts exist for all users. Unfortunately that is not the case with my app.

[quote=199360:@Eric Wilson]Michel, WebListBox cells already can display multiple lines when required and display single when not.
The solution you gave in the link looks good provided known fonts exist for all users. Unfortunately that is not the case with my app.[/quote]

There you have it. It is impossible to be absolutely sure the client will have the right font, and use the default font size. Then trying to autogrow a WebLabel vertically for all clients is in the realm of impossible IMHO.

The WebListBox is indeed already intelligent enough to provide that.

The conversation started with the need to know ScrollPosition. With no multiline, it would be conceivable to get that in JavaScript.

But as soon as you inject multiline and/or variable font size, this becomes a whole new ball game and I frankly do not see any way, however complex, to get there. WebListBox or WebLabels included.

The only way I think you might be able to figure this out is by setting all that in a WebCanvas, or in a picture. Then you control very precisely the place of every item. Problem is, it will be a lot slower.

Jquery can get absolute positions of controls. You can do this on the Listbox control itself and the cell you want. If the cell’s Y position is within the listbox’s top and top+height then it’s at least partially visible. Consider the cell’s full height to see if the entire cell is visible. You’ll want to use the WebControlWrapper to return values from the Jquery so you can respond to the result. All in all it isn’t an easy thing, but its certainly possible.

It would be possible to use the multiline list box as a template to create an array of labels the same size of the cells if the RowHeight property worked in multiline. Unfortunately it reports as if it were a single line.