public class WWidget
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
height
The height of this widget, defaults to 18 pixels.
|
protected @Nullable GuiDescription |
host
The containing
GuiDescription of this widget. |
protected @Nullable WPanel |
parent
The containing panel of this widget.
|
protected int |
width
The width of this widget, defaults to 18 pixels.
|
protected int |
x
The X coordinate of this widget relative to its parent.
|
protected int |
y
The Y coordinate of this widget relative to its parent.
|
| Constructor and Description |
|---|
WWidget() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPainters()
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 |
canResize()
Checks whether this widget can be resized using
setSize(int, int). |
void |
createPeers(GuiDescription c)
Deprecated.
All widget peers should be added in
validate(GuiDescription). |
@Nullable WWidget |
cycleFocus(boolean lookForwards)
Cycles the focus inside this widget.
|
int |
getAbsoluteX()
Gets the absolute X coordinate of this widget.
|
int |
getAbsoluteY()
Gets the absolute Y coordinate of this widget.
|
int |
getHeight() |
@Nullable GuiDescription |
getHost()
Gets the host of this widget.
|
@Nullable WPanel |
getParent()
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.
|
WWidget |
hit(int x,
int y)
Find the most specific child node at this location.
|
static boolean |
isActivationKey(int ch)
Tests if the provided key code is an activation key for widgets.
|
boolean |
isFocused()
Tests whether this widget has focus.
|
boolean |
isWithinBounds(int x,
int y)
Checks whether a location is within this widget's bounds.
|
void |
onCharTyped(char ch)
Notifies this widget that a character has been typed.
|
InputResult |
onClick(int x,
int y,
int button)
Notifies this widget that the mouse has been pressed and released, both while inside its bounds.
|
void |
onFocusGained()
Notifies this widget that it has gained focus
|
void |
onFocusLost()
Notifies this widget that it has lost focus
|
void |
onHidden()
Notifies this widget that it won't be drawn and
hides any visible peers of itself and its children.
|
void |
onKeyPressed(int ch,
int key,
int modifiers)
Notifies this widget that a key has been pressed.
|
void |
onKeyReleased(int ch,
int key,
int modifiers)
Notifies this widget that a key has been released
|
InputResult |
onMouseDown(int x,
int y,
int button)
Notifies this widget that the mouse has been pressed while inside its bounds
|
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.
|
InputResult |
onMouseMove(int x,
int y)
Notifies this widget that the mouse has been moved while inside its bounds.
|
InputResult |
onMouseScroll(int x,
int y,
double amount)
Notifies this widget that the mouse has been scrolled inside its bounds.
|
InputResult |
onMouseUp(int x,
int y,
int button)
Notifies this widget that the mouse has been released while inside its bounds
|
void |
onShown()
Notifies this widget that it is visible and
shows any hidden peers of itself and its children.
|
void |
paint(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int mouseX,
int mouseY)
Paints this widget.
|
void |
releaseFocus()
If this widget has a host, releases this widget's focus.
|
void |
renderTooltip(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int tX,
int tY)
Internal method to render tooltip data.
|
void |
requestFocus()
If this widget has a host, requests the focus from the host.
|
void |
setHost(@Nullable GuiDescription host)
Sets the host of this widget without creating peers.
|
void |
setLocation(int x,
int y)
Sets the location of this widget relative to its parent.
|
void |
setParent(WPanel parent)
Sets the parent panel of this widget.
|
void |
setSize(int x,
int y)
Sets the size of this widget.
|
void |
tick()
Executes a client-side tick for this widget.
|
void |
validate(GuiDescription host)
Creates component peers, lays out children, and initializes animation data for this Widget and all its children.
|
@Nullable protected @Nullable WPanel parent
protected int x
protected int y
protected int width
protected int height
@Nullable protected @Nullable GuiDescription host
GuiDescription of this widget.
Can be null if this widget is a HUD widget.public void setLocation(int x,
int y)
x - the new X coordinatey - the new Y coordinatepublic void setSize(int x,
int y)
Overriding methods may restrict one of the dimensions to be
a constant value, for example super.setSize(x, 20).
x - the new widthy - the new heightpublic int getX()
public int getY()
public int getAbsoluteX()
public int getAbsoluteY()
public int getWidth()
public int getHeight()
public boolean canResize()
setSize(int, int).@Nullable public @Nullable WPanel getParent()
public void setParent(WPanel parent)
parent - the new parent@Environment(value=CLIENT) public InputResult onMouseDown(int x, int y, int button)
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)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseDrag(int x, int y, int button, double deltaX, double deltaY)
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 axisInputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseUp(int x, int y, int button)
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)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onClick(int x, int y, int button)
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)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseScroll(int x, int y, double amount)
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)amount - The scrolled amount. Positive values are up and negative values are down.InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public InputResult onMouseMove(int x, int y)
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)InputResult.PROCESSED if the event is handled, InputResult.IGNORED otherwise.@Environment(value=CLIENT) public void onCharTyped(char ch)
ch - the character typed@Environment(value=CLIENT)
public void onKeyPressed(int ch,
int key,
int modifiers)
key - the GLFW scancode of the key@Environment(value=CLIENT)
public void onKeyReleased(int ch,
int key,
int modifiers)
key - the GLFW scancode of the keypublic void onFocusGained()
public void onFocusLost()
public boolean isFocused()
GuiDescription.isFocused(WWidget)public void requestFocus()
GuiDescription.requestFocus(WWidget)public void releaseFocus()
GuiDescription.releaseFocus(WWidget)public boolean canFocus()
@Deprecated public void createPeers(GuiDescription c)
validate(GuiDescription).c - the top-level Container that will hold the peers@Environment(value=CLIENT)
public void paint(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int mouseX,
int mouseY)
matrices - the rendering matrix stackx - 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 cursorpublic boolean isWithinBounds(int x,
int y)
The default implementation checks that X and Y are at least 0 and below the width and height of this widget.
x - the X coordinatey - the Y coordinate@Environment(value=CLIENT)
public void renderTooltip(net.minecraft.client.util.math.MatrixStack matrices,
int x,
int y,
int tX,
int tY)
addTooltip method to insert data into the tooltip - without this, the method returns early, because no workx - 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 tooltippublic void validate(GuiDescription host)
host - the host GUI description@Nullable public final @Nullable GuiDescription getHost()
hostpublic void setHost(@Nullable
@Nullable GuiDescription host)
host - the new hosthost@Environment(value=CLIENT) public void addTooltip(TooltipBuilder tooltip)
tooltip - the builder to add tooltip lines topublic WWidget hit(int x, int y)
@Environment(value=CLIENT) public void tick()
@Nullable public @Nullable WWidget cycleFocus(boolean lookForwards)
If this widget is not focusable, returns null.
lookForwards - whether this should cycle forwards (true) or backwards (false)@Beta public void onShown()
@Beta public void onHidden()
The default implementation releases this widget's focus if it is focused. Overriding implementations might want to do this as well.
@Environment(value=CLIENT) public void addPainters()
Always called before GuiDescription.addPainters() to allow users to modify painters.
@Environment(value=CLIENT) public static boolean isActivationKey(int ch)
The activation keys are Enter, keypad Enter, and Space.
ch - the key code