Chapter 8. Adjustments

GTK has various widgets that can be visually adjusted by the user using the mouse or the keyboard, such as the range widgets, described in the Range Widgets section. There arre also a few widgets that display some adjustable portion of a larger area of data, such as the text widget and the viewport widget.

Obviously, an application needs to be able to react to changes the user makes in range widgets. One way to do this would be to have each widget emit its own type of signal when its adjustment changes, and either pass the new value to the signal handler, or require it to look inside the widget's data structure in order to ascertain the value. You may also want to connect the adjustments of several widgets together, so that adjusting one adjusts the others. The most obvious example of this is connecting a scrollbar to to a panning veiwport or a scrolling text area. If each widget has it's own way of setting or getting the adjustment value, then the programmer may have to write their own signal handlers to translate between the output of one widget's signal and the "input" of another's adjustment setting method.

GTK solves this problem (as well as Ruby-GNOME2 by default) using the Gtk::Adjustment object, which is not a widget, but a way for widgets to store and pass information in an abstract and flexible form. The most obvious use of Gtk::Adjustment is to store the configuration parameters and values of range widgets, such as scrollbars and scale controls. However, since Gtk::Adjustments are derived from Gtk::Object, they have some special powers beyond those of normal data structures. Most importantly, they can emit signals, just like widgets, and these signals can also be used not only to allow your program to react to user input on adjustable widgets, but also to propagate adjustment values transparently between adjustable widgets.

You will see how adjustments fit in when you see the other widgets that incorporate them: Progress Bars, Viewports, Scrolled Windows,and others.


Prev Next