2008-05-01

ListBox Finished!

The ListBox and ScrollingListBox (a ListBox with a scrollbar) are finished. I’ve added some more functions for working with the options within a ListBox and an alphabetical sort routine (I was looking into sorts for something else today, so decided to add one in). The ScrollingListBox features both smooth scrolling (when the list is dragged) and jump scrolling (when the scrollbar is dragged). The previously untested theories about how the scrollbars would work in this situation have all turned out to accurate. Hurrah!

As I haven’t put one up in ages, here’s a screenshot:

Woopsi ListBox

Another quick change - John requested a way to change the default colours for the gadgets. There’s now a static “DefaultStyle” class that contains all of the default colour data. Altering the variables in this class will cause any gadgets constructed afterwards to use the changed values as their colour settings. There’s also a font pointer that, if set to anything other than NULL, Woopsi will use as the system font. Again, that should be set before you any construct any gadgets that should use the alternative font, as the gadgets make copies of all variables. The developer is responsible for deleting that font when it is no longer needed.

Here’s a screenshot of a nasty salmon version of Woopsi made by mucking about with the new DefaultStyle class:

Woopsi Alt Colours

Comments

ant on 2008-05-01 at 20:23 said:

Thanks, missed that one. Maybe I’ve got the warning level set wrongly? Anyhoo, it’s fixed now.

Jeff on 2008-05-01 at 21:03 said:

Minor gotcha on latest svn

Compiling defaultstyle.cpp /projects/Woopsi/woopsi/defaultstyle.cpp:10: error: ‘NULL’ was not declared in this scope make[1]: *** [defaultstyle.o] Error 1

Jeff on 2008-05-02 at 01:34 said:

I’ve been caught out like that because of timestamps and make not realising that headers had been changed. No big deal.

It might be a good idea to update the demo so that the list is in a window - at the moment, it looks like a bug, not a feature.

ant on 2008-05-02 at 05:55 said:

That’s true. I’ve just been marvelling at how Woopsi lets me have two scrolling gadgets on top of each other. :)

ant on 2008-05-09 at 11:32 said:

Just the ratio value that needs switching to s32?

Jeff on 2008-05-09 at 12:29 said:

Its taken me ages, but I found a crashing bug in the scrollbars (it took ages because I thought it was my List that was doing it). You haven’t tried a scrollbar bigger than 127 pixels, have you? Here’s the offending code…

// Calculate ratio (max fractional value of 255) u32 ratio = (rect.height <>= 8; newGripY += rect.y;

My problem was happening because the scrollbar was returning values from getValue() that were less than the minimum - indexing into negative values in my source array.

The problem? Integer overflow. My min and max were ‘20’ apart and the scrollbar was 168 pixels tall which gave a ratio of 2048. When you put in a new value of 21 (by clicking the down button when its near the bottom already), you get a newGripY value of -22528 and from there its all over. The bitshift down propagates the minus bit and you end up with a small, but still negative value.

Make it s32 (because there’s no guarantee that it won’t need to hold negative values - its initialised from an s16) and it all works again.

Jeff on 2008-05-09 at 12:30 said:

Oh, crap, HTML ate half my message again. I don’t want to go back and type it again…

Jeff on 2008-05-09 at 12:57 said:

No, the newGripY

Jeff on 2008-05-09 at 12:58 said:

Same problem in the horizontal scrollbar too, of course, though its newGripX over there…

ant on 2008-05-12 at 12:11 said:

Sorted.