In-line style template declaration
You may declare templates within a template tag anywhere inside a composer node of your SMXML. It makes sense to declare templates before the UI element instances they are being applied on. So by the time SMAF gets to render the UI element the template has already been registered. All template declarations must appear as child nodes of a <template/> node in SMXML.
All template declarations must also have a template attribute. The value of which is the unique template ID. You apply a template by referencing its unique template ID. In the example below we apply the boxTemplateExample template on a couple of box components by setting their template attribute to 'boxTemplateExample'. Note that all template properties are shared amongst the instances: dimensions, color and roundness. At the same time you may freely position or rotate them.
SMXML
<!DOCTYPE composer SYSTEM "http://dtd.samplemath.com/smxml.dtd">
<composer>
<style>
<fill style="boxFill" type="solid">
<color>0x0000ff</color>
</fill>
</style>
<template>
<box template="boxTemplateExample" width="144" height="44" rounded="8" fill="boxFill"/>
</template>
<box id="background" width="100%" height="100%" alpha=".1" rounded="24"/>
<box template="boxTemplateExample" x="120" y="50"/>
<box template="boxTemplateExample" x="380" y="50" rotation="15"/>
</composer>
<composer>
<style>
<fill style="boxFill" type="solid">
<color>0x0000ff</color>
</fill>
</style>
<template>
<box template="boxTemplateExample" width="144" height="44" rounded="8" fill="boxFill"/>
</template>
<box id="background" width="100%" height="100%" alpha=".1" rounded="24"/>
<box template="boxTemplateExample" x="120" y="50"/>
<box template="boxTemplateExample" x="380" y="50" rotation="15"/>
</composer>
OUTPUT
Applying templates
You may and should apply one template on many components. There should only be one template applied on a component at a time. Applying a new template will override the previous one.
If both the template and the instance it's applied to declare a certain attribute value the template value will prevail. You may freely declare any attributes on an instance that has not yet been specified by the template applied on it.
There are no comments on this page. [Add comment]