Skip to content

UITemplateElement

Since 2.2.1
Component example screen loaded from a UITemplate resource
The complete two-pane layout and its stylesheets come from example_layout.ui.nbt; Java only supplies the live examples.

UITemplateElement loads a saved UITemplate resource and inserts its children and stylesheets into itself at runtime. It is used to reuse UI layouts created in the editor without duplicating code.

Circular template references are detected and logged as errors.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var tmpl = new UITemplateElement(IResourcePath.parse("mymod:my_panel"));
parent.addChild(tmpl);

// Change the template at runtime:
tmpl.setTemplate(IResourcePath.parse("mymod:other_panel"));

XML

xml
<template path="mymod:my_panel"/>
XML AttributeTypeDescription
pathstringResource path of the UITemplate to load (e.g. mymod:my_panel).

Fields

NameTypeAccessDescription
pathIResourcePath (nullable)private (getter)The currently loaded template path.
templateUITemplate (nullable)private (getter)The resolved UITemplate instance.

Methods

MethodReturnsDescription
setTemplate(IResourcePath)UITemplateElementLoads a new template, replacing the current children and styles. Pass null to clear.

Released under the MIT License.