Scrollbar
com.jsmacrosce.wagyourgui.elements.Scrollbar
A vertical scroll control whose callback receives the current page offset, not a normalized fraction.
The offset is calculated as max(pages - 1, 0) * scrollAmount / scrollDistance; geometry and page values are not validated.
The callback may be null, and initialization can invoke it when fewer than one page is supplied.
Construct the widget, then register it with the desired host separately.
js
const Scrollbar = Java.type("com.jsmacrosce.wagyourgui.elements.Scrollbar");
function createScrollbar(x, y, width, height, onOffset) {
return new Scrollbar(x, y, width, height, Color.rgb(0x20, 0x20, 0x20), Color.rgb(0x00, 0x00, 0x00), Color.rgb(0x80, 0x80, 0x80), 3,
JavaWrapper.methodToJava(onOffset));
}Constructors
new Scrollbar
new Scrollbar(int x, int y, int width, int height, int color, int borderColor, int highlightColor, double scrollPages, Consumer<Double> onChange)#Sets native geometry and raw packed-ARGB colors, stores the optional page-offset callback, then calls the overridable setScrollPages. Its base implementation with fewer than one page resets the position and calls onChange before hiding and deactivating the widget. If that callback throws, the later visibility and activation assignments are not reached. The constructor does not register the widget with a host.
Parameters:
x: left edge in GUI unitsy: top edge in GUI unitswidth: widget width in GUI unitsheight: widget height in GUI unitscolor: raw packed-ARGB background colorborderColor: raw packed-ARGB border colorhighlightColor: raw packed-ARGB thumb colorscrollPages: total page count used to initialize the controlonChange: optional consumer receiving the current page offset; may be null
Methods
mouseDragged
mouseDragged(MouseButtonEvent buttonEvent, double deltaX, double deltaY): boolean#Adds the vertical drag delta to position, clamps first to the upper travel distance and then to zero, calls onChange, then delegates to the superclass. There is no local activation, visibility, focus, button or bounds check. The callback may run even if position is unchanged; if it throws, superclass delegation is not reached. The superclass result does not report whether this method changed position.
Parameters:
buttonEvent: non-null native pointer event; its y-coordinate is read before changing position but is unused in the local adjustment, and the event is forwarded unchanged to the superclassdeltaX: horizontal drag delta, forwarded to the superclass but unused in the local adjustmentdeltaY: vertical drag delta in GUI units; positive values increase the position
Returns: the result returned by the superclass
onChange
onChange(): void#Invokes the optional callback with the current page offset: extra pages multiplied by position and divided by travel distance. A direct call does not change position and may notify even when unchanged, hidden or inactive. No finite-value or range check is performed.
onClick
onClick(MouseButtonEvent buttonEvent, boolean doubleClick): void#Moves the thumb toward the clicked track position when active. Each qualifying side of the thumb calls onChange after its own one-sided position clamp. The two tests are separate, not mutually exclusive; a click within the thumb makes no change. This method does not check visibility or whether the coordinates lie within the widget.
Parameters:
buttonEvent: non-null pointer event; its y-coordinate in GUI units is read even when inactive, and its other fields are unuseddoubleClick: unused double-click indicator
scrollToPercent
scrollToPercent(double percent): void#Sets the thumb position as a fraction of its travel distance and calls the overridable onChange, even if unchanged, hidden or inactive. Values outside
0..1 are retained without clamping; visibility and activation are unchanged.Parameters:
percent: travel fraction, normally0at the start and1at the end
setPos
Updates geometry, recalculates thumb height and travel distance, and rescales position by the old and new travel distances. Unlike setScrollPages, this calculation does not round the thumb height up. Position is not explicitly clamped; no callback is invoked and visibility and activation are unchanged.
Parameters:
x: left edge in GUI unitsy: top edge in GUI unitswidth: widget width in GUI unitsheight: widget height in GUI units
Returns: self for chaining
setScrollPages
setScrollPages(double scrollPages): void#Sets the total page count and recalculates the thumb geometry, rounding the thumb height up. Values below one reset position and call the overridable onChange before hiding and deactivating the widget; if the callback throws, those later assignments are not reached. Values of one or greater show and activate it without rescaling, clamping or resetting position, or notifying the callback.
Parameters:
scrollPages: total page count, not the number of extra pages