Class WScrollBar
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WScrollBar
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected Axisstatic final intThe default scrolling speed for mouse inputs.protected intprotected booleanprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a horizontal scroll bar.WScrollBar(Axis axis) Constructs a scroll bar with a custom axis. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.protected voidadjustSlider(int x, int y) booleancanFocus()Tests whether this widget can have the focus in the GUI.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).protected voidChecks that the current value is in the correct range and adjusts it if needed.intintGets the on-axis size of the scrollbar handle in gui pixelsintGets the maximum scroll value achievable; this will typically be the maximum value minus the window sizeintintGets the number of pixels the scrollbar handle is able to move along its track from one end to the other.intReturns the default mouse scroll speed.intgetValue()intonKeyPressed(int ch, int key, int modifiers) Notifies this widget that a key has been pressed.onMouseDown(int x, int y, int button) Notifies this widget that the mouse has been pressed while inside its boundsonMouseDrag(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.onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) Notifies this widget that the mouse has been scrolled inside its bounds.onMouseUp(int x, int y, int button) Notifies this widget that the mouse has been released while inside its boundsvoidpaint(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.intpixelsToValues(int pixels) setMaxValue(int max) setScrollingSpeed(int scrollingSpeed) Sets the mouse scroll speed.setValue(int value) setWindow(int window) Methods inherited from class io.github.cottonmc.cotton.gui.widget.WWidget
addPainters, addTooltip, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onHidden, onKeyReleased, onMouseMove, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode, tick, validate
-
Field Details
-
DEFAULT_SCROLLING_SPEED
public static final int DEFAULT_SCROLLING_SPEEDThe default scrolling speed for mouse inputs.- Since:
- 9.0.0
- See Also:
-
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
Constructs a scroll bar with a custom axis.- Parameters:
axis- the axis
-
-
Method Details
-
paint
Description copied from class:WWidgetPaints this widget. -
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
canFocus
public boolean canFocus()Description copied from class:WWidgetTests whether this widget can have the focus in the GUI. -
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
Description copied from class:WWidgetNotifies this widget that the mouse has been pressed while inside its bounds- Overrides:
onMouseDownin classWWidget- 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.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onMouseDrag
@Environment(CLIENT) public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY) Description copied from class:WWidgetNotifies this widget that the mouse has been moved while pressed and inside its bounds.- Overrides:
onMouseDragin classWWidget- 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 axisdeltaY- The amount of dragging on the Y axis- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onMouseUp
Description copied from class:WWidgetNotifies this widget that the mouse has been released while inside its bounds- Overrides:
onMouseUpin classWWidget- 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.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onKeyPressed
Description copied from class:WWidgetNotifies this widget that a key has been pressed.- Overrides:
onKeyPressedin classWWidget- Parameters:
key- the GLFW scancode of the key- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onMouseScroll
@Environment(CLIENT) public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) Description copied from class:WWidgetNotifies this widget that the mouse has been scrolled inside its bounds.- Overrides:
onMouseScrollin classWWidget- 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.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
getValue
public int getValue() -
setValue
-
getMaxValue
public int getMaxValue() -
setMaxValue
-
setScrollingSpeed
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
-
checkValue
protected void checkValue()Checks that the current value is in the correct range and adjusts it if needed. -
addNarrations
Description copied from class:WWidgetAdds 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:
addNarrationsin classWWidget- Parameters:
builder- the narration builder, cannot be null
-