Slider
com.jsmacrosce.wagyourgui.elements.Slider
A slider widget with a value normally constrained to [0.0, 1.0].
Mouse input maps across the track, and left/right keys move by one configured interval. The action runs when setting the value changes it.
Constructors
new Slider
new Slider(int x, int y, int width, int height, Component text, double value, Consumer<Slider> action, int steps)#Creates a slider with the given number of discrete positions. Values are rounded to those positions; this constructor treats counts below two as two.
Parameters:
x: left edge in screen pixelsy: top edge in screen pixelswidth: widget width in screen pixelsheight: widget height in screen pixelstext: displayed messagevalue: initial value, rounded to a configured position without clampingaction: called with this slider when its value changessteps: number of discrete positions
new Slider(int x, int y, int width, int height, Component text, double value, Consumer<Slider> action)#Creates a slider with two positions:
0.0 and 1.0.Parameters:
x: left edge in screen pixelsy: top edge in screen pixelswidth: widget width in screen pixelsheight: widget height in screen pixelstext: displayed messagevalue: initial value, rounded to a configured position without clampingaction: called with this slider when its value changes
Methods
getSteps
getSteps(): int#Returns the configured number of discrete positions.
Returns: the number of discrete positions
getValue
getValue(): double#Returns the current value. The constructor rounds its initial value without clamping; setValue(double) clamps requested values to
[0.0, 1.0].Returns: the current normalized value
keyPressed
Moves the value one configured interval left or right for the corresponding key. The key is handled even when clamping leaves the value unchanged; other keys return false without superclass delegation. Calls the overridable setValue; an action failure propagates before returning. There is no local focus, visibility or activation check.
Parameters:
keyEvent: non-null native key event; only its GLFW key code is used, not its scan code or modifiers
Returns:
true for left or right; false for other keysonClick
onClick(MouseButtonEvent event, boolean isDoubleClick): void#Sets the value from the horizontal mouse position along the slider track. The position is mapped from the track inset by four GUI units on each side, then clamped and rounded; the action runs only if the value changes, through the overridable setValue. The calculation divides by width minus eight; this method does not validate track width or check bounds, focus, activation or visibility.
Parameters:
event: non-null pointer event; only its x-coordinate in GUI units is usedisDoubleClick: unused double-click indicator
onRelease
onRelease(MouseButtonEvent event): void#Requests the widget's down sound for a release; this does not change the slider value or invoke the action. A direct call does not check activation, visibility or focus; sound audibility depends on native sound handling.
Parameters:
event: unused pointer event
roundValue
roundValue(double value): double#Rounds a normalized value to the nearest configured interval; does not clamp it.
Parameters:
value: value to round
Returns: the value rounded to the nearest configured interval
setMessage
Sets the displayed message as literal text.
Parameters:
message: text to display
Sets the displayed label to the supplied component without changing the slider value or action. Unlike the string overload, this preserves the supplied component rather than making literal text.
Parameters:
message: non-null native component used as the displayed label
setSteps
setSteps(int steps): void#Sets the number of discrete positions without changing or re-rounding the current value; use at least two.
Parameters:
steps: number of discrete positions
setValue
setValue(double mouseX): void#Clamps the requested value to
[0.0, 1.0], rounds it, and notifies the action if it changed.Parameters:
mouseX: requested normalized value