Web text size and valign

I am creating labels on the fly (in a webcontainer) and wish to position them based on their width and/or making the label multiline, horizontally.

So can you get the width of a string to help determine if text will fit in a specified width and whether I need to make the label multiline and increase the height.

A related question is, is there a way to set “valign” so that if a series of labels (horizontally) are all aligned on the bottom? Some may be one line some may be multiple lines.


See this thread for discussions on determining a string’s width.

To align labels at a bottom value, you only need a simple calculation to determine the correct top position: - . To make it easier to use, you could create a method in a module that extends WebControl so that it applies to all controls:

Sub SetBottom(extends wc as WebControl, bottom as integer)
  If wc <> nil Then
    wc.Top = bottom - wc.Height
  End If
End Sub

You would then call .SetBottom on every control that you wanted aligned.

I guess I will need to wait for some of the iterations to use the auto layout discussed in that other link. These are dynamic labels where the label is a fixed width and variable height, depending on need. So I need to know the height of what the text will be so that I can make the label the appropriate height and multiline if necessary. And then with that information I can use your above suggestion to determine a bottom alignment.

At present Auto Layout does not take into account the content of controls. And from what I see it may not be exactly simple to implement.

On desktop, you would use Graphics.Stringwidth and Graphics.Stringheight to know the dimensions of a particular block of text. Problem is, even if Web Edition supports that and you can use it in a debug run on your computer, most hosts do not have fonts installed. See https://forum.xojo.com/15834-install-fonts-on-linux-server

If you can get your host to install fonts for you, or if you can install them yourself on your VPS, then it becomes available to estimate precisely the size of the text.

See https://forum.xojo.com/22918-rubberviewswe-for-xojo-web-version-1-15-20151119?search=gettextheight