Class WLabeledSlider
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WAbstractSlider
io.github.cottonmc.cotton.gui.widget.WLabeledSlider
A vanilla-style labeled slider widget.
In addition to the standard slider listeners, labeled sliders also support "label updaters" that can update the label when the value is changed.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA label updater updates the label of a slider based on the current value.Nested classes/interfaces inherited from class io.github.cottonmc.cotton.gui.widget.WAbstractSlider
WAbstractSlider.Direction -
Field Summary
Fields inherited from class io.github.cottonmc.cotton.gui.widget.WAbstractSlider
axis, coordToValueRatio, direction, dragging, max, min, value, valueToCoordRatio -
Constructor Summary
ConstructorsConstructorDescriptionWLabeledSlider(int min, int max) Constructs a horizontal slider with no default label.WLabeledSlider(int min, int max, Axis axis) Constructs a slider with no default label.WLabeledSlider(int min, int max, Axis axis, @Nullable Text label) Constructs a slider.WLabeledSlider(int min, int max, @Nullable Text label) Constructs a horizontal slider. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.getLabel()Gets the current label of this slider.Gets the text alignment of this slider's label.Gets theWLabeledSlider.LabelUpdaterof this slider.protected intReturns the thumb size along the slider axis.protected booleanisMouseInsideBounds(int x, int y) Checks if the mouse cursor is close enough to the slider that the user can start dragging.protected voidonValueChanged(int value) voidpaint(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.voidSets the label of this slider.voidsetLabelAlignment(HorizontalAlignment labelAlignment) Sets the text alignment of this slider's label.voidsetLabelUpdater(@Nullable WLabeledSlider.LabelUpdater labelUpdater) Sets theWLabeledSlider.LabelUpdaterof this slider.Methods inherited from class io.github.cottonmc.cotton.gui.widget.WAbstractSlider
canFocus, canResize, getAxis, getDirection, getDraggingFinishedListener, getMaxValue, getMinValue, getValue, getValueChangeListener, isDecreasingKey, isDragging, isIncreasingKey, onClick, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseScroll, onMouseUp, setDirection, setDraggingFinishedListener, setMaxValue, setMinValue, setSize, setValue, setValue, setValueChangeListener, tick, updateValueCoordRatiosMethods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onFocusGained, onFocusLost, onHidden, onMouseMove, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, shouldRenderInDarkMode, validate
-
Constructor Details
-
WLabeledSlider
public WLabeledSlider(int min, int max) Constructs a horizontal slider with no default label.- Parameters:
min- the minimum valuemax- the maximum value
-
WLabeledSlider
Constructs a slider with no default label.- Parameters:
min- the minimum valuemax- the maximum valueaxis- the slider axis
-
WLabeledSlider
Constructs a slider.- Parameters:
min- the minimum valuemax- the maximum valueaxis- the slider axislabel- the slider label (can be null)
-
WLabeledSlider
Constructs a horizontal slider.- Parameters:
min- the minimum valuemax- the maximum valuelabel- the slider label (can be null)
-
-
Method Details
-
getLabel
Gets the current label of this slider.- Returns:
- the label
-
setLabel
Sets the label of this slider.- Parameters:
label- the new label
-
onValueChanged
protected void onValueChanged(int value) - Overrides:
onValueChangedin classWAbstractSlider
-
getLabelAlignment
Gets the text alignment of this slider's label.- Returns:
- the alignment
-
setLabelAlignment
Sets the text alignment of this slider's label.- Parameters:
labelAlignment- the new alignment
-
getLabelUpdater
Gets theWLabeledSlider.LabelUpdaterof this slider.- Returns:
- the label updater
-
setLabelUpdater
Sets theWLabeledSlider.LabelUpdaterof this slider.- Parameters:
labelUpdater- the new label updater
-
getThumbWidth
protected int getThumbWidth()Description copied from class:WAbstractSliderReturns the thumb size along the slider axis.- Specified by:
getThumbWidthin classWAbstractSlider- Returns:
- the thumb size along the slider axis
-
isMouseInsideBounds
protected boolean isMouseInsideBounds(int x, int y) Description copied from class:WAbstractSliderChecks if the mouse cursor is close enough to the slider that the user can start dragging.- Specified by:
isMouseInsideBoundsin classWAbstractSlider- Parameters:
x- the mouse x positiony- the mouse y position- Returns:
- if the cursor is inside dragging bounds
-
paint
Description copied from class:WWidgetPaints this widget. -
addNarrations
Description copied from class:WWidgetAdds the narrations of this widget to a narration builder. Narrations will only apply if this widget is narratable.The widget needs to be focusable or hoverable, and also be focused/hovered for narrations to be added.
- Overrides:
addNarrationsin classWAbstractSlider- Parameters:
builder- the narration builder, cannot be null
-