Class WLabeledSlider


public class WLabeledSlider extends WAbstractSlider
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:
  • Constructor Details

    • WLabeledSlider

      public WLabeledSlider(int min, int max)
      Constructs a horizontal slider with no default label.
      Parameters:
      min - the minimum value
      max - the maximum value
    • WLabeledSlider

      public WLabeledSlider(int min, int max, Axis axis)
      Constructs a slider with no default label.
      Parameters:
      min - the minimum value
      max - the maximum value
      axis - the slider axis
    • WLabeledSlider

      public WLabeledSlider(int min, int max, Axis axis, @Nullable @Nullable Text label)
      Constructs a slider.
      Parameters:
      min - the minimum value
      max - the maximum value
      axis - the slider axis
      label - the slider label (can be null)
    • WLabeledSlider

      public WLabeledSlider(int min, int max, @Nullable @Nullable Text label)
      Constructs a horizontal slider.
      Parameters:
      min - the minimum value
      max - the maximum value
      label - the slider label (can be null)
  • Method Details

    • getLabel

      @Nullable public @Nullable Text getLabel()
      Gets the current label of this slider.
      Returns:
      the label
    • setLabel

      public void setLabel(@Nullable @Nullable Text label)
      Sets the label of this slider.
      Parameters:
      label - the new label
    • onValueChanged

      protected void onValueChanged(int value)
      Overrides:
      onValueChanged in class WAbstractSlider
    • getLabelAlignment

      public HorizontalAlignment getLabelAlignment()
      Gets the text alignment of this slider's label.
      Returns:
      the alignment
    • setLabelAlignment

      public void setLabelAlignment(HorizontalAlignment labelAlignment)
      Sets the text alignment of this slider's label.
      Parameters:
      labelAlignment - the new alignment
    • getLabelUpdater

      Gets the WLabeledSlider.LabelUpdater of this slider.
      Returns:
      the label updater
    • setLabelUpdater

      public void setLabelUpdater(@Nullable @Nullable WLabeledSlider.LabelUpdater labelUpdater)
      Sets the WLabeledSlider.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 class WAbstractSlider
      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 class WAbstractSlider
      Parameters:
      x - the mouse x position
      y - the mouse y position
      Returns:
      if the cursor is inside dragging bounds
    • paint

      @Environment(CLIENT) public void paint(DrawContext context, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      context - the draw context
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • addNarrations

      @Environment(CLIENT) public void addNarrations(NarrationMessageBuilder builder)
      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 class WAbstractSlider
      Parameters:
      builder - the narration builder, cannot be null