Spinner

The Spinner widget displays a small spinning animation, commonly used to indicate ongoing activity when the exact progress is unknown—an alternative to ProgressBar for indefinite loading states.

To control the animation, call:

  • Spinner.start to begin spinning
  • Spinner.stop to halt the animation

Example

samples/gtk/widgets/src/nativeMain/kotlin/org/gtkkn/samples/gtk/widgets/Spinner.kt
fun spinner(): Widget {
    val spinner = Spinner().apply {
        setSizeRequest(100, 100)
    }

    val toggleButton = ToggleButton(label = "Start Spinning")

    // bind the spinning property of the spinner to the active property of the toggleButton
    toggleButton.bindProperty("active", spinner, "spinning", BindingFlags.DEFAULT)

    // update the text when the button is spinning
    toggleButton.connectClicked {
        if (toggleButton.active) {
            toggleButton.setLabel("Stop Spinning")
        } else {
            toggleButton.setLabel("Start Spinning")
        }
    }

    val box = Box(Orientation.VERTICAL, 20).apply {
        setMargins(20)
        append(spinner)
        append(toggleButton)
    }

    return box
}