Class WScrollBar

java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WScrollBar

public class WScrollBar extends WWidget
  • Field Details

    • DEFAULT_SCROLLING_SPEED

      public static final int DEFAULT_SCROLLING_SPEED
      Since:
      9.0.0
      See Also:
    • axis

      protected Axis axis
    • value

      protected int value
    • maxValue

      protected int maxValue
    • window

      protected int window
    • anchor

      protected int anchor
    • anchorValue

      protected int anchorValue
    • sliding

      protected boolean sliding
  • Constructor Details

    • WScrollBar

      public WScrollBar()
      Constructs a horizontal scroll bar.
    • WScrollBar

      public WScrollBar(Axis axis)
      Constructs a scroll bar with a custom axis.
      Parameters:
      axis - the axis
  • Method Details

    • 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
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • canFocus

      public boolean canFocus()
      Description copied from class: WWidget
      Tests whether this widget can have the focus in the GUI.
      Overrides:
      canFocus in class WWidget
      Returns:
      true if this widget can be focused, false otherwise
    • getHandleSize

      public int getHandleSize()
      Gets the on-axis size of the scrollbar handle in gui pixels
    • getMovableDistance

      public int getMovableDistance()
      Gets the number of pixels the scrollbar handle is able to move along its track from one end to the other.
    • pixelsToValues

      public int pixelsToValues(int pixels)
    • getHandlePosition

      public int getHandlePosition()
    • getMaxScrollValue

      public int getMaxScrollValue()
      Gets the maximum scroll value achievable; this will typically be the maximum value minus the window size
    • adjustSlider

      protected void adjustSlider(int x, int y)
    • onMouseDown

      public InputResult onMouseDown(int x, int y, int button)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been pressed while inside its bounds
      Overrides:
      onMouseDown in class WWidget
      Parameters:
      x - 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)
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • onMouseDrag

      @Environment(CLIENT) public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been moved while pressed and inside its bounds.
      Overrides:
      onMouseDrag in class WWidget
      Parameters:
      x - 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 axis
      deltaY - The amount of dragging on the Y axis
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • onMouseUp

      @Environment(CLIENT) public InputResult onMouseUp(int x, int y, int button)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been released while inside its bounds
      Overrides:
      onMouseUp in class WWidget
      Parameters:
      x - 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)
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • onKeyPressed

      public InputResult onKeyPressed(int ch, int key, int modifiers)
      Description copied from class: WWidget
      Notifies this widget that a key has been pressed.
      Overrides:
      onKeyPressed in class WWidget
      Parameters:
      key - the GLFW scancode of the key
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • onMouseScroll

      @Environment(CLIENT) public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount)
      Description copied from class: WWidget
      Notifies this widget that the mouse has been scrolled inside its bounds.
      Overrides:
      onMouseScroll in class WWidget
      Parameters:
      x - 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)
      horizontalAmount - The scrolled horizontal amount. Positive values are right and negative values are left.
      verticalAmount - The scrolled vertical amount. Positive values are up and negative values are down.
      Returns:
      InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.
    • getValue

      public int getValue()
    • setValue

      public WScrollBar setValue(int value)
    • getMaxValue

      public int getMaxValue()
    • setMaxValue

      public WScrollBar setMaxValue(int max)
    • setScrollingSpeed

      public WScrollBar setScrollingSpeed(int scrollingSpeed)
      Sets the mouse scroll speed.

      By default, the scrolling speed is 4.

      Parameters:
      scrollingSpeed - the scroll speed, must be positive
      Returns:
      this scroll bar
    • getScrollingSpeed

      public int getScrollingSpeed()
      Returns the default mouse scroll speed.

      By default, the scrolling speed is 4.

      Returns:
      the default mouse scroll speed
    • getWindow

      public int getWindow()
    • setWindow

      public WScrollBar setWindow(int window)
    • checkValue

      protected void checkValue()
      Checks that the current value is in the correct range and adjusts it if needed.
    • 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 WWidget
      Parameters:
      builder - the narration builder, cannot be null