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 net.minecraft.text.Text label) Constructs a slider.WLabeledSlider(int min, int max, @Nullable net.minecraft.text.Text label) Constructs a horizontal slider. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.@Nullable net.minecraft.text.TextgetLabel()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(net.minecraft.client.util.math.MatrixStack matrices, 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.voidsetSize(int x, int y) Sets the size of this widget.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, setValue, setValue, setValueChangeListener, tick, updateValueCoordRatiosMethods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, canHover, cycleFocus, getAbsoluteX, getAbsoluteY, 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, 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
public WLabeledSlider(int min, int max, Axis axis, @Nullable @Nullable net.minecraft.text.Text label) 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
-
setSize
public void setSize(int x, int y) Description copied from class:WWidgetSets the size of this widget.Overriding methods may restrict one of the dimensions to be a constant value, for example
super.setSize(x, 20).- Overrides:
setSizein classWAbstractSlider- Parameters:
x- the new widthy- the new height
-
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
@Environment(CLIENT) public void paint(net.minecraft.client.util.math.MatrixStack matrices, int x, int y, int mouseX, int mouseY) Description copied from class:WWidgetPaints this widget. -
addNarrations
@Environment(CLIENT) public void addNarrations(net.minecraft.client.gui.screen.narration.NarrationMessageBuilder builder) 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
-