Interface ElementSpec
PanelElement whose final position is computed
by an M8 layout helper (Row, Column).
Decouples element declaration (intrinsic dimensions, content,
behavior) from element position (childX, childY). The consumer
declares an ElementSpec at construction time; the layout helper computes
the position from spacing + alignment policy + sibling dimensions; the
helper invokes at(int, int) to instantiate the element at its
final position.
Why deferred construction: PanelElement declares
childX/childY as "Fixed at construction; never mutated"
(THESIS Principle 4). If layout helpers received pre-constructed
elements, they could only either mutate child coordinates (violation)
or copy-construct (forces every element type to expose a copy-with-
position constructor). ElementSpec is the third path: positions flow
through the helper into the element constructor at first instantiation.
Library-shipped element types provide static spec(...)
factories returning ElementSpec. Consumers building custom
elements can implement this interface directly or wrap an existing
element type via an anonymous instance.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionat(int childX, int childY) Construct the element positioned at the given panel-local coordinates.intheight()Height of the element in pixels (panel-local).static ElementSpecof(PanelElement element) Wraps an ALREADY-CONSTRUCTED element as anElementSpecso it can be dropped into aRow/Column(Pass 3).default ElementSpecSupplier-driven variant oftooltip(Component).default ElementSpectooltip(net.minecraft.network.chat.Component text) Returns anElementSpecidentical to this one that ALSO attaches a hover tooltip to the element when the layout helper materializes it.intwidth()Width of the element in pixels (panel-local).
-
Method Details
-
width
int width()Width of the element in pixels (panel-local). -
height
int height()Height of the element in pixels (panel-local). -
at
Construct the element positioned at the given panel-local coordinates. Called once per spec by the layout helper; the returned element'schildX/childYmatch the supplied(x, y). -
tooltip
Returns anElementSpecidentical to this one that ALSO attaches a hover tooltip to the element when the layout helper materializes it. This closes the gap where the.spec()factories and theRow/Columnlayout path could not carry a tooltip — the chainable.tooltip(...)setter lives on the concrete element, but on this path the element doesn't exist untilat(int,int)runs. An immutable decorator: it defers to the underlying spec for size + element construction, then applies the tooltip if the built element supports one (a libraryAbstractPanelElement); a bare custom element that doesn't extend the base keeps no tooltip. -
tooltip
Supplier-driven variant oftooltip(Component).
-