Class Spinner
java.lang.Object
de.gurkenlabs.litiengine.gui.GuiComponent
de.gurkenlabs.litiengine.gui.ImageComponent
de.gurkenlabs.litiengine.gui.TextFieldComponent
de.gurkenlabs.litiengine.gui.Spinner
- All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final FontIconDown-arrow icon shown on the decrement button.static final FontIconUp-arrow icon shown on the increment button.Fields inherited from class TextFieldComponent
DOUBLE_FORMAT, INTEGER_FORMATFields inherited from class ImageComponent
BACKGROUND_DISABLED_INDEX, BACKGROUND_HOVER_INDEX, BACKGROUND_INDEX, BACKGROUND_PRESSED_INDEXFields inherited from class GuiComponent
ICON_FONT -
Constructor Summary
ConstructorsConstructorDescriptionSpinner(double x, double y, double width, double height, double lowerBound, double upperBound, double startValue, double stepSize) Constructs a new spinner. -
Method Summary
Modifier and TypeMethodDescriptionvoidDecreases the current value by one step, clamping to the lower bound.Gets the current value of the spinner.Gets the lowest allowed value of the spinner.Gets the step size between adjacent spinner values.Gets the highest allowed value of the spinner.voidIncreases the current value by one step, clamping to the upper bound.voidonValueChange(Consumer<BigDecimal> cons) Registers a callback invoked whenever the spinner value changes.voidprepare()Prepare the GuiComponent and all its child Components (Makes the GuiComponent visible and adds mouse listeners.).voidsetCurrentValue(BigDecimal newValue) Sets the current value, clamped to the configured range, and notifies registered change listeners.voidsetLowerBound(BigDecimal lowerBound) Sets the lowest allowed value.voidsetStepSize(BigDecimal stepSize) Sets the step size between adjacent spinner values.voidsetUpperBound(BigDecimal upperBound) Sets the highest allowed value.Methods inherited from class TextFieldComponent
canHandleInput, getCursor, getFormat, getMaxLength, getText, getTextToRender, handleTypedKey, onChangeConfirmed, render, setCursor, setFlickerDelay, setFormat, setMaxLength, setTextMethods inherited from class ImageComponent
getBackground, getHorizontalImagePadding, getImage, getImageAlign, getImageScaleInterpolation, getImageScaleMode, getImageValign, getSpritesheet, getSpritesheetScaleFactor, getSpritesheetScaleInterpolation, getSpritesheetScaleMode, getVerticalImagePadding, rescaleImage, setHeight, setHorizontalImagePadding, setImage, setImageAlign, setImageScaleInterpolation, setImageScaleMode, setImageValign, setSpritesheet, setSpritesheet, setSpritesheet, setSpritesheetScaleFactor, setSpritesheetScaleInterpolation, setSpritesheetScaleMode, setVerticalImagePadding, setWidthMethods inherited from class GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFocusedComponent, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasInputFocus, hasTextAntialiasing, hasTextShadow, initializeComponents, isAutoScaling, isEnabled, isFocusable, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onResolutionChanged, onTextChanged, removeListener, removeListener, setAutomaticLineBreaks, setAutoScaling, setDimension, setEnabled, setFocusable, setFont, setFontSize, setForwardMouseEvents, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setX, setY, suspend, toggleSelection, toggleSuspension
-
Field Details
-
ARROW_DOWN
Down-arrow icon shown on the decrement button. -
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 componenty- the y coordinate of the componentwidth- the width of the componentheight- the height of the componentlowerBound- the lowest allowed valueupperBound- the highest allowed valuestartValue- the initial valuestepSize- 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
Gets the current value of the spinner.- Returns:
- the current value
-
getLowerBound
Gets the lowest allowed value of the spinner.- Returns:
- the lower bound
-
getStepSize
Gets the step size between adjacent spinner values.- Returns:
- the step size
-
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
Registers a callback invoked whenever the spinner value changes.- Parameters:
cons- the change consumer
-
prepare
public void prepare()Description copied from class:GuiComponentPrepare 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:
preparein classGuiComponent
-
setCurrentValue
Sets the current value, clamped to the configured range, and notifies registered change listeners.- Parameters:
newValue- the new value
-
setLowerBound
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
Sets the step size between adjacent spinner values.- Parameters:
stepSize- the step size
-
setUpperBound
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
-