| 118 | A spin button is used to select a number from within a numeric range. The user may click on the up/down arrows to the side of the field to change the value. |
| 119 | |
| 120 | Using a spin button means first creating an instance of the 'Adjustment' class: this holds the min/max values for the range, as well as information on how large a jump the user can make. The 'Adjustment' class takes 6 float parameters: |
| 121 | |
| 122 | * the initial value |
| 123 | * the minimum value |
| 124 | * the maximum value |
| 125 | * the increment for a single step (e.g. one click on an arrow) |
| 126 | * the increment for a page-up or page-down keypress |
| 127 | * page size (but cobra tells me using any value other than 0 for this parameter is deprecated) |
| 128 | |
| 129 | The spin button takes three parameters: |
| 130 | |
| 131 | * an instance of the 'Adjustment' class |
| 132 | * the 'climb rate', which affects the acceleration when you hold a button down |
| 133 | * the number of decimal places to show |
| 134 | |
| 135 | The 'value' attribute of the spin button is used to retrieve the current value. |
| 136 | |
| 137 | To create a spin box which covers the numbers 0 to 100, and produces integer values: |
| 138 | |
| 139 | {{{ |
| 140 | #!cobra |
| 141 | model = Adjustment(50.0f, 0.0f, 100.0f, 1.0f, 10.0f, 0f) |
| 142 | _spinbutton = SpinButton(model, 1.0f, 0) |
| 143 | }}} |
| 144 | |
| 145 | To create a spin box which covers a floating point range -10.000 to 10.000, producing float values at intervals of 0.001: |
| 146 | {{{ |
| 147 | #!cobra |
| 148 | model = Adjustment(0.0f, -10.0f, 10.0f, 0.001f, 1.0f, 0f) |
| 149 | _spinbutton = SpinButton(model, 1.0f, 3) |
| 150 | _spinbutton.snapToTicks = true # used to round entries such as 1.2341 to 1.234 |
| 151 | }}} |
| 152 | |
| 153 | |
| 154 | [[Image(spinbutton.png)]] |