Class WWidget
- Direct Known Subclasses:
WAbstractSlider,WBar,WButton,WDynamicLabel,WItem,WItemSlot,WLabel,WPanel,WScrollBar,WSprite,WText,WTextField,WToggleButton
Property Summary
PropertiesModifier and TypePropertyDescriptionpublic java.lang.BooleanReturns whether the user is hovering over this widget.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe height of this widget, defaults to 18 pixels.protected @Nullable GuiDescriptionThe containingGuiDescriptionof this widget.The containing panel of this widget.protected intThe width of this widget, defaults to 18 pixels.protected intThe X coordinate of this widget relative to its parent.protected intThe Y coordinate of this widget relative to its parent. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNarrations(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.voidAdds the default background painters to this widget and all children.voidaddTooltip(TooltipBuilder tooltip) Adds lines to this widget's tooltip.booleancanFocus()Tests whether this widget can have the focus in the GUI.booleancanHover()Tests whether this widget receives mouse hovering status.booleanChecks whether this widget can be resized usingsetSize(int, int).intGets the absolute X coordinate of this widget.intGets the absolute Y coordinate of this widget.Returns the focus model of this widget.intfinal @Nullable GuiDescriptiongetHost()Gets the host of this widget.Gets the parent panel of this widget.intgetWidth()intgetX()Gets the X coordinate of this widget relative to its parent.intgetY()Gets the Y coordinate of this widget relative to its parent.hit(int x, int y) Find the most specific child node at this location.Returns whether the user is hovering over this widget.static booleanisActivationKey(int ch) Tests if the provided key code is an activation key for widgets.booleanTests whether this widget has focus.final booleanReturns whether the user is hovering over this widget.booleanReturns whether this widget can be narrated.booleanisWithinBounds(int x, int y) Checks whether a location is within this widget's bounds.onCharTyped(char ch) Notifies this widget that a character has been typed.onClick(int x, int y, int button) Notifies this widget that the mouse has been pressed and released, both while inside its bounds.voidNotifies this widget that it has gained focusvoidNotifies this widget that it has lost focusvoidonHidden()Notifies this widget that it won't be drawn and hides any visible peers of itself and its children.onKeyPressed(int ch, int key, int modifiers) Notifies this widget that a key has been pressed.onKeyReleased(int ch, int key, int modifiers) Notifies this widget that a key has been releasedonMouseDown(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.onMouseMove(int x, int y) Notifies this widget that the mouse has been moved while 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 boundsvoidonShown()Notifies this widget that it is visible and shows any hidden peers of itself and its children.voidpaint(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.voidIf this widget has a host, releases this widget's focus.voidrenderTooltip(DrawContext context, int x, int y, int tX, int tY) Internal method to render tooltip data.voidIf this widget has a host, requests the focus from the host.voidsetHost(GuiDescription host) Sets the host of this widget and all its children without creating peers.final voidsetHovered(boolean hovered) Sets thehoveredproperty.voidsetLocation(int x, int y) Sets the location of this widget relative to its parent.voidSets the parent panel of this widget.voidsetSize(int x, int y) Sets the size of this widget.booleanChecks if this widget should be rendered in dark mode.voidtick()Executes a client-side tick for this widget.voidvalidate(GuiDescription host) Creates component peers and initializes animation data for this Widget and all its children.
-
Field Details
-
parent
The containing panel of this widget. Can be null if this widget is the root panel or a HUD widget. -
x
protected int xThe X coordinate of this widget relative to its parent. -
y
protected int yThe Y coordinate of this widget relative to its parent. -
width
protected int widthThe width of this widget, defaults to 18 pixels. -
height
protected int heightThe height of this widget, defaults to 18 pixels. -
host
The containingGuiDescriptionof this widget. Can be null if this widget is a HUD widget.
-
-
Constructor Details
-
WWidget
public WWidget()
-
-
Method Details
-
setLocation
public void setLocation(int x, int y) Sets the location of this widget relative to its parent.- Parameters:
x- the new X coordinatey- the new Y coordinate
-
setSize
public void setSize(int x, int y) Sets the size of this widget.Overriding methods may restrict one of the dimensions to be a constant value, for example
super.setSize(x, 20).- Parameters:
x- the new widthy- the new height
-
getX
public int getX()Gets the X coordinate of this widget relative to its parent.- Returns:
- the X coordinate
-
getY
public int getY()Gets the Y coordinate of this widget relative to its parent.- Returns:
- the Y coordinate
-
getAbsoluteX
public int getAbsoluteX()Gets the absolute X coordinate of this widget.- Returns:
- the absolute X coordinate
-
getAbsoluteY
public int getAbsoluteY()Gets the absolute Y coordinate of this widget.- Returns:
- the absolute Y coordinate
-
getWidth
public int getWidth() -
getHeight
public int getHeight() -
canResize
public boolean canResize()Checks whether this widget can be resized usingsetSize(int, int).- Returns:
- true if this widget can be resized, false otherwise
-
getParent
Gets the parent panel of this widget.- Returns:
- the parent, or null if this widget has no parent
- Since:
- 2.0.0
-
setParent
Sets the parent panel of this widget.- Parameters:
parent- the new parent
-
onMouseDown
Notifies this widget that the mouse has been pressed while inside its bounds- 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) Notifies this widget that the mouse has been moved while pressed and inside its bounds.- 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.- Since:
- 1.5.0
-
onMouseUp
Notifies this widget that the mouse has been released while inside its bounds- 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.
-
onClick
Notifies this widget that the mouse has been pressed and released, both while inside its bounds.- 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.
-
onMouseScroll
@Environment(CLIENT) public InputResult onMouseScroll(int x, int y, double horizontalAmount, double verticalAmount) Notifies this widget that the mouse has been scrolled inside its bounds.- 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.
-
onMouseMove
Notifies this widget that the mouse has been moved while inside its bounds.- 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)- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.- Since:
- 1.5.0
-
onCharTyped
Notifies this widget that a character has been typed. This method is subject to key repeat, and may be called for characters that do not directly have a corresponding keyboard key.- Parameters:
ch- the character typed- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onKeyPressed
Notifies this widget that a key has been pressed.- Parameters:
key- the GLFW scancode of the key- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onKeyReleased
Notifies this widget that a key has been released- Parameters:
key- the GLFW scancode of the key- Returns:
InputResult.PROCESSEDif the event is handled,InputResult.IGNOREDotherwise.
-
onFocusGained
public void onFocusGained()Notifies this widget that it has gained focus -
onFocusLost
public void onFocusLost()Notifies this widget that it has lost focus -
isFocused
public boolean isFocused()Tests whether this widget has focus.- Returns:
- true if this widget widget has focus, false otherwise
- See Also:
-
requestFocus
public void requestFocus()If this widget has a host, requests the focus from the host.- See Also:
-
releaseFocus
public void releaseFocus()If this widget has a host, releases this widget's focus.- See Also:
-
canFocus
public boolean canFocus()Tests whether this widget can have the focus in the GUI.- Returns:
- true if this widget can be focused, false otherwise
-
paint
Paints this widget.- Parameters:
context- the draw contextx- this widget's X coordinate on the screeny- this widget's Y coordinate on the screenmouseX- the X coordinate of the cursormouseY- the X coordinate of the cursor- Since:
- 2.0.0
-
isWithinBounds
public boolean isWithinBounds(int x, int y) Checks whether a location is within this widget's bounds.The default implementation checks that X and Y are at least 0 and below the width and height of this widget.
- Parameters:
x- the X coordinatey- the Y coordinate- Returns:
- true if the location is within this widget, false otherwise
-
renderTooltip
Internal method to render tooltip data. This requires an overriddenaddTooltipmethod to insert data into the tooltip - without this, the method returns early because of no work.- Parameters:
context- the draw contextx- the X coordinate of this widget on screeny- the Y coordinate of this widget on screentX- the X coordinate of the tooltiptY- the Y coordinate of the tooltip
-
validate
Creates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.This method must be called on the root panel of any screen once the widgets have been initialized.
- Parameters:
host- the host GUI description
-
getHost
Gets the host of this widget.- Returns:
- the host
- Since:
- 2.1.0
- See Also:
-
setHost
Sets the host of this widget and all its children without creating peers.- Parameters:
host- the new host- Since:
- 2.1.0
- See Also:
-
addTooltip
Adds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.- Parameters:
tooltip- the builder to add tooltip lines to
-
hit
Find the most specific child node at this location. For non-panel widgets, returns this widget. -
tick
@Environment(CLIENT) public void tick()Executes a client-side tick for this widget. -
getFocusModel
Returns the focus model of this widget. The focus model provides the focusable areas of this widget, and handles switching through them.If this widget can focus, it should return a nonnull focus model. The default implementation returns
FocusModel.simple(this)when the widget can be focused.- Returns:
- the focus model, or
nullif not available - Since:
- 7.0.0
-
onShown
public void onShown()Notifies this widget that it is visible and shows any hidden peers of itself and its children.- Since:
- 3.0.0
-
onHidden
public void onHidden()Notifies this widget that it won't be drawn and hides any visible peers of itself and its children.The default implementation releases this widget's focus if it is focused. Overriding implementations might want to do this as well.
- Since:
- 3.0.0
-
addPainters
@Environment(CLIENT) public void addPainters()Adds the default background painters to this widget and all children.Always called before
GuiDescription.addPainters()to allow users to modify painters.- Since:
- 3.0.0
-
canHover
public boolean canHover()Tests whether this widget receives mouse hovering status.- Returns:
- true if this widget receives hovering status, false otherwise
- Since:
- 4.2.0
-
hoveredProperty
Returns whether the user is hovering over this widget. The result is an observable property that can be modified and listened to.This property takes into account
isWithinBounds(int, int)to check if the cursor is within the bounds, as well ascanHover()to enable hovering at all.Hovering is used by LibGui itself mostly for narration support. For rendering, it might be preferable that you check the mouse coordinates in
paint()directly. That lets you react to different parts of the widget being hovered over.- Returns:
- the
hoveredproperty - Since:
- 4.2.0
- See Also:
-
isHovered
public final boolean isHovered()Returns whether the user is hovering over this widget. This is equivalent to calling.hoveredProperty().get()- Returns:
- true if this widget is hovered, false otherwise
- Since:
- 4.2.0
-
setHovered
public final void setHovered(boolean hovered) Sets thehoveredproperty. This is equivalent to calling.hoveredProperty().set(hovered)- Parameters:
hovered- the new value; true if hovered, false otherwise- Since:
- 4.2.0
-
isNarratable
public boolean isNarratable()Returns whether this widget can be narrated.- Returns:
- whether this widget can be narrated
- Since:
- 4.2.0
- See Also:
-
addNarrations
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.
- Parameters:
builder- the narration builder, cannot be null- Since:
- 4.2.0
-
isActivationKey
@Environment(CLIENT) public static boolean isActivationKey(int ch) Tests if the provided key code is an activation key for widgets.The activation keys are Enter, keypad Enter, and Space.
- Parameters:
ch- the key code- Returns:
- whether the key is an activation key
- Since:
- 2.0.0
-
shouldRenderInDarkMode
@Environment(CLIENT) public boolean shouldRenderInDarkMode()Checks if this widget should be rendered in dark mode.If the widget has a host that forces dark mode, the forced value is used. Otherwise, this method returns
LibGui.isDarkMode().Painting should respect this value for general-purpose widgets intended for use in multiple different GUIs.
- Returns:
trueif this widget should be rendered in dark mode,falseotherwise- Since:
- 7.1.0
-