Tuesday, July 21, 2009

Minimum size on a scrollbar thumb, using a ProgrammaticSkin

I had to make a programmatic skin for a scroll bar. I don't think this is something most people should do, frankly. Graphic skinning is much easier and more flexible, and allows programmers to program and artists to...well, art. Why is there no verb for making art, I wonder? But I digress.

Anyway, this was a special case. I needed complete control over the colors within the scrollbar, and couldn't use a ColorFilter, as I was under a ColorFilterInjunctivitis jinx brought on by re-reading Harry Potter way too many times or something.

So anyway, here's the problem: there doesn't seem to be any way to set the minimum size of a scrollbar thumb through CSS. Or if there is, I can't find it. It looks to be fairly hard-coded in ScrollBar.as.

Here's my solution. I can't say I'm proud, but the damn thing works. Even if it is a butt-ugly solution, my hope here is that my blog will one day get famous, I'll be acknowledged as an expert in the field, and then this solution will be regarded as the "official workaround" and not an egregious hack.


public class VScrollBarSkin extends ProgrammaticSkin
{
private static const THUMB_MIN_HEIGHT:Number = 20;
override public function get measuredHeight():Number
{
// way to style this, it's not at all obvious.
if (parent && (parent is ScrollThumb))
ScrollThumb(parent).minHeight = THUMB_MIN_HEIGHT;

return SKIN_HEIGHT;
}

No comments:

Post a Comment