Interface TParentElement
- All Superinterfaces:
IEnableStateProvider
- All Known Subinterfaces:
IMenuPanelItem
- All Known Implementing Classes:
AbstractFileListPanel
,ActionBar
,ActionBar.FileNameInputField
,FileListItem
,FileListPanel
,NavigationBar
,SidebarPanel
,TBlankElement
,TButtonWidget
,TCheckboxWidget
,TClickableWidget
,TContextMenuPanel
,TDemoBackgroundElement
,TElement
,TEntityRendererElement
,TestTScreen
,TestTWidgetHudScreen
,TFileChooserScreen
,TFileExplorerPanel
,TFillColorElement
,TitleBar
,TitleBar.TitleBarSquareButton
,TLabelElement
,TMenuBarPanel
,TMenuPanel
,TMenuPanelButton
,TMenuPanelSeparator
,TPanelElement
,TProgressBarElement
,TRefreshablePanelElement
,TScreen
,TScreenPlus
,TScrollBarWidget
,TSelectEnumWidget
,TSelectFileFilterWidget
,TSelectWidget
,TSliderWidget
,TStackTraceScreen
,TTextFieldWidget
,TTextureElement
,TWidgetHudScreen
TParentElement
interface represents a GUI element in the TCDCommons
framework.
Implementations of this interface can act as parent elements for other GUI elements, providing
a structural hierarchy for GUI representation and interaction.
Each TParentElement
has an X and Y coordinate, as well as a width and height. These
attributes define the element's position and size within the GUI layout.
Implementing classes should ensure these properties are correctly maintained to ensure accurate representation and interaction within the GUI.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum depth of nested children that can be iterated over by the__findChild(TParentElement, Predicate, boolean, int)
method. -
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
default boolean
default void
default @Nullable TElement
Iterates over every child ingetChildren()
, and applies aPredicate
to it.default @Nullable TElement
findLastChild
(Predicate<TElement> predicate, boolean nested) Similar tofindChild(Predicate, boolean)
, but it returns the last instance that matches a given predicate.default @Nullable TParentElement
findParent
(Predicate<TParentElement> predicate) Finds and returns the firstTParentElement
for which the provided action returns true.default @Nullable TElement
findParentTElement
(Predicate<TElement> predicate) Finds and returns the first parentTElement
for which the provided action returns true.default void
forEachChild
(Consumer<TElement> action, boolean nested) Iterates over every child ingetChildren()
, and applies aConsumer
to it.default boolean
Returns true if thisObject
is enabled.default int
getEndX()
default int
getEndY()
int
@Nullable TParentElement
int
getWidth()
int
getX()
int
getY()
default float
Returns the Z-index for thisTParentElement
.
Should be between 0 (inclusive) and 100 (also inclusive), as any other values may cause this element to not render properly or to not render at all.default boolean
input
(TInputContext inputContext) An input handler that handles inputs on theTInputContext.InputDiscoveryPhase.MAIN
input phase.default boolean
input
(TInputContext inputContext, TInputContext.InputDiscoveryPhase inputPhase) An input handler that handles inputs on all possibleTInputContext.InputDiscoveryPhase
s.default boolean
default boolean
removeChild
(TElement child) default boolean
removeChild
(TElement child, boolean reposition) void
render
(TDrawContext pencil) Renders this GUI element on the screen.
-
Field Details
-
MAX_CHILD_NESTING_DEPTH
static final int MAX_CHILD_NESTING_DEPTHThe maximum depth of nested children that can be iterated over by the__findChild(TParentElement, Predicate, boolean, int)
method.This limit is enforced to prevent several potential issues:
- Stack overflow due to excessive recursion
- Performance degradation from handling an excessive number of nested children
- Infinite recursion resulting from a child element containing itself as one of its children
__findChild(TParentElement, Predicate, boolean, int)
method will returnnull
.- See Also:
-
-
Method Details
-
getX
int getX() -
getY
int getY() -
getWidth
int getWidth() -
getHeight
int getHeight() -
getEndX
default int getEndX() -
getEndY
default int getEndY() -
render
Renders this GUI element on the screen.- Parameters:
pencil
- TheTDrawContext
.
-
getZIndex
default float getZIndex()Returns the Z-index for thisTParentElement
.
Should be between 0 (inclusive) and 100 (also inclusive), as any other values may cause this element to not render properly or to not render at all. -
input
An input handler that handles inputs on theTInputContext.InputDiscoveryPhase.MAIN
input phase.- Parameters:
inputContext
- TheTInputContext
containing information about a given input.- See Also:
-
input
An input handler that handles inputs on all possibleTInputContext.InputDiscoveryPhase
s.- Parameters:
inputContext
- TheTInputContext
containing information about a given input.inputPhase
- The currentTInputContext.InputDiscoveryPhase
.- See Also:
-
getParent
-
getChildren
TElementList getChildren() -
addChild
-
addChild
-
removeChild
-
removeChild
-
clearChildren
default void clearChildren() -
isEnabled
default boolean isEnabled()Returnstrue
ifgetEnabled()
returnstrue
, andgetParent()
'sisEnabled()
also returnstrue
.In other words, this will return
true
if both this element and all of itsTParentElement
s are enabled. -
getEnabled
default boolean getEnabled()Description copied from interface:IEnableStateProvider
Returns true if thisObject
is enabled.- Specified by:
getEnabled
in interfaceIEnableStateProvider
-
findParent
Finds and returns the firstTParentElement
for which the provided action returns true.- Parameters:
predicate
- A predicate that takes aTParentElement
and returns aBoolean
. This predicate is applied to each parent element in the hierarchy until it returns true or no more parent elements are found.- Returns:
- The first
TParentElement
for which the action returns true, or null if no such element is found.
-
findParentTElement
Finds and returns the first parentTElement
for which the provided action returns true.- Parameters:
predicate
- A predicate that takes aTElement
and returns aBoolean
. This predicate is applied to each parent element in the hierarchy that is an instance ofTElement
until it returns true or no more parent elements are found.- Returns:
- The first parent
TElement
for which the action returns true, or null if no such element is found.
-
forEachChild
Iterates over every child ingetChildren()
, and applies aConsumer
to it.This is similar to
findChild(Predicate, boolean)
, except theConsumer
does not return 'true' or 'false', and therefore there's no way to end the loop here. -
findChild
Iterates over every child ingetChildren()
, and applies aPredicate
to it.When the
Predicate
returns true for childTElement
, the "for-each" operation will terminate, and the childTElement
will be returned. -
findLastChild
Similar tofindChild(Predicate, boolean)
, but it returns the last instance that matches a given predicate.
-