|
| 1 | +# Numeric input widgets |
| 2 | + |
| 3 | +Gtk4 provides a few different widgets for user input of numeric values. |
| 4 | + |
| 5 | +## [GtkScale](https://docs.gtk.org/gtk4/class.Scale.html) |
| 6 | + |
| 7 | +The `GtkScale` widget allows users to select a value by sliding a knob within a predefined range. It is a subclass of [`GtkRange`](https://docs.gtk.org/gtk4/class.Range.html) and displays a slider and, optionally, text showing the current value. |
| 8 | + |
| 9 | +A `GtkScale` is typically created using one of the following constructors: |
| 10 | + |
| 11 | + * `GtkScale(orientation, range::AbstractRange)` creates a new `GtkScale` with the specified orientation (`:h`/`Orientation_HORIZONTAL` or `:v`/`Orientation_VERTICAL`), with the range of allowed values defined by `range`. |
| 12 | + * `GtkScale(orientation, min_val, max_val, step)` creates a new `GtkScale` with the range of allowed values defined by `min_val`, `max_val`, and `step`. |
| 13 | + * `GtkScale(orientation, adj::GtkAdjustment)` creates a new `GtkScale` using an existing [`GtkAdjustment`](https://docs.gtk.org/gtk4/class.Adjustment.html) object to manage the range and value. |
| 14 | + |
| 15 | +### Example |
| 16 | + |
| 17 | +```julia |
| 18 | +using Gtk4 |
| 19 | + |
| 20 | +# Create a horizontal scale for integers from 0 to 100 |
| 21 | +scale = GtkScale(:h, 0.0, 100.0, 1.0) |
| 22 | + |
| 23 | +# Set the initial value |
| 24 | +Gtk4.value(scale, 50.0) |
| 25 | +``` |
| 26 | + |
| 27 | +### Useful properties and signals |
| 28 | + |
| 29 | +| property | type | | |
| 30 | +| :--- | :--- | :--- | |
| 31 | +| `value` | `Float64` | The current value of the slider. Get/set using `Gtk4.value(widget)` and `Gtk4.value(widget, val)`. | |
| 32 | +| `draw_value` | `Bool` | Whether the current value is displayed next to the slider. Defaults to `false`. | |
| 33 | +| `digits` | `Int` | The number of decimal places to display for the value. | |
| 34 | +| `adjustment` | `GtkAdjustment` | The `GtkAdjustment` managing the scale's range, value, and step. | |
| 35 | + |
| 36 | +The most important signal for interacting with the scale's value is inherited from `GtkRange`: |
| 37 | + |
| 38 | +| signal | arguments | returns | | |
| 39 | +| :--- | :--- | :--- | :--- | |
| 40 | +| "value-changed" | self::GtkScale | `Nothing` | Emitted when the value is changed | |
| 41 | + |
| 42 | +## [GtkSpinButton](https://docs.gtk.org/gtk4/class.SpinButton.html) |
| 43 | + |
| 44 | +The `GtkSpinButton` widget allows a user to select a value from a numerical range by typing in a text field or by clicking a pair of up/down buttons. |
| 45 | +A `GtkSpinButton` is typically created using one of the following constructors: |
| 46 | + |
| 47 | + * `GtkSpinButton(min_val, max_val, step_increment)` creates a new `GtkSpinButton` with the specified minimum value `min_val`, maximum value `max_val`, and increment size `step_increment`. |
| 48 | + |
| 49 | + * `GtkSpinButton(adj::GtkAdjustment, climb_rate::Real, digits::Integer)` creates a new `GtkSpinButton` using an existing `GtkAdjustment` object to manage the range and value. The argument `climb_rate` is an internal scaling factor applied to the step increment when the arrow buttons are held down, while `digits` is the number of decimal places to display. |
| 50 | + |
| 51 | +### Example |
| 52 | + |
| 53 | +```julia |
| 54 | +using Gtk4 |
| 55 | + |
| 56 | +# Create a spin button for integer values from 1 to 10 with step 1 |
| 57 | +spin = GtkSpinButton(1.0, 10.0, 1.0) |
| 58 | + |
| 59 | +# Set the initial value |
| 60 | +Gtk4.value(spin, 5.0) |
| 61 | +``` |
| 62 | + |
| 63 | +### Useful properties and signals |
| 64 | + |
| 65 | +| property | type | | |
| 66 | +| :--- | :--- | :--- | |
| 67 | +| `value` | `Float64` | The current numerical value of the widget. Get/set using `Gtk4.value(widget)` and `Gtk4.value(widget, val)`. | |
| 68 | +| `adjustment` | `GtkAdjustment` | The object managing the range, value, and step increment. | |
| 69 | +| `digits` | `Int` | The number of decimal places to display. | |
| 70 | +| `numeric` | `Bool` | Whether only numeric characters are allowed in the entry field. Defaults to `false`. | |
| 71 | + |
| 72 | +The most common signal for tracking changes is: |
| 73 | + |
| 74 | +| signal | arguments | returns | | |
| 75 | +| :--- | :--- | :--- | :--- | |
| 76 | +| "value-changed" | self::GtkSpinButton | `Nothing` | Emitted when the value is changed. | |
0 commit comments