typedef control scrollbar; typedef void (*scrollfn)(scrollbar s, int position);
scrollbar newscrollbar(rect r, int max, int size_shown, scrollfn fn); void changescrollbar(scrollbar s, int pos, int max, int size_shown); int getvalue(scrollbar s);
The newscrollbar function creates a scrollbar which can be used to scroll through text or to change some value within the program. The scrollbar will fill the given rectangle, and will scroll vertically if the rectangle is taller than it is wide, and horizontally otherwise. Manipulating the scrollbar with the mouse changes the scroll position, which has a minimum value of zero (at the left or top of the scroll bar), and a maximum value given by max.
The amount of some value which is displayed by the scrollbar can be set with the size_shown argument. When the user clicks in the scrollbar to make the scroll 'thumb' position jump, it will jump by this amount. For instance, in a text window which scrolls vertically, if 24 lines out of an 84 line document is visible at any one time, size_shown would be set to 24 and max to 84-24, since the top-most line of text on the screen at any time can only range from zero at the start of the document, to 60 at the end. When the user clicks in the scrollbar (other than on the 'thumb') the scroll position will increase or decrease by 24.
Every time the scrollbar position changes, the call-back function fn is called. This function is passed two parameters, the first being the scrollbar itself, and the second being the current position, which ranges from zero to max.
The changescrollbar function changes the values used by the scrollbar. It will reset the scrollbar's position pos, its maximum value max and the size_shown value.
The getvalue function returns the scrollbar's current position.