Skip to content

Slider ​

com.jsmacrosce.wagyourgui.elements.Slider

Since1.8.4

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 pixels
  • y: top edge in screen pixels
  • width: widget width in screen pixels
  • height: widget height in screen pixels
  • text: displayed message
  • value: initial value, rounded to a configured position without clamping
  • action: called with this slider when its value changes
  • steps: 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 pixels
  • y: top edge in screen pixels
  • width: widget width in screen pixels
  • height: widget height in screen pixels
  • text: displayed message
  • value: initial value, rounded to a configured position without clamping
  • action: 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 ​

keyPressed(int keyCode, int scanCode, int modifiers): boolean#
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:

  • keyCode: native GLFW key code to handle
  • scanCode: unused platform scan code
  • modifiers: unused modifier bits
Returns: true for left or right; false for other keys

onClick ​

onClick(double mouseX, double mouseY): 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:

  • mouseX: mouse x-coordinate in GUI units
  • mouseY: mouse y-coordinate in GUI units; unused

onRelease ​

onRelease(double mouseX, double mouseY): 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:

  • mouseX: mouse x-coordinate in GUI units; unused
  • mouseY: mouse y-coordinate in GUI units; unused

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 ​

setMessage(String message): void#
Sets the displayed message as literal text.

Parameters:

  • message: text to display
setMessage(Component message): void#
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