Class Spinner

All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class Spinner extends TextFieldComponent
A numeric text-field component with attached up/down arrow buttons that adjust the current value by a configurable step size within a bounded range. The value can also be edited directly via the text field or adjusted using the up/down arrow keys.
  • Field Details

    • ARROW_DOWN

      public static final FontIcon ARROW_DOWN
      Down-arrow icon shown on the decrement button.
    • ARROW_UP

      public static final FontIcon ARROW_UP
      Up-arrow icon shown on the increment button.
  • Constructor Details

    • Spinner

      public Spinner(double x, double y, double width, double height, double lowerBound, double upperBound, double startValue, double stepSize)
      Constructs a new spinner.
      Parameters:
      x - the x coordinate of the component
      y - the y coordinate of the component
      width - the width of the component
      height - the height of the component
      lowerBound - the lowest allowed value
      upperBound - the highest allowed value
      startValue - the initial value
      stepSize - the step size between adjacent values
  • Method Details

    • decrement

      public void decrement()
      Decreases the current value by one step, clamping to the lower bound.
    • getCurrentValue

      public BigDecimal getCurrentValue()
      Gets the current value of the spinner.
      Returns:
      the current value
    • getLowerBound

      public BigDecimal getLowerBound()
      Gets the lowest allowed value of the spinner.
      Returns:
      the lower bound
    • getStepSize

      public BigDecimal getStepSize()
      Gets the step size between adjacent spinner values.
      Returns:
      the step size
    • getUpperBound

      public BigDecimal getUpperBound()
      Gets the highest allowed value of the spinner.
      Returns:
      the upper bound
    • increment

      public void increment()
      Increases the current value by one step, clamping to the upper bound.
    • onValueChange

      public void onValueChange(Consumer<BigDecimal> cons)
      Registers a callback invoked whenever the spinner value changes.
      Parameters:
      cons - the change consumer
    • prepare

      public void prepare()
      Description copied from class: GuiComponent
      Prepare the GuiComponent and all its child Components (Makes the GuiComponent visible and adds mouse listeners.). This is, for example, done right before switching to a new screen.
      Overrides:
      prepare in class GuiComponent
    • setCurrentValue

      public void setCurrentValue(BigDecimal newValue)
      Sets the current value, clamped to the configured range, and notifies registered change listeners.
      Parameters:
      newValue - the new value
    • setLowerBound

      public void setLowerBound(BigDecimal lowerBound)
      Sets the lowest allowed value. If the current value is below the new bound, the current value is clamped to the new bound.
      Parameters:
      lowerBound - the new lower bound
    • setStepSize

      public void setStepSize(BigDecimal stepSize)
      Sets the step size between adjacent spinner values.
      Parameters:
      stepSize - the step size
    • setUpperBound

      public void setUpperBound(BigDecimal upperBound)
      Sets the highest allowed value. If the current value is above the new bound, the current value is clamped to the new bound.
      Parameters:
      upperBound - the new upper bound