HomeWeb Components API Reference - v0.31.0
    Preparing search index...

    Class ElementComponentElement

    The ElementComponentElement interface provides properties and methods for manipulating <pc-element> elements. The ElementComponentElement interface also inherits the properties and methods of the HTMLElement interface.

    Despite the name, this is not a base class or a generic wrapper: it is the engine's 2D UI component, which gives its host entity a rectangle in a <pc-screen> hierarchy that draws either an image, a line of text or nothing (type="image", "text" or "group"). The tag spells the engine component it adds, as every component element does.

    Engine component: ElementComponent (element).

    Hierarchy (View Summary)

    Index
    alignment: Vec2

    The horizontal and vertical alignment of the text within the element. Each is from 0 to 1, and applies to text elements only. Defaults to 0.5 0.5, centered; 0 1 aligns to the top left.

    anchor: Vec4

    The anchor of the element component. It is the left, bottom, right and top edges as fractions of the parent's size, in that order. Defaults to 0 0 0 0, the parent's bottom-left corner; 0.5 0.5 0.5 0.5 centers the element.

    autoFitHeight: boolean

    Whether a text element automatically reduces its font size to fit its height. The size goes down to min-font-size, so that the text fits within the element's height. Requires auto-height to be false.

    autoFitWidth: boolean

    Whether a text element automatically reduces its font size to fit its width. The size goes down to min-font-size, so that the text fits within the element's width. Requires auto-width to be false.

    autoHeight: boolean

    Whether the element component should automatically adjust its height. It adjusts to the text content, and applies to text elements only.

    autoWidth: boolean

    Whether the element component should automatically adjust its width. It adjusts to the text content, and applies to text elements only.

    color: Color

    The color of the element component.

    enableMarkup: boolean

    Whether the element component should use markup.

    fitMode: FitMode

    How the texture or sprite fits the element's rectangle. Applies to image elements only. Can be:

    • stretch - Fills the rectangle exactly, ignoring the source aspect ratio.
    • contain - Fits within the rectangle, preserving the source aspect ratio.
    • cover - Covers the whole rectangle, preserving the source aspect ratio.

    Defaults to stretch.

    fontSize: number

    The font size of the element component.

    height: number

    The height of the element component. Defaults to 32.

    justify: boolean

    Whether wrapped lines are stretched flush with both edges of the element, which needs wrap-lines and a fixed width. The gaps between their words are widened to do it, and it applies to text elements only. The last line, and any line ended by an explicit line break, follows alignment instead. Defaults to false.

    letterSpacing: number

    The extra space between the letters of the text, as a fraction of the font size. Applies to text elements only. 0.1 adds a tenth of the font size between each pair of characters, like the CSS letter-spacing property, and a negative value tightens the text. It is added on top of spacing. Defaults to 0.

    lineHeight: number

    The line height of the element component.

    mask: boolean

    Whether the element component is a mask. A mask clips its descendants to its bounds, and applies to image elements only.

    maxFontSize: number

    The largest font size a text element may use when auto-fitting.

    maxLines: number | null

    The maximum number of lines wrap-lines wraps the text onto. Any leftover text is appended to the last line, and it applies to text elements only. Defaults to null, no limit.

    minFontSize: number

    The smallest font size a text element may use when auto-fitting.

    opacity: number

    The opacity of the element component. It ranges from 0 to 1.

    outlineColor: Color

    The color of the text outline, which is only drawn when outline-thickness is above 0. Applies to text elements only. Defaults to opaque black.

    outlineThickness: number

    The thickness of the text outline. It ranges from 0 to 1, and applies to text elements only. Defaults to 0, no outline.

    pivot: Vec2

    The pivot of the element component. It is the point within its rectangle, as fractions of its width and height, that sits on its position and that it rotates and scales about. Defaults to 0 0, the bottom-left corner; 0.5 0.5 centers it.

    shadowColor: Color

    The color of the text shadow, which is only drawn when shadow-offset is not 0 0. Applies to text elements only. Defaults to opaque black.

    shadowOffset: Vec2

    The offset of the text shadow. It is horizontal then vertical, each from -1 to 1 and proportional to the font size, and applies to text elements only. Positive values shift the shadow right and up. Defaults to 0 0, no shadow.

    spacing: number

    The spacing between the letters of the text. It is a multiple of their normal spacing, and applies to text elements only. Defaults to 1.

    spriteFrame: number

    The frame of the sprite to render. Applies to image elements only.

    text: string

    The text of the element component.

    type: "text" | "image" | "group"

    The type of the element component.

    useInput: boolean

    Whether the element component accepts input events. Buttons and scrolling require it.

    width: number

    The width of the element component. Defaults to 32.

    wrapLines: boolean

    Whether the element component should wrap lines.

    • get closestApp(): AppElement | null

      The nearest ancestor <pc-app> element, or null if this element has no <pc-app> ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns AppElement | null

      The closest app element, or null.

    • get closestEntity(): EntityBaseElement | null

      The nearest ancestor element that fronts an entity — <pc-entity>, <pc-model> or <pc-node> — or null if this element has no such ancestor. The search starts at the parent, so an element never resolves to itself.

      Returns EntityBaseElement | null

      The closest entity-fronting element, or null.

    • get enabled(): boolean

      Gets the enabled state of the component.

      Returns boolean

      The enabled state of the component.

    • set enabled(value: boolean): void

      Sets the enabled state of the component.

      Parameters

      • value: boolean

        The enabled state of the component.

      Returns void

    • get pixelsPerUnit(): number | null

      Gets the number of pixels per unit used when rendering a sprite.

      Returns number | null

      The pixels per unit.

    • set pixelsPerUnit(value: number | null): void

      Sets the number of pixels per unit to use when rendering a sprite (image elements only).

      Parameters

      • value: number | null

        The pixels per unit.

      Returns void

    • Called when the element is fully initialized and ready. Subclasses should call this when they're ready. Resolves the ready promise and dispatches a bubbling, composed ready event. Signals at most once per readiness cycle: a repeat call before _resetReady has re-armed the promise does nothing.

      Returns void

    • Returns the ready promise to its pending state. Subclasses should call this when the resource their readiness announced is torn down (typically from disconnectedCallback), so that a later re-initialization can signal readiness again. Does nothing while the promise is still pending — an in-flight waiter carries over to the next readiness cycle rather than being stranded on a promise nothing will ever resolve.

      Returns void

    • Returns the data the component is created with: the value of every attribute in the subclass's schema. Overridden by subclasses that cache their properties themselves, to supply those. The element's enabled state is not among them: the base class adds it when it creates the component.

      Returns Record<string, any>

      The initial component data.

    • Returns a promise that resolves with this element when it's ready. This is the low-level primitive underlying whenReady, which is the recommended way to wait for elements.

      Readiness tracks the element's current lifecycle: once a ready element is torn down (for example by removing it from the document), this returns a fresh promise that resolves when the element is next ready. A promise obtained earlier stays resolved — call this again after re-inserting an element rather than reusing a promise from before its removal.

      Returns Promise<ElementComponentElement>

      A promise that resolves with this element when it's ready.