Class WScrollBar
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WScrollBar
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected int
protected Axis
static final int
The default scrolling speed for mouse inputs.protected int
protected boolean
protected int
protected int
-
Constructor Summary
ConstructorDescriptionConstructs a horizontal scroll bar.WScrollBar
(Axis axis) Constructs a scroll bar with a custom axis. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNarrations
(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.protected void
adjustSlider
(int x, int y) boolean
canFocus()
Tests whether this widget can have the focus in the GUI.boolean
Checks whether this widget can be resized usingWWidget.setSize(int, int)
.protected void
Checks that the current value is in the correct range and adjusts it if needed.int
int
Gets the on-axis size of the scrollbar handle in gui pixelsint
Gets the maximum scroll value achievable; this will typically be the maximum value minus the window sizeint
int
Gets the number of pixels the scrollbar handle is able to move along its track from one end to the other.int
Returns the default mouse scroll speed.int
getValue()
int
onKeyPressed
(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 boundsvoid
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.int
pixelsToValues
(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:WWidget
Paints this widget. -
canResize
public boolean canResize()Description copied from class:WWidget
Checks whether this widget can be resized usingWWidget.setSize(int, int)
. -
canFocus
public boolean canFocus()Description copied from class:WWidget
Tests 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:WWidget
Notifies this widget that the mouse has been pressed while inside its bounds- Overrides:
onMouseDown
in 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.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 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
onMouseUp
Description copied from class:WWidget
Notifies this widget that the mouse has been released while inside its bounds- Overrides:
onMouseUp
in 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
onKeyPressed
Description copied from class:WWidget
Notifies this widget that a key has been pressed.- Overrides:
onKeyPressed
in classWWidget
- 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 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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: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 classWWidget
- Parameters:
builder
- the narration builder, cannot be null
-