From Lavish Software Wiki
What is a template?
A template is a set of characteristics that can be applied to any LGUI item (yes, including other templates). Templates are considered the "default" characteristics for the item. This means that if a characteristic is not given, the value from the template is used (if any). Put another way, a template is the "parent" from which an LGUI item inherits; anything specified by the item itself overrides the parent.
Why use templates?
There are many good reasons for using templates, including:
- The same characteristics can be applied to any number of items (elements, textures, fonts, other templates, etc) without re-describing them each time
- New characteristics for each element type can automatically apply to existing interfaces
What can templates NOT do?
Templates can NOT be individually applied to specific characteristics of items. For example, elements have a characteristic "X" and "Y". The element cannot specify separate templates for these characteristics, only a template for the element itself. However, they can specify separate templates for referenced items, such as fonts or textures. In other words, the element can use a template for fonts or textures that it uses.
A template can contain anything at all. However, a Name is required, and must be supplied by an attribute called Name. Typically, a template is named after the item it is designed for. For example, a template named "button" is designed for use with buttons. This does not mean that the template can only be used for that type of item, just that it is designed for buttons. It could equally be used for a window, a texture, etc. The item will determine what pieces of the template it actually needs, and will use only those pieces.
An empty template named "My Template"
<Template Name="My Template" />
A simple template
<template name='my template'> <X>12</X> <Y>24</Y> <Width>100</Width> <Height>100</Height> </template>
A Button template, designed to provide default settings for button elements
<template name='button'> <BackgroundColor></BackgroundColor> <Font Template='button.Font' /> <Border>5</Border> <BorderColor>FFD4D0C8</BorderColor> <Texture Template='button.Texture' /> <TextureHover Template='button.TextureHover' /> <TexturePressed Template='button.TexturePressed' /> </template>
A commandbutton template, using the button template, designed to provide default settings for commandbutton elements
<template name='commandbutton' Template='button'> <Font Template='commandbutton.Font' /> <Texture Template='commandbutton.Texture' /> <TextureHover Template='commandbutton.TextureHover' /> <TexturePressed Template='commandbutton.TexturePressed' /> </template>
Note that in this example, the template is templated. This means the commandbutton template inherits the button template. Only the font and textures are overridden, and the rest comes from button!
Templates can be used by any LGUI item but NOT individual characteristics. In the "Creating Templates" examples, some characteristics ARE shown to use templates -- but these are characteristics that reference an item (e.g. fonts and textures).
Templates are used by adding an attribute called Template that gives the name of the template to use. If the template does not exist at time of usage, it will work just like there was no template.
Elements (but not other LGUI items) automatically attempt to use a template with the same name as the element. For example, a "window" element will try to use the "window" template, if it exists. This makes it easy to apply a default skin to the entire interface without modifying individual elements.
A window element that uses a custom template.
<Window Name='Paranoia' Template='Paranoia.Window'> <X>1</X> <Y>479</Y> <Width>271</Width> <Height>232</Height> <BackgroundColor>00000000</BackgroundColor> </Window>