Button
com.jsmacrosce.wagyourgui.elements.Button
A native-widget button with a wrapped label, configurable packed ARGB colors, and an optional press callback.
The constructor does not add the button to a host; use an existing host for normal input and rendering.
js
function makeButton(font, label, onPressed) {
const Button = Java.type('com.jsmacrosce.wagyourgui.elements.Button');
return new Button(10, 10, 120, 20, font, Color.rgb(0x00, 0x00, 0x00), Color.rgb(0xFF, 0xFF, 0xFF),
Color.rgb(0x80, 0x80, 0x80), Color.rgb(0xFF, 0xFF, 0xFF), label, JavaWrapper.methodToJava(onPressed));
}The factory takes a native font, component label, and JavaScript callback; add the result to your existing host separately.
Constructors
new Button
new Button(int x, int y, int width, int height, Font textRenderer, int color, int borderColor, int highlightColor, int textColor, Component message, Consumer<Button> onPress)#Initializes native geometry and message, stores the font and optional callback, configures colors, then calls the overridable setMessage to prepare the label cache. Does not invoke the callback or register this button with a host. Packed ARGB colors with zero alpha and nonzero RGB are made opaque; zero remains zero.
Parameters:
x: left position in GUI unitsy: top position in GUI unitswidth: width in GUI unitsheight: height in GUI unitstextRenderer: non-null native font used to wrap and draw the labelcolor: idle background fill as packed ARGBborderColor: outline as packed ARGBhighlightColor: hover or forced-hover fill as packed ARGBtextColor: label color as packed ARGBmessage: nonnull native component labelonPress: optional callback receiving this button when invoked; may be null
Fields
forceHover
forceHover: boolean#Forces the hover fill and recorded hover state during a visible contents-render hook, independent of bounds or active state; initially false. Does not make the widget visible or active, or invoke the press callback.
horizCenter
horizCenter: boolean#Whether this button's cached label is horizontally centered, initially true; false uses a two-GUI-unit left inset. A direct change affects the next label draw, without refreshing wrapping or invoking the press callback.
hovering
hovering: boolean#Hover result last recorded by a visible contents-render hook; initially false and not refreshed while hidden. This button records mouse-inside-and-active or forced hover. A direct write is overwritten by the next visible hook and does not control activation.
onPress
Methods
cantRenderAllText
cantRenderAllText(): boolean#Reports whether the cached wrapped label has more lines than the cached visible-line count. This is a cached line-overflow test, not a fresh horizontal-fit or clipping measurement; dimensions changed by setPos do not refresh it.
Returns: true when cached wrapped lines exceed the visible count; false otherwise
onClick
onClick(MouseButtonEvent buttonEvent, boolean doubleClick): void#Ignores this mouse-press hook; mouse activation is dispatched by the release hook instead.
Parameters:
buttonEvent: unused pointer eventdoubleClick: unused double-click indicator
onPress
onPress(InputWithModifiers input): void#Invokes the current press callback with this button, if a callback is set. A null callback is a no-op; this method does not itself check widget state or change it.
Parameters:
input: unused activation input
onRelease
onRelease(MouseButtonEvent buttonEvent): void#On release, forwards the pointer event and a false double-click flag to the superclass click when
isActive() is true. The inherited active test requires visibility and active state. The superclass click invokes this button's overridable press handler; this hook adds no bounds check.Parameters:
buttonEvent: pointer event forwarded to the superclass click
renderContents
renderContents(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#Draws this button's fill, outline and cached label when visible, and records its hover result. Forced hover selects the highlight even outside the bounds or while inactive; hidden calls do nothing and leave the recorded value unchanged. Mouse coordinates use GUI units;
delta is unused by this implementation.Parameters:
drawContext: graphics used for drawingmouseX: mouse x-coordinate in GUI unitsmouseY: mouse y-coordinate in GUI unitsdelta: unused frame delta
setBorderColor
setBorderColor(int color): void#Sets the outline color; a zero alpha byte with nonzero RGB is made opaque, while zero remains zero.
Parameters:
color: packed ARGB color
setColor
setColor(int color): void#Sets the idle background fill; a zero alpha byte with nonzero RGB is made opaque, while zero remains zero.
Parameters:
color: packed ARGB color
setHighlightColor
setHighlightColor(int color): void#Sets the hover or forced-hover fill; a zero alpha byte with nonzero RGB is made opaque, while zero remains zero.
Parameters:
color: packed ARGB color
setMessage
Sets the native label and caches wrapping at width minus four GUI units, a height-limited visible-line count and vertical offset for the current geometry. The cache is not refreshed by later geometry changes until this method is called again. This method does not invoke the press callback.
Parameters:
message: nonnull native component label
setPos
Updates geometry only; call setMessage again to refresh label wrapping, height-limited visible-line count and vertical offset after resizing. No press callback is invoked.
Parameters:
x: left position in GUI unitsy: top position in GUI unitswidth: width in GUI unitsheight: height in GUI units
Returns: self for chaining
setTextColor
setTextColor(int color): void#Sets the packed ARGB label color, making zero-alpha nonzero RGB opaque; zero remains transparent. The color is used when cached label lines are next drawn; this does not refresh their wrapping.
Parameters:
color: packed ARGB label color