# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.section Widgets
.topic widget.spinner
.title Spinner
.toc 0 Spinner
.index Spinner
.index wgtSpinner
.index wgtSpinnerSetValue
.index wgtSpinnerGetValue
.index wgtSpinnerSetRealMode

.h2 Spinner

A numeric input with up/down buttons for incrementing and decrementing a value within a range. Supports both integer and floating-point (real) modes.

Header: widgets/spinner.h

.h3 Creation

.code
WidgetT *sp = wgtSpinner(parent, 0, 100, 1);
.endcode

.h3 API Functions

.index wgtSpinnerSetRange
.index wgtSpinnerSetStep
.index wgtSpinnerGetRealValue
.index wgtSpinnerSetRealValue
.index wgtSpinnerSetRealRange
.index wgtSpinnerSetRealStep
.index wgtSpinnerSetDecimals

.table
  Function                                                Description
  --------                                                -----------
  WidgetT *wgtSpinner(parent, minVal, maxVal, step)       Create a spinner with the given integer range and step size.
  void wgtSpinnerSetValue(w, value)                       Set the integer value.
  int32_t wgtSpinnerGetValue(w)                           Get the current integer value.
  void wgtSpinnerSetRange(w, minVal, maxVal)              Set the integer range.
  void wgtSpinnerSetStep(w, step)                         Set the integer step size.
  void wgtSpinnerSetRealMode(w, enable)                   Switch to floating-point mode.
  double wgtSpinnerGetRealValue(w)                        Get the current floating-point value.
  void wgtSpinnerSetRealValue(w, value)                   Set the floating-point value.
  void wgtSpinnerSetRealRange(w, minVal, maxVal)          Set the floating-point range.
  void wgtSpinnerSetRealStep(w, step)                     Set the floating-point step size.
  void wgtSpinnerSetDecimals(w, decimals)                 Set the number of decimal places displayed in real mode.
.endtable

.h3 API Struct (wgtRegisterApi "spinner")

.table
  Slot           Function
  ----           --------
  create         wgtSpinner
  setValue       wgtSpinnerSetValue
  getValue       wgtSpinnerGetValue
  setRange       wgtSpinnerSetRange
  setStep        wgtSpinnerSetStep
  setRealMode    wgtSpinnerSetRealMode
  getRealValue   wgtSpinnerGetRealValue
  setRealValue   wgtSpinnerSetRealValue
  setRealRange   wgtSpinnerSetRealRange
  setRealStep    wgtSpinnerSetRealStep
  setDecimals    wgtSpinnerSetDecimals
.endtable

.h3 Properties (BASIC Interface)

.table
  Property     Type       Access       Description
  --------     ----       ------       -----------
  Value        Integer    Read/Write   Current integer value.
  RealMode     Boolean    Read/Write   Whether floating-point mode is active.
  Decimals     Integer    Read/Write   Number of decimal places displayed in real mode.
.endtable

.h3 Methods (BASIC Interface)

.table
  Method                Description
  ------                -----------
  SetRange min%, max%   Set the integer range.
  SetStep step%         Set the integer step size.
.endtable

.h3 Events

.table
  Callback     Description
  --------     -----------
  onChange     Fires when the value changes.
.endtable

.h3 Default Event

"Change" (VB basName: SpinButton, namePrefix: Spin).
