Interface ElementSpec


public interface ElementSpec
A factory for a 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 Type
    Method
    Description
    at(int childX, int childY)
    Construct the element positioned at the given panel-local coordinates.
    int
    Height of the element in pixels (panel-local).
    of(PanelElement element)
    Wraps an ALREADY-CONSTRUCTED element as an ElementSpec so it can be dropped into a Row/Column (Pass 3).
    default ElementSpec
    tooltip(Supplier<net.minecraft.network.chat.Component> supplier)
    Supplier-driven variant of tooltip(Component).
    default ElementSpec
    tooltip(net.minecraft.network.chat.Component text)
    Returns an ElementSpec identical to this one that ALSO attaches a hover tooltip to the element when the layout helper materializes it.
    int
    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

      PanelElement at(int childX, int childY)
      Construct the element positioned at the given panel-local coordinates. Called once per spec by the layout helper; the returned element's childX/childY match the supplied (x, y).
    • of

      static ElementSpec of(PanelElement element)
      Wraps an ALREADY-CONSTRUCTED element as an ElementSpec so it can be dropped into a Row/Column (Pass 3). Bridges the common fresh-consumer case — you hold pre-built widgets (constructor-built, or returned from a factory) and want to lay them out, including with CrossAlign.FILL. The wrapper reports the element's live getWidth()/getHeight() and, at layout time, repositions it via setChildPosition (for the library's AbstractPanelElement widgets); a bare custom PanelElement that doesn't extend the base keeps whatever position it was built with.
    • tooltip

      default ElementSpec tooltip(net.minecraft.network.chat.Component text)
      Returns an ElementSpec identical 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 the Row/ Column layout path could not carry a tooltip — the chainable .tooltip(...) setter lives on the concrete element, but on this path the element doesn't exist until at(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 library AbstractPanelElement); a bare custom element that doesn't extend the base keeps no tooltip.
    • tooltip

      default ElementSpec tooltip(Supplier<net.minecraft.network.chat.Component> supplier)
      Supplier-driven variant of tooltip(Component).