Scrollbars are still in progress. I hit a couple of snags along the way, one of which I’ve solved, and one which I haven’t.
The first problem was implementing the “maximum” and “minimum” values that Jeff suggested. The idea is that the developer passes two values to the scrollbar - maximum and minimum values - and the scrollbar automatically works out (based on its own height) how large its grip should be and the value of each pixel within the gutter. Using a simple ratio calculation we can work all of this out.
This worked fine when the scrollbar is thought of as a slider, but it falls apart when the scrollbar is, well, a scrollbar. In the first scenario, the grip always has a value of “1”. So, if we give it a range of values between 0 and 9, and make the scrollbar 100 pixels high, the grip will make itself 10 pixels high. Dragging the grip increases or decreases the value of the scrollbar as a whole by 1.
Imagine that this scrollbar is attached to a textbox that is 9 pixels high. Now we have a problem - the scrollbar will resize itself and suggest that the textbox contains 10 screens of text, but in fact there’s one screen of text and an additional row of pixels that can be scrolled into view.
This had me stumped for a while until I realised that I needed to pass into the scrollbar the height of the viewport into the scrollable area. At that point the calculations all made sense.
The scrollbar can still be used as a slider simply by setting the viewport size (currently unhelpfully called the “page size”) to 1.
The second snag is more tricky. When I wrote the ScrollablePanel gadget, I implemented the minimum and maximum scrollable values as the limits within which an area could be scrolled. So, if you have a ScrollablePanel with a minimum value of 0 and a maximum value of 1, that panel can be scrolled by 1 pixel.
The MultiLineTextBox and Scrollbar gadgets work differently, though. The textbox provides a viewport into a larger scrollable region with its own width and height. The region should not scroll unless its height is larger than the surrounding viewport, so the scrolling values have to be adjusted to compensate for the height of the viewport. Unfortunately, to make the Scrollbar more generally useful, that also has to take into account the height of the viewport.
This leaves me with a host of problems:
- The ScrollablePanel and MultiLineTextBox using two different and incompatible models for their scrollable regions
- The ScrollablePanel and Scrollbar are also using incompatible models
- The workarounds implemented in the MultiLineTextBox break the correct functionality implemented in the Scrollbar.
I need to change the ScrollablePanel to match the MultiLineTextBox, then strip out the workarounds, and everything should work.