Suggestion: Listbox background color

Started by RickJ, Thu 23/03/2006 05:20:50

Previous topic - Next topic

RickJ

There are a number of listbox suggestions on the tracker so here are a couple more.

  • Background Color - Currently the listbox has a transparent background, would it be possible to add the ability to specify the background color?   The transparent background makes it very difficult to do "drop down lists" and other sorts of dynamically sized lists.

  • Resizing - Currently it's possible to get the number of items in the list  and how many items are displayed.  To resize the list to display N items then you must calculate how many pixels are required.   A function to resize the list height so that a specified number of items are displayed would be really handy, if easy and practical to implement.   If not, the calculatoion  is do able in script, just not very pretty.

    [edit]
    re: Resizing - Well I guess it's not that ugly but still it's not as simple as a one liner though ...
    Code: ags
    
    int height=0;
    WinBluListbox.Height = 0;
    while (WinBluListbox.ItemCount>gListbox.RowCount) {
          height = height+5;
          WinBluListbox.Height = height;
    }
    

    [/edit]

    As always thanks for the listen. ;)
    RickJ



Ashen

Couldn't that be reduced to:
Code: ags

WinBluListbox.Height = (WinBluListbox.ItemCount * 5);

(Or gListbox.ItemCount, which you used. Although surely that'd be an infinite loop?)

But I like the background colour for ListBoxes suggestion. While we're at it, could it also include TextBoxes and Labels (and possibly Inventory Windows)?
I know what you're thinking ... Don't think that.

strazer


RickJ

Quote
WinBluListbox.Height = (WinBluListbox.ItemCount * 5);
Only if the font used happened to be 5 pixels tall, and then you still haven't accounted for the top and bottom margins.   Currently there is not way to fetch the the font from the listbox so there isn't a way to know how many pixels to use for the multiplier.  A 5 poixel increment was chosen to decrease the number of iterations it takes to set the height and because 5 pixels is not very perceptable to the eye with regard to the height of a listbox. 

Quote
(Or gListbox.ItemCount, which you used. Although surely that'd be an infinite loop?)
Hardly inifinte.  The loop increases the listbox height until all of the elements in the list are in view.  There is subsequent error checking, not shown,  that limits the max size so that it fit's in the viewport.

Ashen

QuoteOnly if the font used happened to be 5 pixels tall
Ah, OK. I was assuming you knew 5 to be the font height (although it did seem a bit small). Even so, on a Box-by-Box basis, surely you'll know what font you used, and could work out the necessary difference and use that plus a fixed amount for the margins instead? I agree that a ListBox.SetRowCount(NumRows) function would be better, but the loop just seems redundant. (Although I should say, I've not tried it so I could be completely wrong.)

QuoteHardly inifinte.  The loop increases the listbox height until all of the elements in the list are in view.
I got the idea, but it looks like you're altering the size of WinBluListBox, while checking against gListbox.RowCount - and I can't see where that changes, so I got an infinite loop. I sort of assumed it was a typo, or is there something in the error checking that I've missed?

strazer:
I though they must be on already, but couldn't find them. Thanks for pointing them out.
I know what you're thinking ... Don't think that.

RickJ

#5
Quote
Even so, on a Box-by-Box basis, surely you'll know what font you used, and could work out the necessary difference and use that plus a fixed amount for the margins instead?
Since this is a script module meant for general consumption I have no way of knowing what font someone may use in the future.  I agree that the margins could probably be easily fudged.

Quote
I got the idea, but it looks like you're altering the size of WinBluListBox, while checking against gListbox.RowCount - and I
Thanks you found a bug for me.   WinBluListBox is a pointer variable and should be used in all instances.   I hadn't caught it before because gListBox is the actual control pointer and it value gets copied to the WinBluListBox variable.  Script above has been corrected.  Thanks.


Pumaman

Background colour -- this is a reasonable suggestion, as strazer points out it is already requested for other types of controls

ResizeToXRows() seems like a bit too specialized of a function to include in AGS. However, perhaps a ListBox.Font property would help?

RickJ

Thanks.  The first is probably more important/needed than the second item.  Your proposal for the second item sounds reasonable. 


SMF spam blocked by CleanTalk