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
Modifier and TypeClassDescriptionstatic interface
A 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
ConstructorDescriptionWLabeledSlider
(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 TypeMethodDescriptionvoid
addNarrations
(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.LabelUpdater
of this slider.protected int
Returns the thumb size along the slider axis.protected boolean
isMouseInsideBounds
(int x, int y) Checks if the mouse cursor is close enough to the slider that the user can start dragging.protected void
onValueChanged
(int value) void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.void
Sets the label of this slider.void
setLabelAlignment
(HorizontalAlignment labelAlignment) Sets the text alignment of this slider's label.void
setLabelUpdater
(@Nullable WLabeledSlider.LabelUpdater labelUpdater) Sets theWLabeledSlider.LabelUpdater
of 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, updateValueCoordRatios
Methods 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:
onValueChanged
in 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.LabelUpdater
of this slider.- Returns:
- the label updater
-
setLabelUpdater
Sets theWLabeledSlider.LabelUpdater
of this slider.- Parameters:
labelUpdater
- the new label updater
-
getThumbWidth
protected int getThumbWidth()Description copied from class:WAbstractSlider
Returns the thumb size along the slider axis.- Specified by:
getThumbWidth
in classWAbstractSlider
- Returns:
- the thumb size along the slider axis
-
isMouseInsideBounds
protected boolean isMouseInsideBounds(int x, int y) Description copied from class:WAbstractSlider
Checks if the mouse cursor is close enough to the slider that the user can start dragging.- Specified by:
isMouseInsideBounds
in classWAbstractSlider
- Parameters:
x
- the mouse x positiony
- the mouse y position- Returns:
- if the cursor is inside dragging bounds
-
paint
Description copied from class:WWidget
Paints this widget. -
addNarrations
Description copied from class:WWidget
Adds 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:
addNarrations
in classWAbstractSlider
- Parameters:
builder
- the narration builder, cannot be null
-