Class TElement
- All Implemented Interfaces:
INode<TElement>, INodeBounded<TElement,Bounds2i>, INodeRenderable<TElement, TGuiGraphics>, Iterable<TElement>, Collection<TElement>
- Direct Known Subclasses:
TBlockStateElement, TClickableWidget, TContextMenu, TEntityElement, TFillColorElement, THoverScrollElement, TItemStackElement, TLabelElement, TPanelElement, TScreen, TSeparatorElement, TStretchedTextElement, TTextureElement, TTooltip, TWindowElement
TCDCommons's GUI system.-
Field Summary
FieldsModifier and TypeFieldDescriptionAn event that is invoked wheneverclearAndInit()finishes executing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds the child viaNode.add(Node)and repositions it by this element's bounds usingmove(int, int).final NotNullProperty<Bounds2i> TheNotNullPropertythat holds the bounding box of thisTElement.final void(Re/)initializes thisTElementand its children.final BooleanPropertyReturns theBooleanPropertythat controls whether thisTElementwill clip (hide) any part of its descendant elements that would extend beyond its rectangular boundaries.final ObjectProperty<Function<@NotNull TElement, @Nullable TContextMenu>> TheObjectPropertythat holds a supplierFunctionfor the context menuTContextMenuthat is to be shown when thisTElementis right-clicked.protected voidA callback method that is invoked whenever thisTElementstops being dragged.protected voidA callback method that is invoked whenever thisTElementstarts being dragged.final @Nullable TElementfindElementAt(int screenX, int screenY) Attempts to find aTElementat the given screen-space position.final BooleanPropertyReturns theBooleanPropertythat controls whether thisTElementshould be receiving focus via user input such as mouse and keyboard.protected voidA callback method that is invoked whenever thisTElementgains focus.protected voidA callback method that is invoked whenever thisTElementloses focus.final voidforEachVisible(@NotNull Consumer<TElement> action, boolean recursive) Returns theClassobject that represents the base type of this node.final @NotNull Bounds2iReturns the bounding box of thisNode.@Nullable net.minecraft.client.Minecraftfinal @NotNull Bounds2iReturns theBounds2ithat encapsulates all child bounding boxes as one.@NotNull CursorTypeReturnsCursorTypethat represents the visual look the user's mouse cursor should have when thisTElementis hovered.final @NotNull TElementgetSelf()Returns thisNode, cast to its concrete type.final @Nullable TElementReturns the tooltipTElementthat should be rendered whenever thisTElementis hovered.
IftooltipProperty()'s value isnull, a tooltip element is sought in this element's (grand/)parents.final BooleanPropertyReturns theBooleanPropertythat controls whether thisTElementshould be detected as hovered by the mouse cursor.protected voidA callback method that is invoked whenever thisTElementbecomes hovered.protected voidA callback method that is invoked whenever thisTElementstops being hovered.protected voidCallback method that is invoked when thisTElementis initializing.booleaninputCallback(TInputContext.InputDiscoveryPhase phase, @NotNull TInputContext context) A callback method that is invoked when the user makes an input.final voidInvalidates the cachedcurrentTooltipvalue.booleanReturnstrueif thisTElementshould be receiving focus via user input such as mouse and keyboard.final booleanbooleanReturnstrueif thisTElementshould be detected as hovered by the mouse cursor.final booleanReturnstrueif thisTElementis currently being hovered by the mouse cursor.final booleanReturnsisHovered()||isFocused().final booleanfinal voidmove(int dX, int dY) Moves thisTElementand all of its (grand/)children.final voidmoveChildren(int dX, int dY) Moves all of thisTElement's (grand/)children.final voidmoveTo(int x, int y) Moves thisTElementto the given position.voidpostRenderCallback(@NotNull TGuiGraphics pencil) Callback method that is invoked after thisNodeand all of their children have been rendered.final voidRemoves the child viaNode.remove(Node)and repositions it by the inverse of this element's bounds usingmove(int, int).voidrenderCallback(@NotNull TGuiGraphics pencil) Callback method that is invoked when thisNodeis being rendered.final ObjectProperty<TScreen> final voidsetBounds(int x, int y, int width, int height) Sets the value ofboundsProperty().final voidSets the value ofboundsProperty().final voidSets the value ofboundsProperty(), usingUDims to calculate the new bounds relative to parent bounds.final @Nullable TContextMenuShows the context menu for thisTElement, if available incontextMenuProperty().protected voidCallback method that is invoked automatically every GUI tick, if and afterNode.getParent()ticks.final ObjectProperty<Function<@NotNull TElement, @NotNull TElement>> TheObjectPropertythat holds a supplierFunctionfor the tooltipTElementthat is to be rendered as thisTElement's tooltip.toString()final BooleanPropertyReturns theBooleanPropertythat controls the visibility of thisTElement.Methods inherited from class Node
add, addAll, childAddedCallback, childRemovedCallback, clear, contains, containsAll, equals, findChild, findParent, findSibling, forEach, get, getFirst, getLast, getParent, hashCode, indexOf, isEmpty, iterator, parentProperty, remove, remove, remove, removeAll, retainAll, rootProperty, size, toArray, toArray
-
Field Details
-
eInitialized
An event that is invoked wheneverclearAndInit()finishes executing.The
Consumerprovides an instance ofthisfor convenience.
-
-
Constructor Details
-
TElement
public TElement()
-
-
Method Details
-
getSelf
-
getBaseType
Description copied from class:NodeReturns theClassobject that represents the base type of this node.The base type is the "root"
Classin anNodehierarchy, from which all other specificNodetypes in a scene graph are derived. For example, ifLightNode,MeshNode, andCameraNodeall extend a commonNodeclass, thenNodeis the base type for that hierarchy.Override this method in your subclasses and return the class literal of your subclass. For example:
public class MyNode extends Node<MyNode> { public Class<MyNode> getBaseType() { return MyNode.class; } }- Specified by:
getBaseTypein interfaceINode<TElement>- Specified by:
getBaseTypein classNode<TElement>- See Also:
-
renderCallback
Description copied from interface:INodeRenderableCallback method that is invoked when thisNodeis being rendered.- Specified by:
renderCallbackin interfaceINodeRenderable<TElement, TGuiGraphics>- Parameters:
pencil- The rendering context.
-
postRenderCallback
Description copied from interface:INodeRenderableCallback method that is invoked after thisNodeand all of their children have been rendered.- Specified by:
postRenderCallbackin interfaceINodeRenderable<TElement, TGuiGraphics>- Parameters:
pencil- The rendering context.
-
toString
-
getBounds
Description copied from interface:INodeBoundedReturns the bounding box of thisNode.- Specified by:
getBoundsin interfaceINodeBounded<TElement,Bounds2i>
-
getContentBounds
Returns theBounds2ithat encapsulates all child bounding boxes as one. The returned bounding box shall represent the exact space all children's bounding boxes collectively occupy at the moment. This is done using each child'sgetBounds().Does NOT return
null. If there are no children, returns aBounds2iinstance that has thisTElement's position but zero size (aka width and height of 0). -
getClient
-
boundsProperty
TheNotNullPropertythat holds the bounding box of thisTElement. -
screenProperty
- API Note:
- Read only. Owned by
TElement.TElementPropertyAccessor.
-
visibleProperty
Returns theBooleanPropertythat controls the visibility of thisTElement. Invisible elements do not render and cannot be interacted with. -
clipsDescendantsProperty
Returns theBooleanPropertythat controls whether thisTElementwill clip (hide) any part of its descendant elements that would extend beyond its rectangular boundaries. -
focusableProperty
Returns theBooleanPropertythat controls whether thisTElementshould be receiving focus via user input such as mouse and keyboard.- API Note:
- Not to be confused with
isFocusable(). This property is about telling theTElementif it should be focusable, andisFocusable()is about theTElementmaking the final decision.
-
hoverableProperty
Returns theBooleanPropertythat controls whether thisTElementshould be detected as hovered by the mouse cursor.- API Note:
- Not to be confused with
isHoverable(). This property is about telling theTElementif it should be hoverable, andisHoverable()is about theTElementmaking the final decision.
-
tooltipProperty
TheObjectPropertythat holds a supplierFunctionfor the tooltipTElementthat is to be rendered as thisTElement's tooltip.Reason
Functions are used is for optimization, as creating aTElementinstance is much more expensive than a supplierFunction.The first argument of the
FunctionisthisTElementinstance, and theFunctionis to return a newTElementinstance acting as the tooltip.While the function itself can be set to
null, theTElementit returns must not benull!- API Note:
- The tooltip element is only rendered visually, should serve no functional purpose, and should not be a child of another element.
-
contextMenuProperty
public final ObjectProperty<Function<@NotNull TElement, @Nullable TContextMenu>> contextMenuProperty()TheObjectPropertythat holds a supplierFunctionfor the context menuTContextMenuthat is to be shown when thisTElementis right-clicked.Reason
Functions are used is for optimization, as creating aTContextMenuinstance is much more expensive than a supplierFunction.The first argument of the
FunctionisthisTElementinstance, and theFunctionis to return a newTContextMenuinstance acting as the context menu.The function itself can be set to
null, and theTContextMenuit returns may also benull. -
isVisible
-
isHovered
public final boolean isHovered()Returnstrueif thisTElementis currently being hovered by the mouse cursor.- API Note:
- Returns
falseifscreenProperty()'s value isnull.
-
isFocused
public final boolean isFocused()- API Note:
- Returns
falseifscreenProperty()'s value isnull.
-
isHoveredOrFocused
public final boolean isHoveredOrFocused()ReturnsisHovered()||isFocused(). -
isFocusable
Returnstrueif thisTElementshould be receiving focus via user input such as mouse and keyboard.- See Also:
- API Note:
- Overrides should take
focusableProperty()into account.
-
isHoverable
Returnstrueif thisTElementshould be detected as hovered by the mouse cursor. Whenfalse, mouse hovering over this element will "go though" this element, thus hovering an element below it instead.- See Also:
- API Note:
- Overrides should take
hoverableProperty()into account.
-
getTooltip
Returns the tooltipTElementthat should be rendered whenever thisTElementis hovered.
IftooltipProperty()'s value isnull, a tooltip element is sought in this element's (grand/)parents. -
invalidateTooltipCache
public final void invalidateTooltipCache()Invalidates the cachedcurrentTooltipvalue. This cached value is supplied by thetooltipProperty(), and is held for optimization purposes.Call this in the event a property change requires updating the tooltip.
-
move
public final void move(int dX, int dY) Moves thisTElementand all of its (grand/)children.- Parameters:
dX- The amount to move in the X axis.dY- The amount to move in the Y axis.
-
moveChildren
public final void moveChildren(int dX, int dY) Moves all of thisTElement's (grand/)children.- Parameters:
dX- The amount to move in the X axis.dY- The amount to move in the Y axis.
-
moveTo
public final void moveTo(int x, int y) Moves thisTElementto the given position. This affects children as well, by moving them based on the difference between the old and new position.- Parameters:
x- New X position.y- New Y position.
-
setBounds
public final void setBounds(int x, int y, int width, int height) Sets the value ofboundsProperty(). This does not move children or affect their bounding boxes.- Parameters:
x- The new X position.y- The new Y position.width- The new width.height- The new height.
-
setBounds
Sets the value ofboundsProperty(). This does not move children or affect their bounding boxes.- Parameters:
bounds- The newBounds2i.
-
setBounds
public final void setBounds(@NotNull @NotNull UDim2 position, @NotNull @NotNull UDim2 size) throws NullPointerException, IllegalStateException Sets the value ofboundsProperty(), usingUDims to calculate the new bounds relative to parent bounds. This does not move children or affect their bounding boxes.- Parameters:
position- New position.size- New size.- Throws:
NullPointerException- If an argument isnull.IllegalStateException- IfNode.getParent()isnull.
-
findElementAt
Attempts to find aTElementat the given screen-space position.- Parameters:
screenX- Screen-space X position.screenY- Screen-space Y position.- API Note:
- Usually used internally for
TScreen.hoveredElementProperty()value calculation. This method assumesthisTElementdoes not clip descendants.
-
forEachVisible
public final void forEachVisible(@NotNull @NotNull Consumer<TElement> action, boolean recursive) throws NullPointerException - Parameters:
action- The action to perform.recursive- Whether to call theConsumerrecursively for (grand/)children.- Throws:
NullPointerException- If the argument isnull.
-
getCursor
ReturnsCursorTypethat represents the visual look the user's mouse cursor should have when thisTElementis hovered. -
clearAndInit
public final void clearAndInit()(Re/)initializes thisTElementand its children.If this
TElementinstance'sClassoverridesinitCallback();Node.clear()is called and theninitCallback()is called.Once initialized, recursively calls this method for each child, and then invokes
eInitialized.- API Note:
- Automatically called by an initializing
TScreen.
-
initCallback
-
inputCallback
@Virtual public boolean inputCallback(@NotNull TInputContext.InputDiscoveryPhase phase, @NotNull @NotNull TInputContext context) throws NullPointerException A callback method that is invoked when the user makes an input.- Parameters:
phase- The input discovery phase.context- Information about the user's input.- Returns:
trueif thisTElementhandled the input.- Throws:
NullPointerException- If an argument isnull.
-
tickCallback
Callback method that is invoked automatically every GUI tick, if and afterNode.getParent()ticks.For performance optimization reasons, this is invoked if this element is contained within its parent's
getBounds().Note that this is regardless of what
isVisible()returns. The only requirements are the element being "within parent bounds" and the parent having ticked. -
hoverGainedCallback
A callback method that is invoked whenever thisTElementbecomes hovered.- See Also:
-
hoverLostCallback
A callback method that is invoked whenever thisTElementstops being hovered.- See Also:
-
focusGainedCallback
A callback method that is invoked whenever thisTElementgains focus.- See Also:
-
focusLostCallback
A callback method that is invoked whenever thisTElementloses focus.- See Also:
-
dragStartCallback
A callback method that is invoked whenever thisTElementstarts being dragged.- See Also:
-
dragEndCallback
A callback method that is invoked whenever thisTElementstops being dragged.- See Also:
-
addRel
Adds the child viaNode.add(Node)and repositions it by this element's bounds usingmove(int, int).- Parameters:
child- The child to add and reposition relative to this element.
-
removeRel
Removes the child viaNode.remove(Node)and repositions it by the inverse of this element's bounds usingmove(int, int).- Parameters:
child- The child to remove and reposition relative to this element.
-
showContextMenu
Shows the context menu for thisTElement, if available incontextMenuProperty().- Returns:
- The shown
TContextMenu, ornullif none was shown.
-