Jump to content
Sign in to follow this  
chronicsilence

ListBox Auto-Width

Recommended Posts

Is anyone here aware of any way to have a ListBox control element that auto-sizes its width to the size of the text that is put into the different rows of the listbox? i.e. if I use lbAdd to add a row with more text than any other row, the ListBox width would increase?

If this is not possible with list boxes, is it possible with static controls? I see that they have the 'fixedWidth' parameter, but it doesn't seem to allow dynamic widths (that I can tell through testing).

Alternatively, is there any way to figure out what with a certain string will take up with a given font? I suppose you can use a monospace font and calculate the required width by multiplying the number of characters by a preset width per character, but is there a way to do this for non-monospace fonts like PuristaLight? There must be a way, since the built-in "Action Menu" (scroll wheel menu) resizes its width based on the text length of the current actions. If I can calculate the text width, then I can just manually resize the listbox every time I add/remove an item.

EDIT: what the shit? In testing, I have found that the ARMA monospace font (EtelkaMonospacePro) is not actually monospace. A 'W' is about 30% wider than an 'i'. Not cool BI! Tricking me like that.

Edited by ChronicSilence

Share this post


Link to post
Share on other sites

I didn't have any problems with EtelkaMonospace, refer to this video (it is kinda old though)

You can see that 'i's and 'w's seem to line up just fine

Share this post


Link to post
Share on other sites

Put two static text field controls one below the other, set the text of the first one to "iiiiiiiiiiiiiiiiiiii" and the second one to "WWWWWWWWWWWWWWWWWWWW", and you'll see that they gradually start to deviate in alignment.

Share this post


Link to post
Share on other sites

As a follow-up question, what about finding the width of a given StructuredText? Perhaps after using parseText there's a way to determine how wide the resultant text would be?

Share this post


Link to post
Share on other sites
As a follow-up question, what about finding the width of a given StructuredText? Perhaps after using parseText there's a way to determine how wide the resultant text would be?

As far as I know, there's no way to do this.

Going to give this a little bump. Any way to dynamically resize a control to its contents size?

Not sure if there's an easy way to do this, but what you can do is assign each letter a value that could correspond with the control's width and then add up all the values and set the control width with ctrlSetPostion and ctrlCommit.

There might also be a way to check if your control is wide enough using ctrlTextHeight, if the control isn't wide enough the text is bumped down to a new line so if you make sure the return value is below a certain amount then your control is wide enough, if not then it needs to be widened. That's purely anecdotal though since I haven't used that command before and there is no documentation on that wiki page past proper syntax.

Share this post


Link to post
Share on other sites
Using ctrlTextHeight is an interesting idea, thanks. Any idea what the "fixedWidth" property is for, described here: https://community.bistudio.com/wiki/DialogControls-Text? I tried using it but couldn't seem to make it do anything useful.

fixedWidth might possibly make it so that expanding a control has no effect, but I'm not really sure

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×