9.10 Spin Buttons
The Spin Button widget is generally used to allow the user to select a value from a range of numeric values. It consists of a text entry box with up and down arrow buttons attached to the side. Selecting one of the buttons causes the value to "spin" up and down the range of possible values. The entry box may also be edited directly to enter a specific value.
The Spin Button allows the value to have zero or a number of decimal places and to be incremented/decremented in configurable steps. The action of holding down one of the buttons optionally results in an acceleration of change in the value according to how long it is depressed.
The Spin Button uses an Adjustment object to hold information about the range of values that the spin button can take. This makes for a powerful Spin Button widget.
Recall that an adjustment widget is created with the following function, which illustrates the information that it holds:
|
These attributes of an Adjustment are used by the Spin Button in the following way:
value: initial value for the Spin Button
lower: lower range value
upper: upper range value
step_increment: value to increment/decrement when pressing mouse button 1 on a button
page_increment: value to increment/decrement when pressing mouse button 2 on a button
page_size: unused
Additionally, mouse button 3 can be used to jump directly to the upper or lower values when used to select one of the buttons. Lets look at how to create a Spin Button:
|
The climb_rate argument take a value between 0.0 and 1.0 and indicates the amount of acceleration that the Spin Button has. The digits argument specifies the number of decimal places to which the value will be displayed.
A Spin Button can be reconfigured after creation using the following function:
|
The spin_button argument specifies the Spin Button widget that is to be reconfigured. The other arguments are as specified above.
The adjustment can be set and retrieved independantly using the following two functions:
|
The number of decimal places can also be altered using:
|
The value that a Spin Button is currently displaying can be changed using the following function:
|
The current value of a Spin Button can be retrieved as either a floating point or integer value with the following functions:
|
If you want to alter the value of a Spin Value relative to its current value, then the following function can be used:
|
The direction parameter can take one of the following values:
GTK_SPIN_STEP_FORWARD
GTK_SPIN_STEP_BACKWARD
1GTK_SPIN_PAGE_FORWARD
GTK_SPIN_PAGE_BACKWARD
GTK_SPIN_HOME
GTK_SPIN_END
GTK_SPIN_USER_DEFINED
This function packs in quite a bit of functionality, which I will attempt to clearly explain. Many of these settings use values from the Adjustment object that is associated with a Spin Button.