Log inGet started
Package

UiPanel.component

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

UiPanel

A UI panel component that renders a widget tree in one of three modes:

  • "2d" — egui viewport overlay (HUDs, menus, debug panels).
  • "projected" — screen-space UI at the entity's world position via worldToScreen. Always on top, no occlusion or lighting.
  • "3d": world-space billboard using egui render-to-texture. Respects depth/occlusion. The tree (inline, from setTree, or the screen a source library registers) is held on a hidden screen that is rasterized, styling and layout included, into a rasterizeWidth x rasterizeHeight texture every update; a quad in the child entity <name>_ui3d shows it, turned to face the active camera, and what the tree leaves transparent shows the world behind the quad. The quad is built in play.

Public fields: mode, layer, visible, tree (the widget tree, given inline), source (inline or "lib::<path>" / "@..." library module), offsetX/Y/Z, maxDistance, fontSize, textColor, background, billboard3dScale, exposureWeight, theme, rasterizeWidth, rasterizeHeight.

In 3d mode exposureWeight (default 1) keeps the panel at the colours it states on screen whatever the camera's exposure, the way UI reads; 0 draws it as light in the scene, which a night exposure brightens and a day exposure dims.

Methods: setTree(tree), show(), hide(), toggle(), setMode(newMode), getScreenName().

A library module named by source is mounted with mount(ctx). When mount registers its own screen, the panel registers that screen again from its own code, so the screen is the panel's: its callbacks reach the panel's onCallback, which hands them to the onCallback the mount returned, and the screen is unregistered when the panel ends.

entity(id).component.add("UiPanel", {
    mode = "2d",
    layer = 10,
    tree = { type = "label", props = { text = "HP: 100" } },
})