public abstract class WAbstractSlider extends WWidget
You can set two listeners on a slider:
| Modifier and Type | Class and Description |
|---|---|
static class |
WAbstractSlider.Direction
The direction enum represents all four directions a slider can face.
|
| Modifier and Type | Field and Description |
|---|---|
protected Axis |
axis |
protected float |
coordToValueRatio
A coordinate:value ratio.
|
protected WAbstractSlider.Direction |
direction |
protected boolean |
dragging
True if the user is currently dragging the thumb.
|
protected int |
max |
protected int |
min |
protected int |
value |
protected float |
valueToCoordRatio
A value:coordinate ratio.
|
| Modifier | Constructor and Description |
|---|---|
protected |
WAbstractSlider(int min,
int max,
Axis axis) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canFocus()
Tests whether this widget can have the focus in the GUI.
|
boolean |
canResize()
Checks whether this widget can be resized using
WWidget.setSize(int, int). |
Axis |
getAxis() |
WAbstractSlider.Direction |
getDirection()
Gets the direction of this slider.
|
@Nullable java.util.function.IntConsumer |
getDraggingFinishedListener() |
int |
getMaxValue() |
int |
getMinValue() |
protected abstract int |
getThumbWidth() |
int |
getValue() |
@Nullable java.util.function.IntConsumer |
getValueChangeListener() |
static boolean |
isDecreasingKey(int ch,
WAbstractSlider.Direction direction)
Tests if the key should decrease sliders with the specified direction.
|
boolean |
isDragging()
Tests whether the user is dragging this slider.
|
static boolean |
isIncreasingKey(int ch,
WAbstractSlider.Direction direction)
Tests if the key should increase sliders with the specified direction.
|
protected abstract boolean |
isMouseInsideBounds(int x,
int y)
Checks if the mouse cursor is close enough to the slider that the user can start dragging.
|
InputResult |
onClick(int x,
int y,
int button)
Notifies this widget that the mouse has been pressed and released, both while inside its bounds.
|
void |
onKeyPressed(int ch,
int key,
int modifiers)
Notifies this widget that a key has been pressed.
|
void |
onKeyReleased(int ch,
int key,
int modifiers)
Notifies this widget that a key has been released
|
InputResult |
onMouseDown(int x,
int y,
int button)
Notifies this widget that the mouse has been pressed while inside its bounds
|
InputResult |
onMouseDrag(int x,
int y,
int button,
double deltaX,
double deltaY)
Notifies this widget that the mouse has been moved while pressed and inside its bounds.
|
InputResult |
onMouseScroll(int x,
int y,
double amount)
Notifies this widget that the mouse has been scrolled inside its bounds.
|
InputResult |
onMouseUp(int x,
int y,
int button)
Notifies this widget that the mouse has been released while inside its bounds
|
protected void |
onValueChanged(int value) |
void |
setDirection(WAbstractSlider.Direction direction)
Sets the direction of this slider.
|
void |
setDraggingFinishedListener(@Nullable java.util.function.IntConsumer draggingFinishedListener) |
void |
setMaxValue(int max) |
void |
setMinValue(int min) |
void |
setSize(int x,
int y)
Sets the size of this widget.
|
void |
setValue(int value)
Sets the slider value without calling listeners.
|
void |
setValue(int value,
boolean callListeners)
Sets the slider value.
|
void |
setValueChangeListener(@Nullable java.util.function.IntConsumer valueChangeListener) |
void |
tick()
Executes a client-side tick for this widget.
|
addPainters, addTooltip, createPeers, cycleFocus, getAbsoluteX, getAbsoluteY, getHeight, getHost, getParent, getWidth, getX, getY, hit, isActivationKey, isFocused, isWithinBounds, onCharTyped, onFocusGained, onFocusLost, onHidden, onMouseMove, onShown, paint, releaseFocus, renderTooltip, requestFocus, setHost, setLocation, setParent, validateprotected int min
protected int max
protected final Axis axis
protected WAbstractSlider.Direction direction
protected int value
protected boolean dragging
protected float valueToCoordRatio
protected float coordToValueRatio
protected WAbstractSlider(int min,
int max,
Axis axis)
protected abstract int getThumbWidth()
protected abstract boolean isMouseInsideBounds(int x,
int y)
x - the mouse x positiony - the mouse y positionpublic void setSize(int x,
int y)
WWidgetOverriding methods may restrict one of the dimensions to be
a constant value, for example super.setSize(x, 20).
public boolean canResize()
WWidgetWWidget.setSize(int, int).public boolean canFocus()
WWidget@Environment(value=CLIENT) public InputResult onMouseDown(int x, int y, int button)
WWidgetonMouseDown in class WWidgetx - The X coordinate of the event, in widget-space (0 is the left edge of this widget)y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY)
WWidgetonMouseDrag in class WWidgetx - The X coordinate of the event, in widget-space (0 is the left edge of this widget)y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)deltaX - The amount of dragging on the X axisdeltaY - The amount of dragging on the Y axisInputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onClick(int x, int y, int button)
WWidgetonClick in class WWidgetx - The X coordinate of the event, in widget-space (0 is the left edge of this widget)y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseUp(int x, int y, int button)
WWidgetonMouseUp in class WWidgetx - The X coordinate of the event, in widget-space (0 is the left edge of this widget)y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)button - The mouse button that was used. Button numbering is consistent with LWJGL Mouse (0=left, 1=right, 2=mousewheel click)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseScroll(int x, int y, double amount)
WWidgetonMouseScroll in class WWidgetx - The X coordinate of the event, in widget-space (0 is the left edge of this widget)y - The Y coordinate of the event, in widget-space (0 is the top edge of this widget)amount - The scrolled amount. Positive values are up and negative values are down.InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public void tick()
WWidgetpublic int getValue()
public void setValue(int value)
value - the new valuepublic void setValue(int value,
boolean callListeners)
value - the new valuecallListeners - if true, call all slider listeners@Nullable public @Nullable java.util.function.IntConsumer getValueChangeListener()
public void setValueChangeListener(@Nullable
@Nullable java.util.function.IntConsumer valueChangeListener)
@Nullable public @Nullable java.util.function.IntConsumer getDraggingFinishedListener()
public void setDraggingFinishedListener(@Nullable
@Nullable java.util.function.IntConsumer draggingFinishedListener)
public int getMinValue()
public int getMaxValue()
public void setMinValue(int min)
public void setMaxValue(int max)
public Axis getAxis()
public WAbstractSlider.Direction getDirection()
public void setDirection(WAbstractSlider.Direction direction)
direction - the new directionjava.lang.IllegalArgumentException - if the direction axis is not equal to axis.protected void onValueChanged(int value)
@Environment(value=CLIENT)
public void onKeyPressed(int ch,
int key,
int modifiers)
WWidgetonKeyPressed in class WWidgetkey - the GLFW scancode of the key@Environment(value=CLIENT)
public void onKeyReleased(int ch,
int key,
int modifiers)
WWidgetonKeyReleased in class WWidgetkey - the GLFW scancode of the keypublic boolean isDragging()
public static boolean isDecreasingKey(int ch,
WAbstractSlider.Direction direction)
ch - the key codedirection - the directionpublic static boolean isIncreasingKey(int ch,
WAbstractSlider.Direction direction)
ch - the key codedirection - the direction