Class WWidget
- Direct Known Subclasses:
WAbstractSlider
,WBar
,WButton
,WDynamicLabel
,WItem
,WItemSlot
,WLabel
,WPanel
,WScrollBar
,WSprite
,WText
,WTextField
,WToggleButton
Property Summary
Modifier and TypePropertyDescriptionpublic java.lang.Boolean
Returns whether the user is hovering over this widget.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The height of this widget, defaults to 18 pixels.protected @Nullable GuiDescription
The containingGuiDescription
of this widget.The containing panel of this widget.protected int
The width of this widget, defaults to 18 pixels.protected int
The X coordinate of this widget relative to its parent.protected int
The Y coordinate of this widget relative to its parent. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNarrations
(NarrationMessageBuilder builder) Adds the narrations of this widget to a narration builder.void
Adds the default background painters to this widget and all children.void
addTooltip
(TooltipBuilder tooltip) Adds lines to this widget's tooltip.boolean
canFocus()
Tests whether this widget can have the focus in the GUI.boolean
canHover()
Tests whether this widget receives mouse hovering status.boolean
Checks whether this widget can be resized usingsetSize(int, int)
.int
Gets the absolute X coordinate of this widget.int
Gets the absolute Y coordinate of this widget.Returns the focus model of this widget.int
final @Nullable GuiDescription
getHost()
Gets the host of this widget.Gets the parent panel of this widget.int
getWidth()
int
getX()
Gets the X coordinate of this widget relative to its parent.int
getY()
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 boolean
isActivationKey
(int ch) Tests if the provided key code is an activation key for widgets.boolean
Tests whether this widget has focus.final boolean
Returns whether the user is hovering over this widget.boolean
Returns whether this widget can be narrated.boolean
isWithinBounds
(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.void
Notifies this widget that it has gained focusvoid
Notifies this widget that it has lost focusvoid
onHidden()
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 boundsvoid
onShown()
Notifies this widget that it is visible and shows any hidden peers of itself and its children.void
paint
(DrawContext context, int x, int y, int mouseX, int mouseY) Paints this widget.void
If this widget has a host, releases this widget's focus.void
renderTooltip
(DrawContext context, int x, int y, int tX, int tY) Internal method to render tooltip data.void
If this widget has a host, requests the focus from the host.void
setHost
(GuiDescription host) Sets the host of this widget and all its children without creating peers.final void
setHovered
(boolean hovered) Sets thehovered
property.void
setLocation
(int x, int y) Sets the location of this widget relative to its parent.void
Sets the parent panel of this widget.void
setSize
(int x, int y) Sets the size of this widget.boolean
Checks if this widget should be rendered in dark mode.void
tick()
Executes a client-side tick for this widget.void
validate
(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 containingGuiDescription
of 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.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) 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.- 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.- 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.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
onKeyPressed
Notifies this widget that a key has been pressed.- Parameters:
key
- the GLFW scancode of the key- Returns:
InputResult.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
onKeyReleased
Notifies this widget that a key has been released- Parameters:
key
- the GLFW scancode of the key- Returns:
InputResult.PROCESSED
if the event is handled,InputResult.IGNORED
otherwise.
-
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 overriddenaddTooltip
method 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
null
if 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
hovered
property - 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 thehovered
property. 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:
true
if this widget should be rendered in dark mode,false
otherwise- Since:
- 7.1.0
-