weblistbox.rowheight

hi,

i have a listbox inside a containercontrol and i need to adjust the height of the listbox so that all the rows are shown without a scrollbar
since i dont know the number of rows, as i add a row, i get its height and add this to an integer which i later use to resize the listbox
and also to set the height of the containercontrol, so i get a list box with a nice frame around it.

however, rowheight doesnt seem to be giving me the correct height. if i use rowheight * 1.5 its nearly right, but sometimes not, leading to
strange visual effects.

im assuming its to do with syles, but i cant see how to get the correct value.

any ideas?

To do this pixel prefect correctly, you would need to hack into the DOM (Greg is not a fan) and have something return the actual height of each row to the server. You’d add these up, add in some fudge pixels for borders (perhaps) and get the total needed height. Nope, there is no other way to do this right.

Cheers Brad,

i kinda thought that would be the answer ;-(

Not impossible, but that’s just how HTML rendering works. You don’t have great access to the underlying metrics (like fonts) that determine actual sizes.

I have the same issue with needing to know the actual height of a weblistbox. In any of the updates, is there any way to do this?

It would really be great to have autosizing web controls. Not just weblistboxes, but labels, etc.

What kind of autosizing are you talking about ? Controls that grow with the size of content, like for instance labels in VB ?

Yes, autosizing labels would be very nice. Preferably, I’d like all controls to have the option of autosizing to their content. It’s pretty tough to do page layout when you don’t know how large the controls need to be to hold your content.

I used VB some ten years ago and was familiar with Autosize for labels and TextFields. It is pretty simple to do for Desktop, since stringwidth is available. On a Linux host, most of the time fonts are not present, so one has to find another method. I posted a while ago a way to store a font characters width table, but cannot locate it at the moment. Anyway, it was only for one size, so I would need to work on that again and make it more general.

Labels do not necessarily need autosize so badly because they are transparent, so if you make them a lot longer it does not show and your text can grow. It could be of interest for TextFields. The other issue I found with autosize is clamping. How much are you willing the textfield to grow before it bumps into the next control. Otherwise, it ruins your layout just as well.

As for other kinds of controls, how do you want them to grow ? TextAreas usually simply scroll when content grows. They could be made to grow wider, but with which rules ? Listboxes could grow wider, but same issue as TextFields, up to which point ?

That feature itself is tough to implement.

Here’s my problem. I’m writing a survey application. People can define their surveys and then they are displayed on a page. The thing is, I need to know how many lines thing such as questions and choices will take. I can put a question in a label, but if the question is very long, it’s going to be larger than the available label size. Same thing with answers. Suppose there are four multiple choice answers and they each are very long. I need to know how many lines they will take up to display them properly. I guess I could set length limits for things, but that seems like a bad idea. Right now I’m estimating how many vertical lines a string will take up based upon the string length. That sort of works, but is not reliable, and may be extremely unreliable on some systems with very different fonts.

Some people have talked about installing fonts and then using those fonts to determine string lengths. I don’t know whether that is a possible solution or not.

I need to find some solution, though. If you can’t know sizes of items, I don’t know how page layout is really possible.

[quote=167041:@Kevin Clark]Right now I’m estimating how many vertical lines a string will take up based upon the string length. That sort of works, but is not reliable, and may be extremely unreliable on some systems with very different fonts.

Some people have talked about installing fonts and then using those fonts to determine string lengths. I don’t know whether that is a possible solution or not.[/quote]

In Desktop, what you do is to use Graphics.StringWidth and Graphics.StringHeight to get the size of the text block, then you can size your label appropriately. I have observed a slight error margin in height, but it is pretty reliable.

That works well on a linux host, if the font you are using has been installed. Since most Linux servers do not need a GUI, they seldom have the fonts you can use on your machine during debug. You will need your host to install them, or to that yourself on your VPS. I went through the process and largely commented it here:
https://forum.xojo.com/15834-install-fonts-on-linux-server

Alternatively, you can generate a character width table for a given font, so you will be able to calculate the width of a string as precisely as Graphics.StringWidth does. I outlined the method here :
https://forum.xojo.com/18811-weblabel-wrap

Obviously I did not need it because my host provider installed the fonts for me. But I did test the method and it gives just the same result. I realized just recently I could have made the width table for point 100 and then divide for lower sizes, but the principle remain. Likewise, you can get the Graphics.StringHeight for size 100 and divide for smaller sizes, that will give you the line spacing.

AutoLayout is coming for Web next. Once this is here we’ll be able to have intelligently sized controls. In the meantime you can always use the webControlWrapper to build your own controls to handle this.

Autosize is somewhat different to Auto Layout. Although it may ultimately play a role in the interaction between controls, hence play on the layout, it essentially allows a control to adapt to its content.

Present Xojo Auto Layout does not manage controls size relative to content. From previous engineers posts, it may come, but nothing seems on the table yet. And absolutely no indication as to when Auto Layout will be implemented has been given so far.

I do not believe the WebSDK is necessary to create classes capable of autosize. The current controls can be made content aware without much difficulties. I have done that for desktop quite a while ago.

I am not versed enough in JS to know if it provides a way to get the size of a string displayed on the screen, though. If that was the case, then indeed webControlWrapper would become a must.

If the webcontrolwrapper can be used to create autosizing controls, has anybody already done this for weblabels? I’d rather not reinvent the wheel.